From 5b75a5d195ddc6f82ddc01fa76dba09c9451ccbc Mon Sep 17 00:00:00 2001 From: Eyesoft Date: Fri, 30 Sep 2022 10:30:01 +0200 Subject: [PATCH] Added sensor unique_id Sensor became unavailable when Min Renovasjon changed the name of the fraction. --- custom_components/min_renovasjon/manifest.json | 2 +- custom_components/min_renovasjon/sensor.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/custom_components/min_renovasjon/manifest.json b/custom_components/min_renovasjon/manifest.json index 9ade43c..1a64c5d 100644 --- a/custom_components/min_renovasjon/manifest.json +++ b/custom_components/min_renovasjon/manifest.json @@ -10,6 +10,6 @@ "ssdp": [], "zeroconf": [], "homekit": {}, - "version": "0.0.5", + "version": "2.1.0", "iot_class": "cloud_polling" } diff --git a/custom_components/min_renovasjon/sensor.py b/custom_components/min_renovasjon/sensor.py index e05ec2c..72c952e 100644 --- a/custom_components/min_renovasjon/sensor.py +++ b/custom_components/min_renovasjon/sensor.py @@ -49,7 +49,6 @@ def __init__(self, min_renovasjon, fraction_id, calendar_list): self._fraction_id = int(fraction_id) self._available = True self._attributes = {} - self._attr_unique_id = self.get_name() @property def should_poll(self): @@ -79,15 +78,17 @@ def extra_state_attributes(self): @property def name(self): """Return the name.""" - return self.get_name() - - def get_name(self): if self._calendar_list is not None: for fraction in self._calendar_list: if int(fraction[0]) == self._fraction_id: return fraction[1] return None + @property + def unique_id(self) -> str: + """Return unique ID.""" + return "{0}_{1}".format(DOMAIN, self._fraction_id) + @property def state(self): """Return the state/date of the fraction."""