Skip to content

Commit 76f3a58

Browse files
committed
Implement suggested improvements
1 parent 5bcc778 commit 76f3a58

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

plugwise/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
MODULE_LOCATOR: Final = "./logs/point_log/*[@id]"
8686
NONE: Final = "None"
8787
OFF: Final = "off"
88-
PRIORITY_DEVICE_CLASSES = ("heater_central", "gateway")
88+
PRIORITY_DEVICE_CLASSES = ("gateway", "heater_central")
8989

9090
# XML data paths
9191
APPLIANCES: Final = "/core/appliances"

plugwise/helper.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,14 @@ def _get_p1_smartmeter_info(self) -> None:
382382

383383
def _sort_gw_entities(self) -> None:
384384
"""Place the gateway and optional heater_central entities as 1st and 2nd."""
385-
for dev_class in PRIORITY_DEVICE_CLASSES:
386-
for entity_id, entity in dict(self.gw_entities).items():
387-
if entity["dev_class"] == dev_class:
388-
priority_entity = entity
389-
self.gw_entities.pop(entity_id)
390-
other_entities = self.gw_entities
391-
priority_entities = {entity_id: priority_entity}
392-
self.gw_entities = {**priority_entities, **other_entities}
385+
def sort_key(item):
386+
entity_id, entity = item
387+
try:
388+
return PRIORITY_DEVICE_CLASSES.index(entity["dev_class"])
389+
except ValueError:
390+
return len(PRIORITY_DEVICE_CLASSES)
391+
392+
self.gw_entities = dict(sorted(self.gw_entities.items(), key=sort_key))
393393

394394
def _all_locations(self) -> None:
395395
"""Collect all locations."""
@@ -813,13 +813,10 @@ def _process_on_off_device_c_heating_state(self, data: GwEntityData) -> None:
813813
if self.smile(ADAM):
814814
# First count when not present, then create and init to False.
815815
# When present init to False
816-
if "heating_state" not in data["binary_sensors"]:
817-
self._count += 1
818-
data["binary_sensors"]["heating_state"] = False
819-
820-
if "cooling_state" not in data["binary_sensors"]:
821-
self._count += 1
822-
data["binary_sensors"]["cooling_state"] = False
816+
for state in ["heating_state", "cooling_state"]:
817+
if state not in data["binary_sensors"]:
818+
self._count += 1
819+
data["binary_sensors"][state] = False
823820

824821
if self._cooling_enabled:
825822
data["binary_sensors"]["cooling_state"] = data["c_heating_state"]

0 commit comments

Comments
 (0)