From b49a3bbf8ae681c38daec3993af24831560000a5 Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Fri, 22 Dec 2023 15:36:05 +0100 Subject: [PATCH] fix duplicates in entity names (#482) --- CHANGELOG.md | 2 +- src/pyatmo/modules/base_class.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfca525f..36c61090 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- +- Duplicates in entity names (https://github.com/home-assistant/core/issues/88792) ### Security diff --git a/src/pyatmo/modules/base_class.py b/src/pyatmo/modules/base_class.py index 3e6dec0c..72e457e9 100644 --- a/src/pyatmo/modules/base_class.py +++ b/src/pyatmo/modules/base_class.py @@ -35,6 +35,13 @@ def default(key: str, val: Any) -> Any: return lambda x, _: x.get(key, val) +def deduplicate(data: str) -> str: + """Remove duplicates from string.""" + seen: set[str] = set() + seen_add = seen.add + return " ".join([x for x in data.split() if not (x in seen or seen_add(x))]) + + class EntityBase: """Base class for Netatmo entities.""" @@ -62,7 +69,9 @@ def update_topology(self, raw_data: RawData) -> None: and self.bridge in self.home.modules and getattr(self, "device_category") == "weather" ): - self.name = f"{self.home.modules[self.bridge].name} {self.name}" + self.name = deduplicate( + f"{self.home.modules[self.bridge].name} {self.name}", + ) def _update_attributes(self, raw_data: RawData) -> None: """Update attributes."""