mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add multiple departures to Trafikverket Ferry (#71484)
This commit is contained in:
parent
0bc843c133
commit
d84c6af55d
@ -77,8 +77,10 @@ class TVDataUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
when = current_time
|
when = current_time
|
||||||
|
|
||||||
try:
|
try:
|
||||||
routedata: FerryStop = await self._ferry_api.async_get_next_ferry_stop(
|
routedata: list[
|
||||||
self._from, self._to, when
|
FerryStop
|
||||||
|
] = await self._ferry_api.async_get_next_ferry_stops(
|
||||||
|
self._from, self._to, when, 3
|
||||||
)
|
)
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
raise UpdateFailed(
|
raise UpdateFailed(
|
||||||
@ -86,11 +88,13 @@ class TVDataUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
) from error
|
) from error
|
||||||
|
|
||||||
states = {
|
states = {
|
||||||
"departure_time": routedata.departure_time,
|
"departure_time": routedata[0].departure_time,
|
||||||
"departure_from": routedata.from_harbor_name,
|
"departure_from": routedata[0].from_harbor_name,
|
||||||
"departure_to": routedata.to_harbor_name,
|
"departure_to": routedata[0].to_harbor_name,
|
||||||
"departure_modified": routedata.modified_time,
|
"departure_modified": routedata[0].modified_time,
|
||||||
"departure_information": routedata.other_information,
|
"departure_information": routedata[0].other_information,
|
||||||
|
"departure_time_next": routedata[1].departure_time,
|
||||||
|
"departure_time_next_next": routedata[2].departure_time,
|
||||||
}
|
}
|
||||||
_LOGGER.debug("States: %s", states)
|
_LOGGER.debug("States: %s", states)
|
||||||
return states
|
return states
|
||||||
|
@ -38,7 +38,7 @@ class TrafikverketRequiredKeysMixin:
|
|||||||
"""Mixin for required keys."""
|
"""Mixin for required keys."""
|
||||||
|
|
||||||
value_fn: Callable[[dict[str, Any]], StateType | datetime]
|
value_fn: Callable[[dict[str, Any]], StateType | datetime]
|
||||||
info_fn: Callable[[dict[str, Any]], StateType | list]
|
info_fn: Callable[[dict[str, Any]], StateType | list] | None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -80,6 +80,24 @@ SENSOR_TYPES: tuple[TrafikverketSensorEntityDescription, ...] = (
|
|||||||
info_fn=lambda data: data["departure_information"],
|
info_fn=lambda data: data["departure_information"],
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
|
TrafikverketSensorEntityDescription(
|
||||||
|
key="departure_time_next",
|
||||||
|
name="Departure Time Next",
|
||||||
|
icon="mdi:clock",
|
||||||
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
|
value_fn=lambda data: as_utc(data["departure_time_next"]),
|
||||||
|
info_fn=None,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
TrafikverketSensorEntityDescription(
|
||||||
|
key="departure_time_next_next",
|
||||||
|
name="Departure Time Next After",
|
||||||
|
icon="mdi:clock",
|
||||||
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
|
value_fn=lambda data: as_utc(data["departure_time_next_next"]),
|
||||||
|
info_fn=None,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -132,8 +150,11 @@ class FerrySensor(CoordinatorEntity[TVDataUpdateCoordinator], SensorEntity):
|
|||||||
self.coordinator.data
|
self.coordinator.data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.entity_description.info_fn:
|
||||||
self._attr_extra_state_attributes = {
|
self._attr_extra_state_attributes = {
|
||||||
"other_information": self.entity_description.info_fn(self.coordinator.data),
|
"other_information": self.entity_description.info_fn(
|
||||||
|
self.coordinator.data
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
Loading…
x
Reference in New Issue
Block a user