Skip to content

Commit

Permalink
Fix Swiss public transport initial data for attributes (#107452)
Browse files Browse the repository at this point in the history
faster initial data for attributes
  • Loading branch information
miaucl committed Jan 7, 2024
1 parent da8ce7b commit 3139e92
Showing 1 changed file with 11 additions and 1 deletion.
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()
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

0 comments on commit 3139e92

Please sign in to comment.