mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use shorthand attributes in HVV departures (#104637)
* Use shorthand attributes in HVV departures * Apply code review suggestion Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Apply code review sugesstion Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> --------- Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
9dc5d4a1bb
commit
61a5c0de5e
@ -125,13 +125,29 @@ class HvvDepartureBinarySensor(CoordinatorEntity, BinarySensorEntity):
|
|||||||
|
|
||||||
_attr_attribution = ATTRIBUTION
|
_attr_attribution = ATTRIBUTION
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
_attr_device_class = BinarySensorDeviceClass.PROBLEM
|
||||||
|
|
||||||
def __init__(self, coordinator, idx, config_entry):
|
def __init__(self, coordinator, idx, config_entry):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.coordinator = coordinator
|
self.coordinator = coordinator
|
||||||
self.idx = idx
|
self.idx = idx
|
||||||
self.config_entry = config_entry
|
|
||||||
|
self._attr_name = coordinator.data[idx]["name"]
|
||||||
|
self._attr_unique_id = idx
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
entry_type=DeviceEntryType.SERVICE,
|
||||||
|
identifiers={
|
||||||
|
(
|
||||||
|
DOMAIN,
|
||||||
|
config_entry.entry_id,
|
||||||
|
config_entry.data[CONF_STATION]["id"],
|
||||||
|
config_entry.data[CONF_STATION]["type"],
|
||||||
|
)
|
||||||
|
},
|
||||||
|
manufacturer=MANUFACTURER,
|
||||||
|
name=f"Departures at {config_entry.data[CONF_STATION]['name']}",
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
@ -146,38 +162,6 @@ class HvvDepartureBinarySensor(CoordinatorEntity, BinarySensorEntity):
|
|||||||
and self.coordinator.data[self.idx]["available"]
|
and self.coordinator.data[self.idx]["available"]
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self):
|
|
||||||
"""Return the device info for this sensor."""
|
|
||||||
return DeviceInfo(
|
|
||||||
entry_type=DeviceEntryType.SERVICE,
|
|
||||||
identifiers={
|
|
||||||
(
|
|
||||||
DOMAIN,
|
|
||||||
self.config_entry.entry_id,
|
|
||||||
self.config_entry.data[CONF_STATION]["id"],
|
|
||||||
self.config_entry.data[CONF_STATION]["type"],
|
|
||||||
)
|
|
||||||
},
|
|
||||||
manufacturer=MANUFACTURER,
|
|
||||||
name=f"Departures at {self.config_entry.data[CONF_STATION]['name']}",
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return self.coordinator.data[self.idx]["name"]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return a unique ID to use for this sensor."""
|
|
||||||
return self.idx
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
||||||
return BinarySensorDeviceClass.PROBLEM
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict[str, Any] | None:
|
def extra_state_attributes(self) -> dict[str, Any] | None:
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
|
@ -73,6 +73,19 @@ class HVVDepartureSensor(SensorEntity):
|
|||||||
station_id = config_entry.data[CONF_STATION]["id"]
|
station_id = config_entry.data[CONF_STATION]["id"]
|
||||||
station_type = config_entry.data[CONF_STATION]["type"]
|
station_type = config_entry.data[CONF_STATION]["type"]
|
||||||
self._attr_unique_id = f"{config_entry.entry_id}-{station_id}-{station_type}"
|
self._attr_unique_id = f"{config_entry.entry_id}-{station_id}-{station_type}"
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
entry_type=DeviceEntryType.SERVICE,
|
||||||
|
identifiers={
|
||||||
|
(
|
||||||
|
DOMAIN,
|
||||||
|
config_entry.entry_id,
|
||||||
|
config_entry.data[CONF_STATION]["id"],
|
||||||
|
config_entry.data[CONF_STATION]["type"],
|
||||||
|
)
|
||||||
|
},
|
||||||
|
manufacturer=MANUFACTURER,
|
||||||
|
name=config_entry.data[CONF_STATION]["name"],
|
||||||
|
)
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
async def async_update(self, **kwargs: Any) -> None:
|
async def async_update(self, **kwargs: Any) -> None:
|
||||||
@ -165,20 +178,3 @@ class HVVDepartureSensor(SensorEntity):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
self._attr_extra_state_attributes[ATTR_NEXT] = departures
|
self._attr_extra_state_attributes[ATTR_NEXT] = departures
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self):
|
|
||||||
"""Return the device info for this sensor."""
|
|
||||||
return DeviceInfo(
|
|
||||||
entry_type=DeviceEntryType.SERVICE,
|
|
||||||
identifiers={
|
|
||||||
(
|
|
||||||
DOMAIN,
|
|
||||||
self.config_entry.entry_id,
|
|
||||||
self.config_entry.data[CONF_STATION]["id"],
|
|
||||||
self.config_entry.data[CONF_STATION]["type"],
|
|
||||||
)
|
|
||||||
},
|
|
||||||
manufacturer=MANUFACTURER,
|
|
||||||
name=self.config_entry.data[CONF_STATION]["name"],
|
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user