Skip to content

Commit

Permalink
fix: update name prefixing (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgtobi authored Dec 26, 2023
1 parent bce27db commit d79e71c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/pyatmo/modules/base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ def default(key: str, val: Any) -> Any:
return lambda x, _: x.get(key, val)


def deduplicate(data: str) -> str:
def update_name(name: str, pre_fix: 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))])

if name.startswith(pre_fix):
return name
return f"{pre_fix} {name}"


class EntityBase:
Expand Down Expand Up @@ -69,9 +70,7 @@ def update_topology(self, raw_data: RawData) -> None:
and self.bridge in self.home.modules
and getattr(self, "device_category") == "weather"
):
self.name = deduplicate(
f"{self.home.modules[self.bridge].name} {self.name}",
)
self.name = update_name(self.name, self.home.modules[self.bridge].name)

def _update_attributes(self, raw_data: RawData) -> None:
"""Update attributes."""
Expand Down

0 comments on commit d79e71c

Please sign in to comment.