From c43bdbf7c889acb472f364943e18066401b6aa43 Mon Sep 17 00:00:00 2001 From: Colin Robbins Date: Sun, 6 Jun 2021 19:10:16 +0100 Subject: [PATCH] Add lightwave state_class and unique_id properties (#51544) * Add state_class and unique_id properties * Update homeassistant/components/lightwave/sensor.py Co-authored-by: Martin Hjelmare * fix isort * set class via attribute Co-authored-by: Martin Hjelmare --- homeassistant/components/lightwave/climate.py | 1 + homeassistant/components/lightwave/sensor.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/lightwave/climate.py b/homeassistant/components/lightwave/climate.py index 0518e91dda9..44b1e29ff34 100644 --- a/homeassistant/components/lightwave/climate.py +++ b/homeassistant/components/lightwave/climate.py @@ -42,6 +42,7 @@ class LightwaveTrv(ClimateEntity): self._hvac_action = None self._lwlink = lwlink self._serial = serial + self._attr_unique_id = f"{serial}-trv" # inhibit is used to prevent race condition on update. If non zero, skip next update cycle. self._inhibit = 0 diff --git a/homeassistant/components/lightwave/sensor.py b/homeassistant/components/lightwave/sensor.py index f1b6412ab6a..b298b78c7f6 100644 --- a/homeassistant/components/lightwave/sensor.py +++ b/homeassistant/components/lightwave/sensor.py @@ -1,5 +1,5 @@ """Support for LightwaveRF TRV - Associated Battery.""" -from homeassistant.components.sensor import SensorEntity +from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity from homeassistant.const import CONF_NAME, DEVICE_CLASS_BATTERY, PERCENTAGE from . import CONF_SERIAL, LIGHTWAVE_LINK @@ -27,6 +27,7 @@ class LightwaveBattery(SensorEntity): _attr_device_class = DEVICE_CLASS_BATTERY _attr_unit_of_measurement = PERCENTAGE + _attr_state_class = STATE_CLASS_MEASUREMENT def __init__(self, name, lwlink, serial): """Initialize the Lightwave Trv battery sensor.""" @@ -34,6 +35,7 @@ class LightwaveBattery(SensorEntity): self._state = None self._lwlink = lwlink self._serial = serial + self._attr_unique_id = f"{serial}-trv-battery" @property def name(self):