Skip to content

Commit

Permalink
fix duplicates in entity names (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgtobi authored Dec 22, 2023
1 parent 70ea042 commit b49a3bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion src/pyatmo/modules/base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit b49a3bb

Please sign in to comment.