Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Swiss public transport initial data for attributes #107452

Merged
merged 1 commit into from
Jan 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion homeassistant/components/swiss_public_transport/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,25 @@ def __init__(
entry_type=DeviceEntryType.SERVICE,
)

async def async_added_to_hass(self) -> None:
"""Prepare the extra attributes at start."""
self._async_update_attrs()
miaucl marked this conversation as resolved.
Show resolved Hide resolved
await super().async_added_to_hass()

@callback
def _handle_coordinator_update(self) -> None:
"""Handle the state update and prepare the extra state attributes."""
self._async_update_attrs()
return super()._handle_coordinator_update()

@callback
def _async_update_attrs(self) -> None:
"""Update the extra state attributes based on the coordinator data."""
self._attr_extra_state_attributes = {
key: value
for key, value in self.coordinator.data.items()
if key not in {"departure"}
}
return super()._handle_coordinator_update()

@property
def native_value(self) -> str:
Expand Down