diff --git a/CHANGELOG.md b/CHANGELOG.md index 87ebf800a..fad6e4e9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## Ongoing -- Improve readability of xml-data in POST/PUT requests +- Improve readability of xml-data in POST/PUT requests via [#707](https://github.com/plugwise/python-plugwise/pull/707) and [#708](https://github.com/plugwise/python-plugwise/pull/708) +- Continuous improvements [#711](https://github.com/plugwise/python-plugwise/pull/711) ## v1.7.2 diff --git a/plugwise/__init__.py b/plugwise/__init__.py index d2160663f..c12925eca 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -298,11 +298,12 @@ async def _smile_detect_legacy( self.smile_version = parse(system.find("./gateway/firmware").text) return_model = str(system.find("./gateway/product").text) self.smile_hostname = system.find("./gateway/hostname").text - # If wlan0 contains data it's active, so eth0 should be checked last + # If wlan0 contains data it's active, eth0 should be checked last as is preferred for network in ("wlan0", "eth0"): locator = f"./{network}/mac" if (net_locator := system.find(locator)) is not None: self.smile_mac_address = net_locator.text + # P1 legacy: elif dsmrmain is not None: status = await self._request(STATUS) diff --git a/plugwise/data.py b/plugwise/data.py index e89720740..b23b4e53a 100644 --- a/plugwise/data.py +++ b/plugwise/data.py @@ -228,6 +228,7 @@ def _check_availability( for msg in item.values(): if message in msg: data["available"] = False + break def _get_adam_data(self, entity: GwEntityData, data: GwEntityData) -> None: """Helper-function for _get_entity_data(). @@ -329,16 +330,14 @@ def _get_schedule_states_with_off( Also, replace NONE by OFF when none of the schedules are active. """ - loc_schedule_states: dict[str, str] = {} - for schedule in schedules: - loc_schedule_states[schedule] = "off" - if schedule == selected and data["climate_mode"] == "auto": - loc_schedule_states[schedule] = "on" - self._schedule_old_states[location] = loc_schedule_states - all_off = True - for state in self._schedule_old_states[location].values(): - if state == "on": + self._schedule_old_states[location] = {} + for schedule in schedules: + active: bool = schedule == selected and data["climate_mode"] == "auto" + self._schedule_old_states[location][schedule] = "off" + if active: + self._schedule_old_states[location][schedule] = "on" all_off = False + if all_off: data["select_schedule"] = OFF diff --git a/plugwise/helper.py b/plugwise/helper.py index d738f70a3..c053cdcdf 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -195,6 +195,7 @@ def _sort_gw_entities(self) -> None: other_entities = self.gw_entities priority_entities = {entity_id: priority_entity} self.gw_entities = {**priority_entities, **other_entities} + break def _all_locations(self) -> None: """Collect all locations.""" diff --git a/plugwise/legacy/helper.py b/plugwise/legacy/helper.py index 9cf703c5b..61dbe22ef 100644 --- a/plugwise/legacy/helper.py +++ b/plugwise/legacy/helper.py @@ -23,6 +23,7 @@ NONE, OFF, P1_LEGACY_MEASUREMENTS, + PRIORITY_DEVICE_CLASSES, TEMP_CELSIUS, THERMOSTAT_CLASSES, UOM, @@ -130,7 +131,7 @@ def _all_appliances(self) -> None: self._create_gw_entities(appl) # Place the gateway and optional heater_central devices as 1st and 2nd - for dev_class in ("heater_central", "gateway"): + for dev_class in PRIORITY_DEVICE_CLASSES: for entity_id, entity in dict(self.gw_entities).items(): if entity["dev_class"] == dev_class: tmp_entity = entity @@ -138,6 +139,7 @@ def _all_appliances(self) -> None: cleared_dict = self.gw_entities add_to_front = {entity_id: tmp_entity} self.gw_entities = {**add_to_front, **cleared_dict} + break def _all_locations(self) -> None: """Collect all locations.""" diff --git a/plugwise/legacy/smile.py b/plugwise/legacy/smile.py index 7cd22032c..2d1e42eef 100644 --- a/plugwise/legacy/smile.py +++ b/plugwise/legacy/smile.py @@ -204,6 +204,7 @@ async def set_schedule_state( for rule in self._domain_objects.findall("rule"): if rule.find("name").text == name: schedule_rule_id = rule.attrib["id"] + break if schedule_rule_id is None: raise PlugwiseError( @@ -215,8 +216,7 @@ async def set_schedule_state( new_state = "true" locator = f'.//*[@id="{schedule_rule_id}"]/template' - for rule in self._domain_objects.findall(locator): - template_id = rule.attrib["id"] + template_id = self._domain_objects.find(locator).attrib["id"] data = ( "" diff --git a/plugwise/smile.py b/plugwise/smile.py index aec1a6fa8..40df7d333 100644 --- a/plugwise/smile.py +++ b/plugwise/smile.py @@ -399,14 +399,15 @@ async def set_switch_state( return await self._set_groupswitch_member_state(members, state, switch) locator = f'appliance[@id="{appl_id}"]/{switch.actuator}/{switch.func_type}' - found: list[etree] = self._domain_objects.findall(locator) + found = self._domain_objects.findall(locator) for item in found: + # multiple types of e.g. toggle_functionality present if (sw_type := item.find("type")) is not None: if sw_type.text == switch.act_type: switch_id = item.attrib["id"] - else: + break + else: # actuators with a single item like relay_functionality switch_id = item.attrib["id"] - break data = ( f"<{switch.func_type}>"