1 """IMGW-PIB sensor platform."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
8 from imgw_pib.model
import HydrologicalData
13 SensorEntityDescription,
21 from .
import ImgwPibConfigEntry
22 from .coordinator
import ImgwPibDataUpdateCoordinator
23 from .entity
import ImgwPibEntity
28 @dataclass(frozen=True, kw_only=True)
30 """IMGW-PIB sensor entity description."""
32 value: Callable[[HydrologicalData], StateType]
35 SENSOR_TYPES: tuple[ImgwPibSensorEntityDescription, ...] = (
37 key=
"flood_alarm_level",
38 translation_key=
"flood_alarm_level",
39 native_unit_of_measurement=UnitOfLength.CENTIMETERS,
40 device_class=SensorDeviceClass.DISTANCE,
41 entity_category=EntityCategory.DIAGNOSTIC,
42 suggested_display_precision=0,
43 entity_registry_enabled_default=
False,
44 value=
lambda data: data.flood_alarm_level.value,
47 key=
"flood_warning_level",
48 translation_key=
"flood_warning_level",
49 native_unit_of_measurement=UnitOfLength.CENTIMETERS,
50 device_class=SensorDeviceClass.DISTANCE,
51 entity_category=EntityCategory.DIAGNOSTIC,
52 suggested_display_precision=0,
53 entity_registry_enabled_default=
False,
54 value=
lambda data: data.flood_warning_level.value,
58 translation_key=
"water_level",
59 native_unit_of_measurement=UnitOfLength.CENTIMETERS,
60 device_class=SensorDeviceClass.DISTANCE,
61 state_class=SensorStateClass.MEASUREMENT,
62 suggested_display_precision=0,
63 value=
lambda data: data.water_level.value,
66 key=
"water_temperature",
67 translation_key=
"water_temperature",
68 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
69 device_class=SensorDeviceClass.TEMPERATURE,
70 state_class=SensorStateClass.MEASUREMENT,
71 suggested_display_precision=1,
72 value=
lambda data: data.water_temperature.value,
79 entry: ImgwPibConfigEntry,
80 async_add_entities: AddEntitiesCallback,
82 """Add a IMGW-PIB sensor entity from a config_entry."""
83 coordinator = entry.runtime_data.coordinator
87 for description
in SENSOR_TYPES
88 if getattr(coordinator.data, description.key).value
is not None
93 """Define IMGW-PIB sensor entity."""
95 entity_description: ImgwPibSensorEntityDescription
99 coordinator: ImgwPibDataUpdateCoordinator,
100 description: ImgwPibSensorEntityDescription,
110 """Return the value reported by the sensor."""
None __init__(self, ImgwPibDataUpdateCoordinator coordinator, ImgwPibSensorEntityDescription description)
StateType native_value(self)
None async_setup_entry(HomeAssistant hass, ImgwPibConfigEntry entry, AddEntitiesCallback async_add_entities)