From 5f59829c9507917f4feadd34c67047df169d4ffd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 21:34:24 +0000 Subject: [PATCH 1/3] Initial plan From 3748c1cfd36a65e3623b650e7026026b76d0f797 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 21:37:37 +0000 Subject: [PATCH 2/3] Restore latest_events attribute in sensor (v1.2.2) Co-authored-by: Geek-MD <25725990+Geek-MD@users.noreply.github.com> --- CHANGELOG.md | 7 +++++++ custom_components/usgs_earthquakes_feed/manifest.json | 2 +- custom_components/usgs_earthquakes_feed/sensor.py | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4e2ff4..ea1f676 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +## [1.2.2] - 2026-03-15 + +### Fixed +- **Restored `latest_events` attribute**: The sensor's `extra_state_attributes` now includes a `latest_events` key that was inadvertently removed in v1.2.1. + - On the first update, `latest_events` contains all events reported by the integration, ordered from most recent to oldest. + - On subsequent updates, `latest_events` contains only the new events since the previous update, ordered from most recent to oldest. + ## [1.2.1] - 2026-03-15 ### Fixed diff --git a/custom_components/usgs_earthquakes_feed/manifest.json b/custom_components/usgs_earthquakes_feed/manifest.json index d79d9b1..879d733 100644 --- a/custom_components/usgs_earthquakes_feed/manifest.json +++ b/custom_components/usgs_earthquakes_feed/manifest.json @@ -13,5 +13,5 @@ "aio-geojson-usgs-earthquakes==0.3", "aio-geojson-client==0.12" ], - "version": "1.2.1" + "version": "1.2.2" } diff --git a/custom_components/usgs_earthquakes_feed/sensor.py b/custom_components/usgs_earthquakes_feed/sensor.py index 4c57064..7672928 100644 --- a/custom_components/usgs_earthquakes_feed/sensor.py +++ b/custom_components/usgs_earthquakes_feed/sensor.py @@ -45,6 +45,7 @@ def __init__(self, hass: HomeAssistant, entry_id: str, device_info: DeviceInfo) self._entry_id = entry_id self._attr_device_info = device_info self._events: list[dict[str, Any]] = [] + self._latest_events: list[dict[str, Any]] = [] self._unsub_dispatcher: Any = None self._attr_native_value: datetime | None = None @@ -80,6 +81,11 @@ async def _async_update_events(self) -> None: self._events, key=lambda e: parse_event_time(e), reverse=True )[:MAX_EVENTS] + # latest_events: eventos nuevos de esta actualización, ordenados del más reciente al más antiguo + self._latest_events = sorted( + filtered_events, key=lambda e: parse_event_time(e), reverse=True + ) + # Actualizar valor del sensor (fecha del más reciente) if self._events: try: @@ -106,6 +112,7 @@ async def _async_update_events(self) -> None: def extra_state_attributes(self) -> dict[str, Any]: return { "events": self._events, + "latest_events": self._latest_events, } From 191a9ebc7a68717cd6c43c4a54c3f3de0a3c496c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 21:39:03 +0000 Subject: [PATCH 3/3] feat: wire format_events service to read from latest_events (v1.2.2) Co-authored-by: Geek-MD <25725990+Geek-MD@users.noreply.github.com> --- CHANGELOG.md | 3 +++ custom_components/usgs_earthquakes_feed/__init__.py | 2 +- custom_components/usgs_earthquakes_feed/sensor.py | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea1f676..d3efacc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ All notable changes to this project will be documented in this file. - On the first update, `latest_events` contains all events reported by the integration, ordered from most recent to oldest. - On subsequent updates, `latest_events` contains only the new events since the previous update, ordered from most recent to oldest. +### Changed +- **`format_events` service now reads from `latest_events`**: The `format_events` action now formats events sourced from the `latest_events` attribute (new events only per update) instead of the full cumulative `events` list. + ## [1.2.1] - 2026-03-15 ### Fixed diff --git a/custom_components/usgs_earthquakes_feed/__init__.py b/custom_components/usgs_earthquakes_feed/__init__.py index f7b41a4..a778eea 100644 --- a/custom_components/usgs_earthquakes_feed/__init__.py +++ b/custom_components/usgs_earthquakes_feed/__init__.py @@ -60,7 +60,7 @@ async def handle_format_events(call: ServiceCall) -> dict[str, Any]: all_events: list[dict[str, Any]] = [] for entry_data in hass.data.get(DOMAIN, {}).values(): if isinstance(entry_data, dict): - all_events.extend(entry_data.get("events", [])) + all_events.extend(entry_data.get("latest_events", [])) all_events.sort(key=parse_event_time, reverse=True) diff --git a/custom_components/usgs_earthquakes_feed/sensor.py b/custom_components/usgs_earthquakes_feed/sensor.py index 7672928..33c0378 100644 --- a/custom_components/usgs_earthquakes_feed/sensor.py +++ b/custom_components/usgs_earthquakes_feed/sensor.py @@ -86,6 +86,10 @@ async def _async_update_events(self) -> None: filtered_events, key=lambda e: parse_event_time(e), reverse=True ) + # Publicar latest_events en hass.data para que el servicio format_events pueda leerlos + entry_data = self.hass.data[DOMAIN].setdefault(self._entry_id, {}) + entry_data["latest_events"] = self._latest_events + # Actualizar valor del sensor (fecha del más reciente) if self._events: try: