Use enums in wiffi (#61984)

This commit is contained in:
Robert Hillis 2021-12-16 03:01:20 -05:00 committed by GitHub
parent e1f5b63f1e
commit 9084a227fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,9 @@
"""Sensor platform support for wiffi devices."""
from homeassistant.components.sensor import (
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorDeviceClass,
SensorEntity,
SensorStateClass,
)
from homeassistant.const import DEGREE, PRESSURE_MBAR, TEMP_CELSIUS
from homeassistant.core import callback
@ -25,10 +21,10 @@ from .wiffi_strings import (
# map to determine HA device class from wiffi's unit of measurement
UOM_TO_DEVICE_CLASS_MAP = {
WIFFI_UOM_TEMP_CELSIUS: DEVICE_CLASS_TEMPERATURE,
WIFFI_UOM_PERCENT: DEVICE_CLASS_HUMIDITY,
WIFFI_UOM_MILLI_BAR: DEVICE_CLASS_PRESSURE,
WIFFI_UOM_LUX: DEVICE_CLASS_ILLUMINANCE,
WIFFI_UOM_TEMP_CELSIUS: SensorDeviceClass.TEMPERATURE,
WIFFI_UOM_PERCENT: SensorDeviceClass.HUMIDITY,
WIFFI_UOM_MILLI_BAR: SensorDeviceClass.PRESSURE,
WIFFI_UOM_LUX: SensorDeviceClass.ILLUMINANCE,
}
# map to convert wiffi unit of measurements to common HA uom's
@ -74,9 +70,9 @@ class NumberEntity(WiffiEntity, SensorEntity):
self._value = metric.value
if self._is_measurement_entity():
self._attr_state_class = STATE_CLASS_MEASUREMENT
self._attr_state_class = SensorStateClass.MEASUREMENT
elif self._is_metered_entity():
self._attr_state_class = STATE_CLASS_TOTAL_INCREASING
self._attr_state_class = SensorStateClass.TOTAL_INCREASING
self.reset_expiration_date()