Use new enums in deconz (#61343)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-09 13:23:01 +01:00 committed by GitHub
parent 2e99fbc1f3
commit fa38a2d0bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 47 deletions

View file

@ -17,21 +17,16 @@ from pydeconz.sensor import (
) )
from homeassistant.components.binary_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, DOMAIN,
BinarySensorDeviceClass,
BinarySensorEntity, BinarySensorEntity,
BinarySensorEntityDescription, BinarySensorEntityDescription,
) )
from homeassistant.config_entries import ConfigEntry 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.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import ATTR_DARK, ATTR_ON from .const import ATTR_DARK, ATTR_ON
@ -56,27 +51,27 @@ ATTR_VIBRATIONSTRENGTH = "vibrationstrength"
ENTITY_DESCRIPTIONS = { ENTITY_DESCRIPTIONS = {
CarbonMonoxide: BinarySensorEntityDescription( CarbonMonoxide: BinarySensorEntityDescription(
key="carbonmonoxide", key="carbonmonoxide",
device_class=DEVICE_CLASS_GAS, device_class=BinarySensorDeviceClass.GAS,
), ),
Fire: BinarySensorEntityDescription( Fire: BinarySensorEntityDescription(
key="fire", key="fire",
device_class=DEVICE_CLASS_SMOKE, device_class=BinarySensorDeviceClass.SMOKE,
), ),
OpenClose: BinarySensorEntityDescription( OpenClose: BinarySensorEntityDescription(
key="openclose", key="openclose",
device_class=DEVICE_CLASS_OPENING, device_class=BinarySensorDeviceClass.OPENING,
), ),
Presence: BinarySensorEntityDescription( Presence: BinarySensorEntityDescription(
key="presence", key="presence",
device_class=DEVICE_CLASS_MOTION, device_class=BinarySensorDeviceClass.MOTION,
), ),
Vibration: BinarySensorEntityDescription( Vibration: BinarySensorEntityDescription(
key="vibration", key="vibration",
device_class=DEVICE_CLASS_VIBRATION, device_class=BinarySensorDeviceClass.VIBRATION,
), ),
Water: BinarySensorEntityDescription( Water: BinarySensorEntityDescription(
key="water", key="water",
device_class=DEVICE_CLASS_MOISTURE, device_class=BinarySensorDeviceClass.MOISTURE,
), ),
} }
@ -186,8 +181,8 @@ class DeconzTampering(DeconzDevice, BinarySensorEntity):
TYPE = DOMAIN TYPE = DOMAIN
_device: PydeconzSensor _device: PydeconzSensor
_attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC _attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_device_class = DEVICE_CLASS_TAMPER _attr_device_class = BinarySensorDeviceClass.TAMPER
def __init__(self, device: PydeconzSensor, gateway: DeconzGateway) -> None: def __init__(self, device: PydeconzSensor, gateway: DeconzGateway) -> None:
"""Initialize deCONZ binary sensor.""" """Initialize deCONZ binary sensor."""

View file

