1 """Platform for sensor integration."""
3 from collections.abc
import Callable
4 from dataclasses
import dataclass
6 from weheat.abstractions.heat_pump
import HeatPump
11 SensorEntityDescription,
19 from .
import WeheatConfigEntry
21 DISPLAY_PRECISION_COP,
22 DISPLAY_PRECISION_WATER_TEMP,
23 DISPLAY_PRECISION_WATTS,
25 from .coordinator
import WeheatDataUpdateCoordinator
26 from .entity
import WeheatEntity
29 @dataclass(frozen=True, kw_only=True)
31 """Describes Weheat sensor entity."""
33 value_fn: Callable[[HeatPump], StateType]
38 translation_key=
"power_output",
40 native_unit_of_measurement=UnitOfPower.WATT,
41 device_class=SensorDeviceClass.POWER,
42 state_class=SensorStateClass.MEASUREMENT,
43 suggested_display_precision=DISPLAY_PRECISION_WATTS,
44 value_fn=
lambda status: status.power_output,
47 translation_key=
"power_input",
49 native_unit_of_measurement=UnitOfPower.WATT,
50 device_class=SensorDeviceClass.POWER,
51 state_class=SensorStateClass.MEASUREMENT,
52 suggested_display_precision=DISPLAY_PRECISION_WATTS,
53 value_fn=
lambda status: status.power_input,
56 translation_key=
"cop",
58 state_class=SensorStateClass.MEASUREMENT,
59 suggested_display_precision=DISPLAY_PRECISION_COP,
60 value_fn=
lambda status: status.cop,
63 translation_key=
"water_inlet_temperature",
64 key=
"water_inlet_temperature",
65 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
66 device_class=SensorDeviceClass.TEMPERATURE,
67 state_class=SensorStateClass.MEASUREMENT,
68 suggested_display_precision=DISPLAY_PRECISION_WATER_TEMP,
69 value_fn=
lambda status: status.water_inlet_temperature,
72 translation_key=
"water_outlet_temperature",
73 key=
"water_outlet_temperature",
74 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
75 device_class=SensorDeviceClass.TEMPERATURE,
76 state_class=SensorStateClass.MEASUREMENT,
77 suggested_display_precision=DISPLAY_PRECISION_WATER_TEMP,
78 value_fn=
lambda status: status.water_outlet_temperature,
81 translation_key=
"ch_inlet_temperature",
82 key=
"ch_inlet_temperature",
83 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
84 device_class=SensorDeviceClass.TEMPERATURE,
85 state_class=SensorStateClass.MEASUREMENT,
86 suggested_display_precision=DISPLAY_PRECISION_WATER_TEMP,
87 value_fn=
lambda status: status.water_house_in_temperature,
90 translation_key=
"outside_temperature",
91 key=
"outside_temperature",
92 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
93 device_class=SensorDeviceClass.TEMPERATURE,
94 state_class=SensorStateClass.MEASUREMENT,
95 suggested_display_precision=DISPLAY_PRECISION_WATER_TEMP,
96 value_fn=
lambda status: status.air_inlet_temperature,
99 translation_key=
"thermostat_water_setpoint",
100 key=
"thermostat_water_setpoint",
101 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
102 device_class=SensorDeviceClass.TEMPERATURE,
103 state_class=SensorStateClass.MEASUREMENT,
104 suggested_display_precision=DISPLAY_PRECISION_WATER_TEMP,
105 value_fn=
lambda status: status.thermostat_water_setpoint,
108 translation_key=
"thermostat_room_temperature",
109 key=
"thermostat_room_temperature",
110 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
111 device_class=SensorDeviceClass.TEMPERATURE,
112 state_class=SensorStateClass.MEASUREMENT,
113 suggested_display_precision=DISPLAY_PRECISION_WATER_TEMP,
114 value_fn=
lambda status: status.thermostat_room_temperature,
117 translation_key=
"thermostat_room_temperature_setpoint",
118 key=
"thermostat_room_temperature_setpoint",
119 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
120 device_class=SensorDeviceClass.TEMPERATURE,
121 state_class=SensorStateClass.MEASUREMENT,
122 suggested_display_precision=DISPLAY_PRECISION_WATER_TEMP,
123 value_fn=
lambda status: status.thermostat_room_temperature_setpoint,
126 translation_key=
"heat_pump_state",
127 key=
"heat_pump_state",
129 device_class=SensorDeviceClass.ENUM,
130 options=[s.name.lower()
for s
in HeatPump.State],
132 lambda status: status.heat_pump_state.name.lower()
133 if status.heat_pump_state
138 translation_key=
"electricity_used",
139 key=
"electricity_used",
140 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
141 device_class=SensorDeviceClass.ENERGY,
142 state_class=SensorStateClass.TOTAL_INCREASING,
143 value_fn=
lambda status: status.energy_total,
150 translation_key=
"dhw_top_temperature",
151 key=
"dhw_top_temperature",
152 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
153 device_class=SensorDeviceClass.TEMPERATURE,
154 state_class=SensorStateClass.MEASUREMENT,
155 suggested_display_precision=DISPLAY_PRECISION_WATER_TEMP,
156 value_fn=
lambda status: status.dhw_top_temperature,
159 translation_key=
"dhw_bottom_temperature",
160 key=
"dhw_bottom_temperature",
161 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
162 device_class=SensorDeviceClass.TEMPERATURE,
163 state_class=SensorStateClass.MEASUREMENT,
164 suggested_display_precision=DISPLAY_PRECISION_WATER_TEMP,
165 value_fn=
lambda status: status.dhw_bottom_temperature,
172 entry: WeheatConfigEntry,
173 async_add_entities: AddEntitiesCallback,
175 """Set up the sensors for weheat heat pump."""
178 for entity_description
in SENSORS
179 for coordinator
in entry.runtime_data
183 for entity_description
in DHW_SENSORS
184 for coordinator
in entry.runtime_data
185 if coordinator.heat_pump_info.has_dhw
192 """Defines a Weheat heat pump sensor."""
194 coordinator: WeheatDataUpdateCoordinator
195 entity_description: WeHeatSensorEntityDescription
199 coordinator: WeheatDataUpdateCoordinator,
200 entity_description: WeHeatSensorEntityDescription,
202 """Pass coordinator to CoordinatorEntity."""
207 self.
_attr_unique_id_attr_unique_id = f
"{coordinator.heatpump_id}_{entity_description.key}"
211 """Return the state of the sensor."""
None __init__(self, WeheatDataUpdateCoordinator coordinator, WeHeatSensorEntityDescription entity_description)
StateType native_value(self)
None async_setup_entry(HomeAssistant hass, WeheatConfigEntry entry, AddEntitiesCallback async_add_entities)