Skip to content

feat(sensor): restore latest_events attribute and wire format_events service to it (v1.2.2)#36

Merged
Geek-MD merged 3 commits into
mainfrom
copilot/update-latest-events-attribute
Mar 15, 2026
Merged

feat(sensor): restore latest_events attribute and wire format_events service to it (v1.2.2)#36
Geek-MD merged 3 commits into
mainfrom
copilot/update-latest-events-attribute

Conversation

Copilot AI commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

latest_events was dropped from the sensor's extra_state_attributes in v1.2.1. Additionally, the format_events service was reading from the full cumulative events list rather than the per-update delta.

Changes

  • sensor.py — Re-introduces _latest_events:

    • First run: all events from the feed, sorted newest → oldest
    • Subsequent updates: only events not previously seen, sorted newest → oldest
    • Exposed via extra_state_attributes["latest_events"] (raw dicts, unformatted)
    • Written back to hass.data[DOMAIN][entry_id]["latest_events"] so other components can consume it
  • __init__.pyformat_events service now reads from latest_events instead of events, scoping formatted output to the delta of the most recent feed poll

  • manifest.json — version bumped to 1.2.2

Resulting attribute shape

extra_state_attributes = {
    "events": [...],         # cumulative, up to MAX_EVENTS=50, newest first
    "latest_events": [...],  # new events this update only (all on first run), newest first
}

Each entry in latest_events is a raw dict with keys: id, title, place, magnitude, time, updated, coordinates, distance. The format_events service applies formatting at call time from these raw dicts.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits March 15, 2026 21:37
Co-authored-by: Geek-MD <25725990+Geek-MD@users.noreply.github.com>
Co-authored-by: Geek-MD <25725990+Geek-MD@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix removal of latest_events attribute in sensor feat(sensor): restore latest_events attribute and wire format_events service to it (v1.2.2) Mar 15, 2026
Copilot AI requested a review from Geek-MD March 15, 2026 21:39
@Geek-MD Geek-MD marked this pull request as ready for review March 15, 2026 21:51
@Geek-MD Geek-MD merged commit 38633c3 into main Mar 15, 2026
4 checks passed

@code-review-doctor code-review-doctor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Some things to consider. View full project report here.


# 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants