From fa38a2d0bfa68735db0aa35782c0787f625afdf5 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 9 Dec 2021 13:23:01 +0100 Subject: [PATCH] Use new enums in deconz (#61343) Co-authored-by: epenet --- .../components/deconz/binary_sensor.py | 27 +++++------- homeassistant/components/deconz/cover.py | 9 ++-- homeassistant/components/deconz/number.py | 4 +- homeassistant/components/deconz/sensor.py | 41 ++++++++----------- 4 files changed, 34 insertions(+), 47 deletions(-) diff --git a/homeassistant/components/deconz/binary_sensor.py b/homeassistant/components/deconz/binary_sensor.py index 475c631bdf8..32b444b115d 100644 --- a/homeassistant/components/deconz/binary_sensor.py +++ b/homeassistant/components/deconz/binary_sensor.py @@ -17,21 +17,16 @@ from pydeconz.sensor import ( ) from homeassistant.components.binary_sensor import ( - DEVICE_CLASS_GAS, - DEVICE_CLASS_MOISTURE, - DEVICE_CLASS_MOTION, - DEVICE_CLASS_OPENING, - DEVICE_CLASS_SMOKE, - DEVICE_CLASS_TAMPER, - DEVICE_CLASS_VIBRATION, DOMAIN, + BinarySensorDeviceClass, BinarySensorEntity, BinarySensorEntityDescription, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, ENTITY_CATEGORY_DIAGNOSTIC +from homeassistant.const import ATTR_TEMPERATURE from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import ATTR_DARK, ATTR_ON @@ -56,27 +51,27 @@ ATTR_VIBRATIONSTRENGTH = "vibrationstrength" ENTITY_DESCRIPTIONS = { CarbonMonoxide: BinarySensorEntityDescription( key="carbonmonoxide", - device_class=DEVICE_CLASS_GAS, + device_class=BinarySensorDeviceClass.GAS, ), Fire: BinarySensorEntityDescription( key="fire", - device_class=DEVICE_CLASS_SMOKE, + device_class=BinarySensorDeviceClass.SMOKE, ), OpenClose: BinarySensorEntityDescription( key="openclose", - device_class=DEVICE_CLASS_OPENING, + device_class=BinarySensorDeviceClass.OPENING, ), Presence: BinarySensorEntityDescription( key="presence", - device_class=DEVICE_CLASS_MOTION, + device_class=BinarySensorDeviceClass.MOTION, ), Vibration: BinarySensorEntityDescription( key="vibration", - device_class=DEVICE_CLASS_VIBRATION, + device_class=BinarySensorDeviceClass.VIBRATION, ), Water: BinarySensorEntityDescription( key="water", - device_class=DEVICE_CLASS_MOISTURE, + device_class=BinarySensorDeviceClass.MOISTURE, ), } @@ -186,8 +181,8 @@ class DeconzTampering(DeconzDevice, BinarySensorEntity): TYPE = DOMAIN _device: PydeconzSensor - _attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC - _attr_device_class = DEVICE_CLASS_TAMPER + _attr_entity_category = EntityCategory.DIAGNOSTIC + _attr_device_class = BinarySensorDeviceClass.TAMPER def __init__(self, device: PydeconzSensor, gateway: DeconzGateway) -> None: """Initialize deCONZ binary sensor.""" diff --git a/homeassistant/components/deconz/cover.py b/homeassistant/components/deconz/cover.py index 324452c4aa6..d3696783933 100644 --- a/homeassistant/components/deconz/cover.py +++ b/homeassistant/components/deconz/cover.py @@ -10,8 +10,6 @@ from pydeconz.light import Cover from homeassistant.components.cover import ( ATTR_POSITION, ATTR_TILT_POSITION, - DEVICE_CLASS_DAMPER, - DEVICE_CLASS_SHADE, DOMAIN, SUPPORT_CLOSE, SUPPORT_CLOSE_TILT, @@ -21,6 +19,7 @@ from homeassistant.components.cover import ( SUPPORT_SET_TILT_POSITION, SUPPORT_STOP, SUPPORT_STOP_TILT, + CoverDeviceClass, CoverEntity, ) from homeassistant.config_entries import ConfigEntry @@ -32,9 +31,9 @@ from .deconz_device import DeconzDevice from .gateway import DeconzGateway, get_gateway_from_config_entry DEVICE_CLASS = { - "Level controllable output": DEVICE_CLASS_DAMPER, - "Window covering controller": DEVICE_CLASS_SHADE, - "Window covering device": DEVICE_CLASS_SHADE, + "Level controllable output": CoverDeviceClass.DAMPER, + "Window covering controller": CoverDeviceClass.SHADE, + "Window covering device": CoverDeviceClass.SHADE, } diff --git a/homeassistant/components/deconz/number.py b/homeassistant/components/deconz/number.py index 300a10f9a27..fff70b9f7b5 100644 --- a/homeassistant/components/deconz/number.py +++ b/homeassistant/components/deconz/number.py @@ -13,9 +13,9 @@ from homeassistant.components.number import ( NumberEntityDescription, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ENTITY_CATEGORY_CONFIG from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback from .deconz_device import DeconzDevice @@ -37,7 +37,7 @@ class DeconzNumberEntityDescription( ): """Class describing deCONZ number entities.""" - entity_category = ENTITY_CATEGORY_CONFIG + entity_category = EntityCategory.CONFIG ENTITY_DESCRIPTIONS = { diff --git a/homeassistant/components/deconz/sensor.py b/homeassistant/components/deconz/sensor.py index e530e33e654..c74867df5bb 100644 --- a/homeassistant/components/deconz/sensor.py +++ b/homeassistant/components/deconz/sensor.py @@ -22,24 +22,16 @@ from pydeconz.sensor import ( from homeassistant.components.sensor import ( DOMAIN, - STATE_CLASS_MEASUREMENT, - STATE_CLASS_TOTAL_INCREASING, + SensorDeviceClass, SensorEntity, SensorEntityDescription, + SensorStateClass, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_TEMPERATURE, ATTR_VOLTAGE, - DEVICE_CLASS_BATTERY, - DEVICE_CLASS_ENERGY, - DEVICE_CLASS_HUMIDITY, - DEVICE_CLASS_ILLUMINANCE, - DEVICE_CLASS_POWER, - DEVICE_CLASS_PRESSURE, - DEVICE_CLASS_TEMPERATURE, ENERGY_KILO_WATT_HOUR, - ENTITY_CATEGORY_DIAGNOSTIC, LIGHT_LUX, PERCENTAGE, POWER_WATT, @@ -51,6 +43,7 @@ from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, async_dispatcher_send, ) +from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType @@ -79,15 +72,15 @@ ATTR_EVENT_ID = "event_id" ENTITY_DESCRIPTIONS = { Battery: SensorEntityDescription( key="battery", - device_class=DEVICE_CLASS_BATTERY, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.BATTERY, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=PERCENTAGE, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, + entity_category=EntityCategory.DIAGNOSTIC, ), Consumption: SensorEntityDescription( key="consumption", - device_class=DEVICE_CLASS_ENERGY, - state_class=STATE_CLASS_TOTAL_INCREASING, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, ), Daylight: SensorEntityDescription( @@ -97,31 +90,31 @@ ENTITY_DESCRIPTIONS = { ), Humidity: SensorEntityDescription( key="humidity", - device_class=DEVICE_CLASS_HUMIDITY, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.HUMIDITY, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=PERCENTAGE, ), LightLevel: SensorEntityDescription( key="lightlevel", - device_class=DEVICE_CLASS_ILLUMINANCE, + device_class=SensorDeviceClass.ILLUMINANCE, native_unit_of_measurement=LIGHT_LUX, ), Power: SensorEntityDescription( key="power", - device_class=DEVICE_CLASS_POWER, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.POWER, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=POWER_WATT, ), Pressure: SensorEntityDescription( key="pressure", - device_class=DEVICE_CLASS_PRESSURE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.PRESSURE, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=PRESSURE_HPA, ), Temperature: SensorEntityDescription( key="temperature", - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=TEMP_CELSIUS, ), }