1 """Support for Palazzetti sensors."""
3 from dataclasses
import dataclass
8 SensorEntityDescription,
16 from .
import PalazzettiConfigEntry
17 from .coordinator
import PalazzettiDataUpdateCoordinator
18 from .entity
import PalazzettiEntity
21 @dataclass(frozen=True, kw_only=True)
23 """Describes a Palazzetti sensor entity that is read from a `PalazzettiClient` property."""
26 presence_flag:
None | str =
None
29 PROPERTY_SENSOR_DESCRIPTIONS: list[PropertySensorEntityDescription] = [
31 key=
"pellet_quantity",
32 device_class=SensorDeviceClass.WEIGHT,
33 native_unit_of_measurement=UnitOfMass.KILOGRAMS,
34 state_class=SensorStateClass.MEASUREMENT,
35 translation_key=
"pellet_quantity",
36 client_property=
"pellet_quantity",
40 device_class=SensorDeviceClass.DISTANCE,
41 native_unit_of_measurement=UnitOfLength.CENTIMETERS,
42 state_class=SensorStateClass.MEASUREMENT,
43 translation_key=
"pellet_level",
44 presence_flag=
"has_pellet_level",
45 client_property=
"pellet_level",
52 entry: PalazzettiConfigEntry,
53 async_add_entities: AddEntitiesCallback,
55 """Set up Palazzetti sensor entities based on a config entry."""
57 coordinator = entry.runtime_data
63 key=sensor.description_key.value,
64 device_class=SensorDeviceClass.TEMPERATURE,
65 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
66 state_class=SensorStateClass.MEASUREMENT,
67 translation_key=sensor.description_key.value,
68 client_property=sensor.state_property,
71 for sensor
in coordinator.client.list_temperatures()
77 for description
in PROPERTY_SENSOR_DESCRIPTIONS
78 if not description.presence_flag
79 or getattr(coordinator.client, description.presence_flag)
88 """Define a Palazzetti sensor."""
90 entity_description: PropertySensorEntityDescription
94 coordinator: PalazzettiDataUpdateCoordinator,
95 description: PropertySensorEntityDescription,
97 """Initialize Palazzetti sensor."""
100 self.
_attr_unique_id_attr_unique_id = f
"{coordinator.config_entry.unique_id}-{description.key}"
104 """Return the state value of the sensor."""
106 return getattr(self.coordinator.client, self.
entity_descriptionentity_description.client_property)
None __init__(self, PalazzettiDataUpdateCoordinator coordinator, PropertySensorEntityDescription description)
StateType native_value(self)
None async_setup_entry(HomeAssistant hass, PalazzettiConfigEntry entry, AddEntitiesCallback async_add_entities)