1 """Representation of a sensorMultilevel."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
8 from zwave_me_ws
import ZWaveMeData
13 SensorEntityDescription,
20 UnitOfElectricCurrent,
21 UnitOfElectricPotential,
31 from .
import ZWaveMeController
32 from .const
import DOMAIN, ZWaveMePlatform
33 from .entity
import ZWaveMeEntity
36 @dataclass(frozen=True)
38 """Class describing ZWaveMeSensor sensor entities."""
40 value: Callable =
lambda value: value
43 SENSORS_MAP: dict[str, ZWaveMeSensorEntityDescription] = {
46 device_class=SensorDeviceClass.PRESSURE,
47 native_unit_of_measurement=UnitOfPressure.KPA,
48 state_class=SensorStateClass.MEASUREMENT,
52 device_class=SensorDeviceClass.CO,
53 native_unit_of_measurement=
"ppm",
54 state_class=SensorStateClass.MEASUREMENT,
58 device_class=SensorDeviceClass.CO2,
59 native_unit_of_measurement=
"ppm",
60 state_class=SensorStateClass.MEASUREMENT,
64 device_class=SensorDeviceClass.HUMIDITY,
65 native_unit_of_measurement=PERCENTAGE,
66 state_class=SensorStateClass.MEASUREMENT,
70 device_class=SensorDeviceClass.ILLUMINANCE,
71 native_unit_of_measurement=LIGHT_LUX,
72 state_class=SensorStateClass.MEASUREMENT,
75 key=
"meterElectric_ampere",
76 device_class=SensorDeviceClass.CURRENT,
77 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
78 state_class=SensorStateClass.MEASUREMENT,
81 key=
"meterElectric_kilowatt_hour",
82 device_class=SensorDeviceClass.ENERGY,
83 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
84 state_class=SensorStateClass.TOTAL_INCREASING,
87 key=
"meterElectric_power_factor",
88 device_class=SensorDeviceClass.POWER_FACTOR,
89 native_unit_of_measurement=PERCENTAGE,
90 state_class=SensorStateClass.MEASUREMENT,
91 value=
lambda value:
float(value) * 100,
94 key=
"meterElectric_voltage",
95 device_class=SensorDeviceClass.VOLTAGE,
96 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
97 state_class=SensorStateClass.MEASUREMENT,
100 key=
"meterElectric_watt",
101 device_class=SensorDeviceClass.POWER,
102 native_unit_of_measurement=UnitOfPower.WATT,
103 state_class=SensorStateClass.MEASUREMENT,
107 device_class=SensorDeviceClass.TEMPERATURE,
108 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
109 state_class=SensorStateClass.MEASUREMENT,
115 DEVICE_NAME = ZWaveMePlatform.SENSOR
120 config_entry: ConfigEntry,
121 async_add_entities: AddEntitiesCallback,
123 """Set up the sensor platform."""
127 controller: ZWaveMeController = hass.data[DOMAIN][config_entry.entry_id]
128 description = SENSORS_MAP.get(new_device.probeType, SENSORS_MAP[
"generic"])
137 config_entry.async_on_unload(
139 hass, f
"ZWAVE_ME_NEW_{DEVICE_NAME.upper()}", add_new_device
145 """Representation of a ZWaveMe sensor."""
147 entity_description: ZWaveMeSensorEntityDescription
151 controller: ZWaveMeController,
153 description: ZWaveMeSensorEntityDescription,
155 """Initialize the device."""
156 super().
__init__(controller=controller, device=device)
161 """Return the state of the sensor."""
None __init__(self, ZWaveMeController controller, ZWaveMeData device, ZWaveMeSensorEntityDescription description)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
def add_new_device(new_device)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)