Skip to content

Commit

Permalink
Remove deprecated attributes from Swiss public transport integration (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
miaucl authored Jun 24, 2024
1 parent e32a27a commit 59dd63e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class DataConnection(TypedDict):
"""A connection data class."""

departure: datetime | None
next_departure: datetime | None
next_on_departure: datetime | None
duration: int | None
platform: str
remaining_time: str
Expand Down Expand Up @@ -88,8 +86,6 @@ async def _async_update_data(self) -> list[DataConnection]:
return [
DataConnection(
departure=self.nth_departure_time(i),
next_departure=self.nth_departure_time(i + 1),
next_on_departure=self.nth_departure_time(i + 2),
train_number=connections[i]["number"],
platform=connections[i]["platform"],
transfers=connections[i]["transfers"],
Expand Down
28 changes: 0 additions & 28 deletions homeassistant/components/swiss_public_transport/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
SensorEntityDescription,
)
from homeassistant.const import UnitOfTime
from homeassistant.core import callback
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
Expand All @@ -36,7 +35,6 @@ class SwissPublicTransportSensorEntityDescription(SensorEntityDescription):
value_fn: Callable[[DataConnection], StateType | datetime]

index: int = 0
has_legacy_attributes: bool = False


SENSORS: tuple[SwissPublicTransportSensorEntityDescription, ...] = (
Expand All @@ -45,7 +43,6 @@ class SwissPublicTransportSensorEntityDescription(SensorEntityDescription):
key=f"departure{i or ''}",
translation_key=f"departure{i}",
device_class=SensorDeviceClass.TIMESTAMP,
has_legacy_attributes=i == 0,
value_fn=lambda data_connection: data_connection["departure"],
index=i,
)
Expand Down Expand Up @@ -127,28 +124,3 @@ def native_value(self) -> StateType | datetime:
return self.entity_description.value_fn(
self.coordinator.data[self.entity_description.index]
)

async def async_added_to_hass(self) -> None:
"""Prepare the extra attributes at start."""
if self.entity_description.has_legacy_attributes:
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."""
if self.entity_description.has_legacy_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."""
if self.entity_description.has_legacy_attributes:
self._attr_extra_state_attributes = {
key: value
for key, value in self.coordinator.data[
self.entity_description.index
].items()
if key not in {"departure"}
}

0 comments on commit 59dd63e

Please sign in to comment.