1 """Tankerkoenig sensor integration."""
3 from __future__
import annotations
7 from aiotankerkoenig
import GasType, Station
24 from .coordinator
import TankerkoenigConfigEntry, TankerkoenigDataUpdateCoordinator
25 from .entity
import TankerkoenigCoordinatorEntity
27 _LOGGER = logging.getLogger(__name__)
32 entry: TankerkoenigConfigEntry,
33 async_add_entities: AddEntitiesCallback,
35 """Set up the tankerkoenig sensors."""
36 coordinator = entry.runtime_data
39 for station
in coordinator.stations.values():
40 for fuel
in (GasType.E10, GasType.E5, GasType.DIESEL):
41 if getattr(station, fuel)
is None:
43 "Station %s %s (%s) does not offer %s fuel, skipping",
63 """Contains prices for fuel in a given station."""
65 _attr_attribution = ATTRIBUTION
66 _attr_state_class = SensorStateClass.MEASUREMENT
67 _attr_native_unit_of_measurement = CURRENCY_EURO
68 _unrecorded_attributes = frozenset(
86 coordinator: TankerkoenigDataUpdateCoordinator,
88 """Initialize the sensor."""
89 super().
__init__(coordinator, station)
94 attrs: dict[str, int | str | float |
None] = {
95 ATTR_BRAND: station.brand,
96 ATTR_FUEL_TYPE: fuel_type,
97 ATTR_STATION_NAME: station.name,
98 ATTR_STREET: station.street,
99 ATTR_HOUSE_NUMBER: station.house_number,
100 ATTR_POSTCODE: station.post_code,
101 ATTR_CITY: station.place,
104 if coordinator.show_on_map:
105 attrs[ATTR_LATITUDE] = station.lat
106 attrs[ATTR_LONGITUDE] = station.lng
111 """Return the current price for the fuel type."""
112 info = self.coordinator.data[self.
_station_id_station_id]
113 return getattr(info, self.
_fuel_type_fuel_type)
None __init__(self, GasType fuel_type, Station station, TankerkoenigDataUpdateCoordinator coordinator)
_attr_extra_state_attributes
None async_setup_entry(HomeAssistant hass, TankerkoenigConfigEntry entry, AddEntitiesCallback async_add_entities)