1 """The sensor platform for the A. O. Smith integration."""
3 from collections.abc
import Callable
4 from dataclasses
import dataclass
6 from py_aosmith.models
import Device
as AOSmithDevice
11 SensorEntityDescription,
18 from .
import AOSmithConfigEntry
19 from .coordinator
import AOSmithEnergyCoordinator, AOSmithStatusCoordinator
20 from .entity
import AOSmithEnergyEntity, AOSmithStatusEntity
23 @dataclass(frozen=True, kw_only=True)
25 """Entity description class for sensors using data from the status coordinator."""
27 value_fn: Callable[[AOSmithDevice], str | int |
None]
30 STATUS_ENTITY_DESCRIPTIONS: tuple[AOSmithStatusSensorEntityDescription, ...] = (
32 key=
"hot_water_availability",
33 translation_key=
"hot_water_availability",
34 native_unit_of_measurement=PERCENTAGE,
35 value_fn=
lambda device: device.status.hot_water_status,
42 entry: AOSmithConfigEntry,
43 async_add_entities: AddEntitiesCallback,
45 """Set up A. O. Smith sensor platform."""
46 data = entry.runtime_data
50 for description
in STATUS_ENTITY_DESCRIPTIONS
51 for junction_id
in data.status_coordinator.data
56 for junction_id
in data.status_coordinator.data
61 """Class for sensor entities that use data from the status coordinator."""
63 entity_description: AOSmithStatusSensorEntityDescription
67 coordinator: AOSmithStatusCoordinator,
68 description: AOSmithStatusSensorEntityDescription,
71 """Initialize the entity."""
72 super().
__init__(coordinator, junction_id)
78 """Return the state of the sensor."""
83 """Class for the energy sensor entity."""
85 _attr_translation_key =
"energy_usage"
86 _attr_device_class = SensorDeviceClass.ENERGY
87 _attr_state_class = SensorStateClass.TOTAL_INCREASING
88 _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
89 _attr_suggested_display_precision = 1
93 coordinator: AOSmithEnergyCoordinator,
96 """Initialize the entity."""
97 super().
__init__(coordinator, junction_id)
102 """Return the state of the sensor."""
AOSmithDevice device(self)
float|None native_value(self)
None __init__(self, AOSmithEnergyCoordinator coordinator, str junction_id)
None __init__(self, AOSmithStatusCoordinator coordinator, AOSmithStatusSensorEntityDescription description, str junction_id)
str|int|None native_value(self)
None async_setup_entry(HomeAssistant hass, AOSmithConfigEntry entry, AddEntitiesCallback async_add_entities)