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

View File

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