1 """Support for P1 Monitor sensors."""
3 from __future__
import annotations
5 from typing
import Literal
10 SensorEntityDescription,
17 UnitOfElectricCurrent,
18 UnitOfElectricPotential,
36 from .coordinator
import P1MonitorDataUpdateCoordinator
38 SENSORS_SMARTMETER: tuple[SensorEntityDescription, ...] = (
40 key=
"gas_consumption",
41 translation_key=
"gas_consumption",
42 entity_registry_enabled_default=
False,
43 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
44 device_class=SensorDeviceClass.GAS,
45 state_class=SensorStateClass.TOTAL_INCREASING,
48 key=
"power_consumption",
49 translation_key=
"power_consumption",
50 native_unit_of_measurement=UnitOfPower.WATT,
51 device_class=SensorDeviceClass.POWER,
52 state_class=SensorStateClass.MEASUREMENT,
55 key=
"energy_consumption_high",
56 translation_key=
"energy_consumption_high",
57 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
58 device_class=SensorDeviceClass.ENERGY,
59 state_class=SensorStateClass.TOTAL_INCREASING,
62 key=
"energy_consumption_low",
63 translation_key=
"energy_consumption_low",
64 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
65 device_class=SensorDeviceClass.ENERGY,
66 state_class=SensorStateClass.TOTAL_INCREASING,
69 key=
"power_production",
70 translation_key=
"power_production",
71 native_unit_of_measurement=UnitOfPower.WATT,
72 device_class=SensorDeviceClass.POWER,
73 state_class=SensorStateClass.MEASUREMENT,
76 key=
"energy_production_high",
77 translation_key=
"energy_production_high",
78 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
79 device_class=SensorDeviceClass.ENERGY,
80 state_class=SensorStateClass.TOTAL_INCREASING,
83 key=
"energy_production_low",
84 translation_key=
"energy_production_low",
85 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
86 device_class=SensorDeviceClass.ENERGY,
87 state_class=SensorStateClass.TOTAL_INCREASING,
90 key=
"energy_tariff_period",
91 translation_key=
"energy_tariff_period",
95 SENSORS_PHASES: tuple[SensorEntityDescription, ...] = (
97 key=
"voltage_phase_l1",
98 translation_key=
"voltage_phase_l1",
99 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
100 device_class=SensorDeviceClass.VOLTAGE,
101 state_class=SensorStateClass.MEASUREMENT,
104 key=
"voltage_phase_l2",
105 translation_key=
"voltage_phase_l2",
106 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
107 device_class=SensorDeviceClass.VOLTAGE,
108 state_class=SensorStateClass.MEASUREMENT,
111 key=
"voltage_phase_l3",
112 translation_key=
"voltage_phase_l3",
113 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
114 device_class=SensorDeviceClass.VOLTAGE,
115 state_class=SensorStateClass.MEASUREMENT,
118 key=
"current_phase_l1",
119 translation_key=
"current_phase_l1",
120 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
121 device_class=SensorDeviceClass.CURRENT,
122 state_class=SensorStateClass.MEASUREMENT,
125 key=
"current_phase_l2",
126 translation_key=
"current_phase_l2",
127 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
128 device_class=SensorDeviceClass.CURRENT,
129 state_class=SensorStateClass.MEASUREMENT,
132 key=
"current_phase_l3",
133 translation_key=
"current_phase_l3",
134 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
135 device_class=SensorDeviceClass.CURRENT,
136 state_class=SensorStateClass.MEASUREMENT,
139 key=
"power_consumed_phase_l1",
140 translation_key=
"power_consumed_phase_l1",
141 native_unit_of_measurement=UnitOfPower.WATT,
142 device_class=SensorDeviceClass.POWER,
143 state_class=SensorStateClass.MEASUREMENT,
146 key=
"power_consumed_phase_l2",
147 translation_key=
"power_consumed_phase_l2",
148 native_unit_of_measurement=UnitOfPower.WATT,
149 device_class=SensorDeviceClass.POWER,
150 state_class=SensorStateClass.MEASUREMENT,
153 key=
"power_consumed_phase_l3",
154 translation_key=
"power_consumed_phase_l3",
155 native_unit_of_measurement=UnitOfPower.WATT,
156 device_class=SensorDeviceClass.POWER,
157 state_class=SensorStateClass.MEASUREMENT,
160 key=
"power_produced_phase_l1",
161 translation_key=
"power_produced_phase_l1",
162 native_unit_of_measurement=UnitOfPower.WATT,
163 device_class=SensorDeviceClass.POWER,
164 state_class=SensorStateClass.MEASUREMENT,
167 key=
"power_produced_phase_l2",
168 translation_key=
"power_produced_phase_l2",
169 native_unit_of_measurement=UnitOfPower.WATT,
170 device_class=SensorDeviceClass.POWER,
171 state_class=SensorStateClass.MEASUREMENT,
174 key=
"power_produced_phase_l3",
175 translation_key=
"power_produced_phase_l3",
176 native_unit_of_measurement=UnitOfPower.WATT,
177 device_class=SensorDeviceClass.POWER,
178 state_class=SensorStateClass.MEASUREMENT,
182 SENSORS_SETTINGS: tuple[SensorEntityDescription, ...] = (
184 key=
"gas_consumption_price",
185 translation_key=
"gas_consumption_price",
186 entity_registry_enabled_default=
False,
187 state_class=SensorStateClass.MEASUREMENT,
188 native_unit_of_measurement=f
"{CURRENCY_EURO}/{UnitOfVolume.CUBIC_METERS}",
191 key=
"energy_consumption_price_low",
192 translation_key=
"energy_consumption_price_low",
193 state_class=SensorStateClass.MEASUREMENT,
194 native_unit_of_measurement=f
"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}",
197 key=
"energy_consumption_price_high",
198 translation_key=
"energy_consumption_price_high",
199 state_class=SensorStateClass.MEASUREMENT,
200 native_unit_of_measurement=f
"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}",
203 key=
"energy_production_price_low",
204 translation_key=
"energy_production_price_low",
205 state_class=SensorStateClass.MEASUREMENT,
206 native_unit_of_measurement=f
"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}",
209 key=
"energy_production_price_high",
210 translation_key=
"energy_production_price_high",
211 state_class=SensorStateClass.MEASUREMENT,
212 native_unit_of_measurement=f
"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}",
216 SENSORS_WATERMETER: tuple[SensorEntityDescription, ...] = (
218 key=
"consumption_day",
219 translation_key=
"consumption_day",
220 state_class=SensorStateClass.TOTAL_INCREASING,
221 native_unit_of_measurement=UnitOfVolume.LITERS,
222 device_class=SensorDeviceClass.WATER,
225 key=
"consumption_total",
226 translation_key=
"consumption_total",
227 state_class=SensorStateClass.TOTAL_INCREASING,
228 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
229 device_class=SensorDeviceClass.WATER,
233 translation_key=
"pulse_count",
239 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
241 """Set up P1 Monitor Sensors based on a config entry."""
242 entities: list[P1MonitorSensorEntity] = []
246 description=description,
248 service=SERVICE_SMARTMETER,
250 for description
in SENSORS_SMARTMETER
255 description=description,
257 service=SERVICE_PHASES,
259 for description
in SENSORS_PHASES
264 description=description,
266 service=SERVICE_SETTINGS,
268 for description
in SENSORS_SETTINGS
270 if entry.runtime_data.has_water_meter:
274 description=description,
276 service=SERVICE_WATERMETER,
278 for description
in SENSORS_WATERMETER
284 CoordinatorEntity[P1MonitorDataUpdateCoordinator], SensorEntity
286 """Defines an P1 Monitor sensor."""
288 _attr_has_entity_name =
True
294 description: SensorEntityDescription,
296 service: Literal[
"smartmeter",
"watermeter",
"phases",
"settings"],
298 """Initialize P1 Monitor sensor."""
299 super().
__init__(coordinator=entry.runtime_data)
304 f
"{entry.runtime_data.config_entry.entry_id}_{service}_{description.key}"
308 entry_type=DeviceEntryType.SERVICE,
310 (DOMAIN, f
"{entry.runtime_data.config_entry.entry_id}_{service}")
312 configuration_url=f
"http://{entry.runtime_data.config_entry.data[CONF_HOST]}",
313 manufacturer=
"P1 Monitor",
319 """Return the state of the sensor."""
323 if isinstance(value, str):
StateType native_value(self)
None __init__(self, *ConfigEntry entry, SensorEntityDescription description, str name, Literal["smartmeter", "watermeter", "phases", "settings"] service)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)