Use enums in xiaomi_aqara (#61981)

This commit is contained in:
Robert Hillis 2021-12-16 03:05:13 -05:00 committed by GitHub
parent a41810efcf
commit 98c2c8c2d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 18 deletions

View File

@ -2,8 +2,7 @@
import logging
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_MOISTURE,
DEVICE_CLASS_OPENING,
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.core import callback
@ -303,7 +302,7 @@ class XiaomiDoorSensor(XiaomiBinarySensor):
"Door Window Sensor",
xiaomi_hub,
data_key,
DEVICE_CLASS_OPENING,
BinarySensorDeviceClass.OPENING,
config_entry,
)
@ -353,7 +352,7 @@ class XiaomiWaterLeakSensor(XiaomiBinarySensor):
"Water Leak Sensor",
xiaomi_hub,
data_key,
DEVICE_CLASS_MOISTURE,
BinarySensorDeviceClass.MOISTURE,
config_entry,
)

View File

@ -3,15 +3,13 @@ from __future__ import annotations
import logging
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
)
from homeassistant.const import (
ATTR_BATTERY_LEVEL,
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_POWER,
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE,
LIGHT_LUX,
PERCENTAGE,
POWER_WATT,
@ -28,27 +26,27 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
"temperature": SensorEntityDescription(
key="temperature",
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
),
"humidity": SensorEntityDescription(
key="humidity",
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_HUMIDITY,
device_class=SensorDeviceClass.HUMIDITY,
),
"illumination": SensorEntityDescription(
key="illumination",
native_unit_of_measurement="lm",
device_class=DEVICE_CLASS_ILLUMINANCE,
device_class=SensorDeviceClass.ILLUMINANCE,
),
"lux": SensorEntityDescription(
key="lux",
native_unit_of_measurement=LIGHT_LUX,
device_class=DEVICE_CLASS_ILLUMINANCE,
device_class=SensorDeviceClass.ILLUMINANCE,
),
"pressure": SensorEntityDescription(
key="pressure",
native_unit_of_measurement=PRESSURE_HPA,
device_class=DEVICE_CLASS_PRESSURE,
device_class=SensorDeviceClass.PRESSURE,
),
"bed_activity": SensorEntityDescription(
key="bed_activity",
@ -58,7 +56,7 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
"load_power": SensorEntityDescription(
key="load_power",
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
device_class=SensorDeviceClass.POWER,
),
"final_tilt_angle": SensorEntityDescription(
key="final_tilt_angle",
@ -185,7 +183,7 @@ class XiaomiBatterySensor(XiaomiDevice, SensorEntity):
"""Representation of a XiaomiSensor."""
_attr_native_unit_of_measurement = PERCENTAGE
_attr_device_class = DEVICE_CLASS_BATTERY
_attr_device_class = SensorDeviceClass.BATTERY
def parse_data(self, data, raw_data):
"""Parse data sent by gateway."""