Add Z-Wave.Me SensorMultilevels types (#68585)
* Added SensorMultilevels types * Fixed sort and spaces * co, co2 * PF -> PERCENTAGE * POWER_FACTOR to PERCENTAGE * Fix import sorting * Whitespaces for flake8 * Whitespaces * Whitespaces * Fixed entity_description type Co-authored-by: aivs <aivs@yandex.ru> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>pull/70658/head
parent
1af7c26741
commit
5b9e3a5e7b
|
@ -1,6 +1,9 @@
|
|||
"""Representation of a sensorMultilevel."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
|
||||
from zwave_me_ws import ZWaveMeData
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
|
@ -11,11 +14,13 @@ from homeassistant.components.sensor import (
|
|||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ELECTRIC_CURRENT_AMPERE,
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
POWER_WATT,
|
||||
SIGNAL_STRENGTH_DECIBELS,
|
||||
PRESSURE_KPA,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
@ -25,50 +30,83 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from . import ZWaveMeController, ZWaveMeEntity
|
||||
from .const import DOMAIN, ZWaveMePlatform
|
||||
|
||||
SENSORS_MAP: dict[str, SensorEntityDescription] = {
|
||||
"meterElectric_watt": SensorEntityDescription(
|
||||
key="meterElectric_watt",
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
|
||||
@dataclass
|
||||
class ZWaveMeSensorEntityDescription(SensorEntityDescription):
|
||||
"""Class describing ZWaveMeSensor sensor entities."""
|
||||
|
||||
value: Callable = lambda value: value
|
||||
|
||||
|
||||
SENSORS_MAP: dict[str, ZWaveMeSensorEntityDescription] = {
|
||||
"barometer": ZWaveMeSensorEntityDescription(
|
||||
key="barometer",
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
native_unit_of_measurement=PRESSURE_KPA,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"meterElectric_kilowatt_hour": SensorEntityDescription(
|
||||
"co": ZWaveMeSensorEntityDescription(
|
||||
key="co",
|
||||
device_class=SensorDeviceClass.CO,
|
||||
native_unit_of_measurement="ppm",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"co2": ZWaveMeSensorEntityDescription(
|
||||
key="co2",
|
||||
device_class=SensorDeviceClass.CO2,
|
||||
native_unit_of_measurement="ppm",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"humidity": ZWaveMeSensorEntityDescription(
|
||||
key="humidity",
|
||||
device_class=SensorDeviceClass.HUMIDITY,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"luminosity": ZWaveMeSensorEntityDescription(
|
||||
key="luminosity",
|
||||
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||
native_unit_of_measurement=LIGHT_LUX,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"meterElectric_ampere": ZWaveMeSensorEntityDescription(
|
||||
key="meterElectric_ampere",
|
||||
device_class=SensorDeviceClass.CURRENT,
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"meterElectric_kilowatt_hour": ZWaveMeSensorEntityDescription(
|
||||
key="meterElectric_kilowatt_hour",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
),
|
||||
"meterElectric_voltage": SensorEntityDescription(
|
||||
"meterElectric_power_factor": ZWaveMeSensorEntityDescription(
|
||||
key="meterElectric_power_factor",
|
||||
device_class=SensorDeviceClass.POWER_FACTOR,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
value=lambda value: float(value) * 100,
|
||||
),
|
||||
"meterElectric_voltage": ZWaveMeSensorEntityDescription(
|
||||
key="meterElectric_voltage",
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"light": SensorEntityDescription(
|
||||
key="light",
|
||||
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||
native_unit_of_measurement=LIGHT_LUX,
|
||||
"meterElectric_watt": ZWaveMeSensorEntityDescription(
|
||||
key="meterElectric_watt",
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"noise": SensorEntityDescription(
|
||||
key="noise",
|
||||
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
|
||||
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"currentTemperature": SensorEntityDescription(
|
||||
key="currentTemperature",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"temperature": SensorEntityDescription(
|
||||
"temperature": ZWaveMeSensorEntityDescription(
|
||||
key="temperature",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"generic": SensorEntityDescription(
|
||||
"generic": ZWaveMeSensorEntityDescription(
|
||||
key="generic",
|
||||
),
|
||||
}
|
||||
|
@ -104,11 +142,13 @@ async def async_setup_entry(
|
|||
class ZWaveMeSensor(ZWaveMeEntity, SensorEntity):
|
||||
"""Representation of a ZWaveMe sensor."""
|
||||
|
||||
entity_description: ZWaveMeSensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
controller: ZWaveMeController,
|
||||
device: ZWaveMeData,
|
||||
description: SensorEntityDescription,
|
||||
description: ZWaveMeSensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the device."""
|
||||
super().__init__(controller=controller, device=device)
|
||||
|
@ -117,4 +157,4 @@ class ZWaveMeSensor(ZWaveMeEntity, SensorEntity):
|
|||
@property
|
||||
def native_value(self) -> str:
|
||||
"""Return the state of the sensor."""
|
||||
return self.device.level
|
||||
return self.entity_description.value(self.device.level)
|
||||
|
|
Loading…
Reference in New Issue