@ -10,8 +10,6 @@ from pydeconz.light import Cover
from homeassistant.components.cover import ( from homeassistant.components.cover import (
ATTR_POSITION, ATTR_POSITION,
ATTR_TILT_POSITION, ATTR_TILT_POSITION,
DEVICE_CLASS_DAMPER,
DEVICE_CLASS_SHADE,
DOMAIN, DOMAIN,
SUPPORT_CLOSE, SUPPORT_CLOSE,
SUPPORT_CLOSE_TILT, SUPPORT_CLOSE_TILT,
@ -21,6 +19,7 @@ from homeassistant.components.cover import (
SUPPORT_SET_TILT_POSITION, SUPPORT_SET_TILT_POSITION,
SUPPORT_STOP, SUPPORT_STOP,
SUPPORT_STOP_TILT, SUPPORT_STOP_TILT,
CoverDeviceClass,
CoverEntity, CoverEntity,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -32,9 +31,9 @@ from .deconz_device import DeconzDevice
from .gateway import DeconzGateway, get_gateway_from_config_entry from .gateway import DeconzGateway, get_gateway_from_config_entry
DEVICE_CLASS = { DEVICE_CLASS = {
"Level controllable output": DEVICE_CLASS_DAMPER, "Level controllable output": CoverDeviceClass.DAMPER,
"Window covering controller": DEVICE_CLASS_SHADE, "Window covering controller": CoverDeviceClass.SHADE,
"Window covering device": DEVICE_CLASS_SHADE, "Window covering device": CoverDeviceClass.SHADE,
} }

View file

@ -13,9 +13,9 @@ from homeassistant.components.number import (
NumberEntityDescription, NumberEntityDescription,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENTITY_CATEGORY_CONFIG
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .deconz_device import DeconzDevice from .deconz_device import DeconzDevice
@ -37,7 +37,7 @@ class DeconzNumberEntityDescription(
): ):
"""Class describing deCONZ number entities.""" """Class describing deCONZ number entities."""
entity_category = ENTITY_CATEGORY_CONFIG entity_category = EntityCategory.CONFIG
ENTITY_DESCRIPTIONS = { ENTITY_DESCRIPTIONS = {

View file

@ -22,24 +22,16 @@ from pydeconz.sensor import (
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
DOMAIN, DOMAIN,
STATE_CLASS_MEASUREMENT, SensorDeviceClass,
STATE_CLASS_TOTAL_INCREASING,
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ATTR_TEMPERATURE, ATTR_TEMPERATURE,
ATTR_VOLTAGE, 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, ENERGY_KILO_WATT_HOUR,
ENTITY_CATEGORY_DIAGNOSTIC,
LIGHT_LUX, LIGHT_LUX,
PERCENTAGE, PERCENTAGE,
POWER_WATT, POWER_WATT,
@ -51,6 +43,7 @@ from homeassistant.helpers.dispatcher import (
async_dispatcher_connect, async_dispatcher_connect,
async_dispatcher_send, async_dispatcher_send,
) )
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType from homeassistant.helpers.typing import StateType
@ -79,15 +72,15 @@ ATTR_EVENT_ID = "event_id"
ENTITY_DESCRIPTIONS = { ENTITY_DESCRIPTIONS = {
Battery: SensorEntityDescription( Battery: SensorEntityDescription(
key="battery", key="battery",
device_class=DEVICE_CLASS_BATTERY, device_class=SensorDeviceClass.BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
Consumption: SensorEntityDescription( Consumption: SensorEntityDescription(
key="consumption", key="consumption",
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
), ),
Daylight: SensorEntityDescription( Daylight: SensorEntityDescription(
@ -97,31 +90,31 @@ ENTITY_DESCRIPTIONS = {
), ),
Humidity: SensorEntityDescription( Humidity: SensorEntityDescription(
key="humidity", key="humidity",
device_class=DEVICE_CLASS_HUMIDITY, device_class=SensorDeviceClass.HUMIDITY,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
), ),
LightLevel: SensorEntityDescription( LightLevel: SensorEntityDescription(
key="lightlevel", key="lightlevel",
device_class=DEVICE_CLASS_ILLUMINANCE, device_class=SensorDeviceClass.ILLUMINANCE,
native_unit_of_measurement=LIGHT_LUX, native_unit_of_measurement=LIGHT_LUX,
), ),
Power: SensorEntityDescription( Power: SensorEntityDescription(
key="power", key="power",
device_class=DEVICE_CLASS_POWER, device_class=SensorDeviceClass.POWER,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=POWER_WATT,
), ),
Pressure: SensorEntityDescription( Pressure: SensorEntityDescription(
key="pressure", key="pressure",
device_class=DEVICE_CLASS_PRESSURE, device_class=SensorDeviceClass.PRESSURE,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PRESSURE_HPA, native_unit_of_measurement=PRESSURE_HPA,
), ),
Temperature: SensorEntityDescription( Temperature: SensorEntityDescription(
key="temperature", key="temperature",
device_class=DEVICE_CLASS_TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=TEMP_CELSIUS,
), ),
} }