Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/usgs_earthquakes_feed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/usgs_earthquakes_feed/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"aio-geojson-usgs-earthquakes==0.3",
"aio-geojson-client==0.12"
],
"version": "1.2.1"
"version": "1.2.2"
}
11 changes: 11 additions & 0 deletions custom_components/usgs_earthquakes_feed/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
filtered_events, key=lambda e: parse_event_time(e), reverse=True
filtered_events, key=parse_event_time, reverse=True

Avoid unnecessarily wrapping parse_event_time in a lambda. Read more.

)

# 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:
Expand All @@ -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,
}


Expand Down
Loading