Use enums in sht31 ()

This commit is contained in:
Robert Hillis 2021-12-16 08:28:21 -05:00 committed by GitHub
parent b6ed3e87e0
commit 9ddf2035d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,14 +12,13 @@ import voluptuous as vol
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
PLATFORM_SCHEMA, PLATFORM_SCHEMA,
SensorDeviceClass,
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
) )
from homeassistant.const import ( from homeassistant.const import (
CONF_MONITORED_CONDITIONS, CONF_MONITORED_CONDITIONS,
CONF_NAME, CONF_NAME,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE,
PERCENTAGE, PERCENTAGE,
TEMP_CELSIUS, TEMP_CELSIUS,
) )
@ -50,14 +49,14 @@ SENSOR_TYPES = (
SHT31SensorEntityDescription( SHT31SensorEntityDescription(
key="temperature", key="temperature",
name="Temperature", name="Temperature",
device_class=DEVICE_CLASS_TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=TEMP_CELSIUS,
value_fn=lambda sensor: sensor.temperature, value_fn=lambda sensor: sensor.temperature,
), ),
SHT31SensorEntityDescription( SHT31SensorEntityDescription(
key="humidity", key="humidity",
name="Humidity", name="Humidity",
device_class=DEVICE_CLASS_HUMIDITY, device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
value_fn=lambda sensor: ( value_fn=lambda sensor: (
round(val) # pylint: disable=undefined-variable round(val) # pylint: disable=undefined-variable