From 25d33a21269a311c2aa3fda2fd97680cfce5bd25 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 15 Dec 2021 22:00:10 +0100 Subject: [PATCH] Use new enums in nest (#61942) --- .../components/nest/legacy/binary_sensor.py | 15 ++++++--------- .../components/nest/legacy/sensor.py | 8 +++----- homeassistant/components/nest/sensor_sdm.py | 19 +++++++++---------- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/nest/legacy/binary_sensor.py b/homeassistant/components/nest/legacy/binary_sensor.py index c257ddd9456..79e1bf65c86 100644 --- a/homeassistant/components/nest/legacy/binary_sensor.py +++ b/homeassistant/components/nest/legacy/binary_sensor.py @@ -3,10 +3,7 @@ from itertools import chain import logging from homeassistant.components.binary_sensor import ( - DEVICE_CLASS_CONNECTIVITY, - DEVICE_CLASS_MOTION, - DEVICE_CLASS_OCCUPANCY, - DEVICE_CLASS_SOUND, + BinarySensorDeviceClass, BinarySensorEntity, ) from homeassistant.const import CONF_BINARY_SENSORS, CONF_MONITORED_CONDITIONS @@ -16,7 +13,7 @@ from .const import DATA_NEST, DATA_NEST_CONFIG _LOGGER = logging.getLogger(__name__) -BINARY_TYPES = {"online": DEVICE_CLASS_CONNECTIVITY} +BINARY_TYPES = {"online": BinarySensorDeviceClass.CONNECTIVITY} CLIMATE_BINARY_TYPES = { "fan": None, @@ -26,9 +23,9 @@ CLIMATE_BINARY_TYPES = { } CAMERA_BINARY_TYPES = { - "motion_detected": DEVICE_CLASS_MOTION, - "sound_detected": DEVICE_CLASS_SOUND, - "person_detected": DEVICE_CLASS_OCCUPANCY, + "motion_detected": BinarySensorDeviceClass.MOTION, + "sound_detected": BinarySensorDeviceClass.SOUND, + "person_detected": BinarySensorDeviceClass.OCCUPANCY, } STRUCTURE_BINARY_TYPES = {"away": None} @@ -160,7 +157,7 @@ class NestActivityZoneSensor(NestBinarySensor): @property def device_class(self): """Return the device class of the binary sensor.""" - return DEVICE_CLASS_MOTION + return BinarySensorDeviceClass.MOTION def update(self): """Retrieve latest state.""" diff --git a/homeassistant/components/nest/legacy/sensor.py b/homeassistant/components/nest/legacy/sensor.py index 7b3ba5ec2fe..c5229177b60 100644 --- a/homeassistant/components/nest/legacy/sensor.py +++ b/homeassistant/components/nest/legacy/sensor.py @@ -1,12 +1,10 @@ """Support for Nest Thermostat sensors for the legacy API.""" import logging -from homeassistant.components.sensor import SensorEntity +from homeassistant.components.sensor import SensorDeviceClass, SensorEntity from homeassistant.const import ( CONF_MONITORED_CONDITIONS, CONF_SENSORS, - DEVICE_CLASS_HUMIDITY, - DEVICE_CLASS_TEMPERATURE, PERCENTAGE, STATE_OFF, TEMP_CELSIUS, @@ -47,7 +45,7 @@ _VALID_SENSOR_TYPES = ( SENSOR_UNITS = {"humidity": PERCENTAGE} -SENSOR_DEVICE_CLASSES = {"humidity": DEVICE_CLASS_HUMIDITY} +SENSOR_DEVICE_CLASSES = {"humidity": SensorDeviceClass.HUMIDITY} VARIABLE_NAME_MAPPING = {"eta": "eta_begin", "operation_mode": "mode"} @@ -201,7 +199,7 @@ class NestTempSensor(NestSensorDevice, SensorEntity): @property def device_class(self): """Return the device class of the sensor.""" - return DEVICE_CLASS_TEMPERATURE + return SensorDeviceClass.TEMPERATURE def update(self): """Retrieve latest state.""" diff --git a/homeassistant/components/nest/sensor_sdm.py b/homeassistant/components/nest/sensor_sdm.py index 786efde43f7..30587606b19 100644 --- a/homeassistant/components/nest/sensor_sdm.py +++ b/homeassistant/components/nest/sensor_sdm.py @@ -7,14 +7,13 @@ from google_nest_sdm.device import Device from google_nest_sdm.device_traits import HumidityTrait, TemperatureTrait from google_nest_sdm.exceptions import GoogleNestException -from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity -from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ( - DEVICE_CLASS_HUMIDITY, - DEVICE_CLASS_TEMPERATURE, - PERCENTAGE, - TEMP_CELSIUS, +from homeassistant.components.sensor import ( + SensorDeviceClass, + SensorEntity, + SensorStateClass, ) +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import PERCENTAGE, TEMP_CELSIUS from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -58,7 +57,7 @@ class SensorBase(SensorEntity): """Representation of a dynamically updated Sensor.""" _attr_shoud_poll = False - _attr_state_class = STATE_CLASS_MEASUREMENT + _attr_state_class = SensorStateClass.MEASUREMENT def __init__(self, device: Device) -> None: """Initialize the sensor.""" @@ -77,7 +76,7 @@ class SensorBase(SensorEntity): class TemperatureSensor(SensorBase): """Representation of a Temperature Sensor.""" - _attr_device_class = DEVICE_CLASS_TEMPERATURE + _attr_device_class = SensorDeviceClass.TEMPERATURE _attr_native_unit_of_measurement = TEMP_CELSIUS @property @@ -98,7 +97,7 @@ class TemperatureSensor(SensorBase): class HumiditySensor(SensorBase): """Representation of a Humidity Sensor.""" - _attr_device_class = DEVICE_CLASS_HUMIDITY + _attr_device_class = SensorDeviceClass.HUMIDITY _attr_native_unit_of_measurement = PERCENTAGE @property