From c875d726b1b9202d7d0b37abd595decc08ddeaf8 Mon Sep 17 00:00:00 2001 From: ollo69 <60491700+ollo69@users.noreply.github.com> Date: Thu, 2 Dec 2021 03:11:19 +0100 Subject: [PATCH] Use state and device class enums in Nut (#60810) --- homeassistant/components/nut/const.py | 78 +++++++++++++-------------- 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/homeassistant/components/nut/const.py b/homeassistant/components/nut/const.py index 12306b63dc1..11b07f04b78 100644 --- a/homeassistant/components/nut/const.py +++ b/homeassistant/components/nut/const.py @@ -5,13 +5,9 @@ from __future__ import annotations from typing import Final from homeassistant.components.sensor import ( - DEVICE_CLASS_BATTERY, - DEVICE_CLASS_HUMIDITY, - DEVICE_CLASS_POWER, - DEVICE_CLASS_TEMPERATURE, - DEVICE_CLASS_VOLTAGE, - STATE_CLASS_MEASUREMENT, + SensorDeviceClass, SensorEntityDescription, + SensorStateClass, ) from homeassistant.const import ( ELECTRIC_CURRENT_AMPERE, @@ -64,8 +60,8 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="ups.temperature", name="UPS Temperature", native_unit_of_measurement=TEMP_CELSIUS, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -74,7 +70,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { name="Load", native_unit_of_measurement=PERCENTAGE, icon="mdi:gauge", - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, ), "ups.load.high": SensorEntityDescription( key="ups.load.high", @@ -180,7 +176,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { name="Efficiency", native_unit_of_measurement=PERCENTAGE, icon="mdi:gauge", - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -189,7 +185,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { name="Current Apparent Power", native_unit_of_measurement=POWER_VOLT_AMPERE, icon="mdi:flash", - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -205,8 +201,8 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="ups.realpower", name="Current Real Power", native_unit_of_measurement=POWER_WATT, - device_class=DEVICE_CLASS_POWER, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.POWER, + state_class=SensorStateClass.MEASUREMENT, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -214,7 +210,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="ups.realpower.nominal", name="Nominal Real Power", native_unit_of_measurement=POWER_WATT, - device_class=DEVICE_CLASS_POWER, + device_class=SensorDeviceClass.POWER, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -271,8 +267,8 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="battery.charge", name="Battery Charge", native_unit_of_measurement=PERCENTAGE, - device_class=DEVICE_CLASS_BATTERY, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.BATTERY, + state_class=SensorStateClass.MEASUREMENT, ), "battery.charge.low": SensorEntityDescription( key="battery.charge.low", @@ -307,8 +303,8 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="battery.voltage", name="Battery Voltage", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, - device_class=DEVICE_CLASS_VOLTAGE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.VOLTAGE, + state_class=SensorStateClass.MEASUREMENT, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -316,7 +312,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="battery.voltage.nominal", name="Nominal Battery Voltage", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, - device_class=DEVICE_CLASS_VOLTAGE, + device_class=SensorDeviceClass.VOLTAGE, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -324,7 +320,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="battery.voltage.low", name="Low Battery Voltage", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, - device_class=DEVICE_CLASS_VOLTAGE, + device_class=SensorDeviceClass.VOLTAGE, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -332,7 +328,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="battery.voltage.high", name="High Battery Voltage", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, - device_class=DEVICE_CLASS_VOLTAGE, + device_class=SensorDeviceClass.VOLTAGE, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -349,7 +345,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { name="Battery Current", native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE, icon="mdi:flash", - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -365,8 +361,8 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="battery.temperature", name="Battery Temperature", native_unit_of_measurement=TEMP_CELSIUS, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -447,7 +443,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="input.transfer.low", name="Low Voltage Transfer", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, - device_class=DEVICE_CLASS_VOLTAGE, + device_class=SensorDeviceClass.VOLTAGE, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -455,7 +451,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="input.transfer.high", name="High Voltage Transfer", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, - device_class=DEVICE_CLASS_VOLTAGE, + device_class=SensorDeviceClass.VOLTAGE, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -470,14 +466,14 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="input.voltage", name="Input Voltage", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, - device_class=DEVICE_CLASS_VOLTAGE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.VOLTAGE, + state_class=SensorStateClass.MEASUREMENT, ), "input.voltage.nominal": SensorEntityDescription( key="input.voltage.nominal", name="Nominal Input Voltage", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, - device_class=DEVICE_CLASS_VOLTAGE, + device_class=SensorDeviceClass.VOLTAGE, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -486,7 +482,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { name="Input Line Frequency", native_unit_of_measurement=FREQUENCY_HERTZ, icon="mdi:flash", - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -510,7 +506,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { name="Output Current", native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE, icon="mdi:flash", - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -526,14 +522,14 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="output.voltage", name="Output Voltage", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, - device_class=DEVICE_CLASS_VOLTAGE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.VOLTAGE, + state_class=SensorStateClass.MEASUREMENT, ), "output.voltage.nominal": SensorEntityDescription( key="output.voltage.nominal", name="Nominal Output Voltage", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, - device_class=DEVICE_CLASS_VOLTAGE, + device_class=SensorDeviceClass.VOLTAGE, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -542,7 +538,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { name="Output Frequency", native_unit_of_measurement=FREQUENCY_HERTZ, icon="mdi:flash", - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -558,8 +554,8 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="ambient.humidity", name="Ambient Humidity", native_unit_of_measurement=PERCENTAGE, - device_class=DEVICE_CLASS_HUMIDITY, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.HUMIDITY, + state_class=SensorStateClass.MEASUREMENT, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -567,8 +563,8 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="ambient.temperature", name="Ambient Temperature", native_unit_of_measurement=TEMP_CELSIUS, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -576,8 +572,8 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { key="watts", name="Watts", native_unit_of_measurement=POWER_WATT, - device_class=DEVICE_CLASS_POWER, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.POWER, + state_class=SensorStateClass.MEASUREMENT, ), }