Skip to content

Commit 86eaf12

Browse files
committed
Optimize further
1 parent d0cb08c commit 86eaf12

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

plugwise/helper.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -696,22 +696,30 @@ def _get_actuator_functionalities(
696696
act_item = cast(ActuatorType, item)
697697
data[act_item] = temp_dict
698698

699+
def _get_actuator_mode(self, appliance: etree, entity_id: str, key: str) -> str | None:
700+
"""Helper-function for _get_regulation_mode and _get_gateway_mode.
701+
702+
Collect the requested gateway mode.
703+
"""
704+
if not (self.smile(ADAM) and entity_id == self.gateway_id):
705+
return None
706+
707+
if (search := search_actuator_functionalities(appliance, key)) is not None:
708+
return str(search.find("mode").text)
709+
710+
return None
711+
699712
def _get_regulation_mode(
700713
self, appliance: etree, entity_id: str, data: GwEntityData
701714
) -> None:
702715
"""Helper-function for _get_measurement_data().
703716
704717
Adam: collect the gateway regulation_mode.
705718
"""
706-
if not (self.smile(ADAM) and entity_id == self.gateway_id):
707-
return
708-
709-
if (search := search_actuator_functionalities(
710-
appliance, "regulation_mode_control_functionality"
711-
)) is not None:
712-
data["select_regulation_mode"] = search.find("mode").text
719+
if (mode := self._get_actuator_mode(appliance, entity_id, "regulation_mode_control_functionality")) is not None:
720+
data["select_regulation_mode"] = mode
713721
self._count += 1
714-
self._cooling_enabled = data["select_regulation_mode"] == "cooling"
722+
self._cooling_enabled = mode == "cooling"
715723

716724
def _get_gateway_mode(
717725
self, appliance: etree, entity_id: str, data: GwEntityData
@@ -720,13 +728,8 @@ def _get_gateway_mode(
720728
721729
Adam: collect the gateway mode.
722730
"""
723-
if not (self.smile(ADAM) and entity_id == self.gateway_id):
724-
return
725-
726-
if (search := search_actuator_functionalities(
727-
appliance, "gateway_mode_control_functionality"
728-
)) is not None:
729-
data["select_gateway_mode"] = search.find("mode").text
731+
if (mode := self._get_actuator_mode(appliance, entity_id, "gateway_mode_control_functionality")) is not None:
732+
data["select_gateway_mode"] = mode
730733
self._count += 1
731734

732735
def _get_gateway_outdoor_temp(self, entity_id: str, data: GwEntityData) -> None:

0 commit comments

Comments
 (0)