Use device class enum in Onewire (#60766)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
1268cefc38
commit
7363033ada
2 changed files with 67 additions and 75 deletions
|
@ -18,17 +18,13 @@ from homeassistant.components.onewire.model import (
|
|||
from homeassistant.components.sensor import (
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_TYPE,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
DEVICE_CLASS_PRESSURE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
|
@ -64,7 +60,7 @@ class OneWireSensorEntityDescription(OneWireEntityDescription, SensorEntityDescr
|
|||
|
||||
SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION = OneWireSensorEntityDescription(
|
||||
key="temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
|
@ -79,7 +75,7 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
"12": (
|
||||
OneWireSensorEntityDescription(
|
||||
key="TAI8570/temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
|
@ -88,7 +84,7 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="TAI8570/pressure",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Pressure",
|
||||
native_unit_of_measurement=PRESSURE_MBAR,
|
||||
|
@ -101,7 +97,7 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION,
|
||||
OneWireSensorEntityDescription(
|
||||
key="humidity",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
device_class=SensorDeviceClass.HUMIDITY,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Humidity",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
|
@ -110,7 +106,7 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="HIH3600/humidity",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
device_class=SensorDeviceClass.HUMIDITY,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Humidity HIH3600",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
|
@ -119,7 +115,7 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="HIH4000/humidity",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
device_class=SensorDeviceClass.HUMIDITY,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Humidity HIH4000",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
|
@ -128,7 +124,7 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="HIH5030/humidity",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
device_class=SensorDeviceClass.HUMIDITY,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Humidity HIH5030",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
|
@ -137,7 +133,7 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="HTM1735/humidity",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
device_class=SensorDeviceClass.HUMIDITY,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Humidity HTM1735",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
|
@ -146,7 +142,7 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="B1-R1-A/pressure",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Pressure",
|
||||
native_unit_of_measurement=PRESSURE_MBAR,
|
||||
|
@ -155,7 +151,7 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="S3-R1-A/illuminance",
|
||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
||||
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Illuminance",
|
||||
native_unit_of_measurement=LIGHT_LUX,
|
||||
|
@ -164,7 +160,7 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="VAD",
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Voltage VAD",
|
||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
|
@ -173,7 +169,7 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="VDD",
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Voltage VDD",
|
||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
|
@ -182,7 +178,7 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="vis",
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
entity_registry_enabled_default=False,
|
||||
name="vis",
|
||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
|
@ -219,7 +215,7 @@ HOBBYBOARD_EF: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
"HobbyBoards_EF": (
|
||||
OneWireSensorEntityDescription(
|
||||
key="humidity/humidity_corrected",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
device_class=SensorDeviceClass.HUMIDITY,
|
||||
name="Humidity",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
|
@ -227,7 +223,7 @@ HOBBYBOARD_EF: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="humidity/humidity_raw",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
device_class=SensorDeviceClass.HUMIDITY,
|
||||
name="Humidity Raw",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
|
@ -235,7 +231,7 @@ HOBBYBOARD_EF: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="humidity/temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
|
@ -245,7 +241,7 @@ HOBBYBOARD_EF: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
"HB_MOISTURE_METER": (
|
||||
OneWireSensorEntityDescription(
|
||||
key="moisture/sensor.0",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
name="Moisture 0",
|
||||
native_unit_of_measurement=PRESSURE_CBAR,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
|
@ -253,7 +249,7 @@ HOBBYBOARD_EF: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="moisture/sensor.1",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
name="Moisture 1",
|
||||
native_unit_of_measurement=PRESSURE_CBAR,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
|
@ -261,7 +257,7 @@ HOBBYBOARD_EF: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="moisture/sensor.2",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
name="Moisture 2",
|
||||
native_unit_of_measurement=PRESSURE_CBAR,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
|
@ -269,7 +265,7 @@ HOBBYBOARD_EF: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="moisture/sensor.3",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
name="Moisture 3",
|
||||
native_unit_of_measurement=PRESSURE_CBAR,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
|
@ -284,7 +280,7 @@ EDS_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
"EDS0066": (
|
||||
OneWireSensorEntityDescription(
|
||||
key="EDS0066/temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
|
@ -292,7 +288,7 @@ EDS_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="EDS0066/pressure",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
name="Pressure",
|
||||
native_unit_of_measurement=PRESSURE_MBAR,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
|
@ -302,7 +298,7 @@ EDS_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
"EDS0068": (
|
||||
OneWireSensorEntityDescription(
|
||||
key="EDS0068/temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
|
@ -310,7 +306,7 @@ EDS_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="EDS0068/pressure",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
name="Pressure",
|
||||
native_unit_of_measurement=PRESSURE_MBAR,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
|
@ -318,7 +314,7 @@ EDS_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="EDS0068/light",
|
||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
||||
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||
name="Illuminance",
|
||||
native_unit_of_measurement=LIGHT_LUX,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
|
@ -326,7 +322,7 @@ EDS_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
|||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="EDS0068/humidity",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
device_class=SensorDeviceClass.HUMIDITY,
|
||||
name="Humidity",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
|
@ -404,7 +400,7 @@ def get_entities(
|
|||
)
|
||||
if is_leaf:
|
||||
description = copy.deepcopy(description)
|
||||
description.device_class = DEVICE_CLASS_HUMIDITY
|
||||
description.device_class = SensorDeviceClass.HUMIDITY
|
||||
description.native_unit_of_measurement = PERCENTAGE
|
||||
description.name = f"Wetness {s_id}"
|
||||
device_file = os.path.join(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue