1 """Sensor platform for Garages Amsterdam."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
8 from odp_amsterdam
import Garage
12 SensorEntityDescription,
19 from .
import GaragesAmsterdamConfigEntry
20 from .coordinator
import GaragesAmsterdamDataUpdateCoordinator
21 from .entity
import GaragesAmsterdamEntity
24 @dataclass(frozen=True, kw_only=True)
26 """Class describing Garages Amsterdam sensor entity."""
28 value_fn: Callable[[Garage], StateType]
31 SENSORS: tuple[GaragesAmsterdamSensorEntityDescription, ...] = (
33 key=
"free_space_short",
34 translation_key=
"free_space_short",
35 state_class=SensorStateClass.MEASUREMENT,
36 value_fn=
lambda garage: garage.free_space_short,
39 key=
"free_space_long",
40 translation_key=
"free_space_long",
41 state_class=SensorStateClass.MEASUREMENT,
42 value_fn=
lambda garage: garage.free_space_long,
46 translation_key=
"short_capacity",
47 value_fn=
lambda garage: garage.short_capacity,
51 translation_key=
"long_capacity",
52 value_fn=
lambda garage: garage.long_capacity,
59 entry: GaragesAmsterdamConfigEntry,
60 async_add_entities: AddEntitiesCallback,
62 """Defer sensor setup to the shared sensor module."""
63 coordinator = entry.runtime_data
67 coordinator=coordinator,
68 garage_name=entry.data[
"garage_name"],
69 description=description,
71 for description
in SENSORS
72 if description.value_fn(coordinator.data[entry.data[
"garage_name"]])
is not None
77 """Sensor representing garages amsterdam data."""
79 entity_description: GaragesAmsterdamSensorEntityDescription
84 coordinator: GaragesAmsterdamDataUpdateCoordinator,
86 description: GaragesAmsterdamSensorEntityDescription,
88 """Initialize garages amsterdam sensor."""
89 super().
__init__(coordinator, garage_name)
95 """Return if sensor is available."""
96 return self.coordinator.last_update_success
and (
102 """Return the state of the sensor."""
StateType native_value(self)
None __init__(self, *GaragesAmsterdamDataUpdateCoordinator coordinator, str garage_name, GaragesAmsterdamSensorEntityDescription description)
None async_setup_entry(HomeAssistant hass, GaragesAmsterdamConfigEntry entry, AddEntitiesCallback async_add_entities)