Move tankerkoenig to new aiotankerkoenig package (#108913)

* Move tankerkoenig to new aiotankerkoenig package

* Fix config flow coverage

* Process code review suggestions

* Process code review suggestions
This commit is contained in:
Jan-Philipp Benecke 2024-01-31 14:57:08 +01:00 committed by GitHub
parent 640463c559
commit 71c2460161
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 367 additions and 320 deletions

View file

@ -3,6 +3,8 @@ from __future__ import annotations
import logging
from aiotankerkoenig import PriceInfo, Station, Status
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
@ -23,21 +25,15 @@ async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up the tankerkoenig binary sensors."""
coordinator: TankerkoenigDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
stations = coordinator.stations.values()
entities = []
for station in stations:
sensor = StationOpenBinarySensorEntity(
async_add_entities(
StationOpenBinarySensorEntity(
station,
coordinator,
coordinator.show_on_map,
)
entities.append(sensor)
_LOGGER.debug("Added sensors %s", entities)
async_add_entities(entities)
for station in coordinator.stations.values()
)
class StationOpenBinarySensorEntity(TankerkoenigCoordinatorEntity, BinarySensorEntity):
@ -48,22 +44,21 @@ class StationOpenBinarySensorEntity(TankerkoenigCoordinatorEntity, BinarySensorE
def __init__(
self,
station: dict,
station: Station,
coordinator: TankerkoenigDataUpdateCoordinator,
show_on_map: bool,
) -> None:
"""Initialize the sensor."""
super().__init__(coordinator, station)
self._station_id = station["id"]
self._attr_unique_id = f"{station['id']}_status"
if show_on_map:
self._station_id = station.id
self._attr_unique_id = f"{station.id}_status"
if coordinator.show_on_map:
self._attr_extra_state_attributes = {
ATTR_LATITUDE: station["lat"],
ATTR_LONGITUDE: station["lng"],
ATTR_LATITUDE: station.lat,
ATTR_LONGITUDE: station.lng,
}
@property
def is_on(self) -> bool | None:
"""Return true if the station is open."""
data: dict = self.coordinator.data[self._station_id]
return data is not None and data.get("status") == "open"
data: PriceInfo = self.coordinator.data[self._station_id]
return data is not None and data.status == Status.OPEN