From efd2817221a9fc5d30c87ab8bb2cb3e9c4c18d1c Mon Sep 17 00:00:00 2001 From: Luca Angemi Date: Sat, 28 Jan 2023 06:20:51 +0100 Subject: [PATCH] Add state class to nest legacy sensors (#86810) * Add state class to nest legacy sensors Add state class (measurement) to humidity and temperature for the nest legacy sensors. * Update Update --- homeassistant/components/nest/legacy/sensor.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/nest/legacy/sensor.py b/homeassistant/components/nest/legacy/sensor.py index 86e73114568..ce38b2dbf0d 100644 --- a/homeassistant/components/nest/legacy/sensor.py +++ b/homeassistant/components/nest/legacy/sensor.py @@ -3,7 +3,11 @@ import logging -from homeassistant.components.sensor import SensorDeviceClass, SensorEntity +from homeassistant.components.sensor import ( + SensorDeviceClass, + SensorEntity, + SensorStateClass, +) from homeassistant.const import ( CONF_MONITORED_CONDITIONS, CONF_SENSORS, @@ -48,6 +52,8 @@ SENSOR_UNITS = {"humidity": PERCENTAGE} SENSOR_DEVICE_CLASSES = {"humidity": SensorDeviceClass.HUMIDITY} +SENSOR_STATE_CLASSES = {"humidity": SensorStateClass.MEASUREMENT} + VARIABLE_NAME_MAPPING = {"eta": "eta_begin", "operation_mode": "mode"} VALUE_MAPPING = { @@ -167,6 +173,11 @@ class NestBasicSensor(NestSensorDevice, SensorEntity): """Return the device class of the sensor.""" return SENSOR_DEVICE_CLASSES.get(self.variable) + @property + def state_class(self): + """Return the state class of the sensor.""" + return SENSOR_STATE_CLASSES.get(self.variable) + def update(self): """Retrieve latest state.""" self._unit = SENSOR_UNITS.get(self.variable) @@ -202,6 +213,11 @@ class NestTempSensor(NestSensorDevice, SensorEntity): """Return the device class of the sensor.""" return SensorDeviceClass.TEMPERATURE + @property + def state_class(self): + """Return the state class of the sensor.""" + return SensorStateClass.MEASUREMENT + def update(self): """Retrieve latest state.""" if self.device.temperature_scale == "C":