From 87577eae6bf1cba96c41416faa68d02ca5eb5c7a Mon Sep 17 00:00:00 2001 From: Remus Lazar Date: Sat, 17 Dec 2022 13:13:27 +0100 Subject: [PATCH] Derive the unique_id from the sensor name This leads to more "stable" unique_ids, not losing the history data after changing the friendly_name property in the configuration. --- custom_components/luxtronik/binary_sensor.py | 2 +- custom_components/luxtronik/sensor.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/luxtronik/binary_sensor.py b/custom_components/luxtronik/binary_sensor.py index b983724..30396c0 100644 --- a/custom_components/luxtronik/binary_sensor.py +++ b/custom_components/luxtronik/binary_sensor.py @@ -87,7 +87,7 @@ def __init__(self, luxtronik, sensor, friendly_name, icon, invert_state): self._icon = icon self._invert = invert_state self._attr_unique_id = ENTITY_ID_FORMAT.format( - slugify(self._sensor.name if not self._name else self._name) + slugify(self._sensor.name) ) @property diff --git a/custom_components/luxtronik/sensor.py b/custom_components/luxtronik/sensor.py index c377367..a47ccdc 100644 --- a/custom_components/luxtronik/sensor.py +++ b/custom_components/luxtronik/sensor.py @@ -92,7 +92,7 @@ def __init__(self, luxtronik, sensor, friendly_name, icon, state_class): self._icon = icon self._state_class = state_class self._attr_unique_id = ENTITY_ID_FORMAT.format( - slugify(self._sensor.name if not self._name else self._name) + slugify(self._sensor.name) ) @property