diff --git a/CHANGELOG.md b/CHANGELOG.md index f4e2ff4..d3efacc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ 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. + +### 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/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..33c0378 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,15 @@ 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 + ) + + # 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: @@ -106,6 +116,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, }