Skip to content

Commit 447aefe

Browse files
committed
Reduce complexity
1 parent a965eb1 commit 447aefe

File tree

1 file changed

+51
-41
lines changed

1 file changed

+51
-41
lines changed

plugwise/helper.py

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -538,54 +538,15 @@ def _get_measurement_data(self, dev_id: str) -> DeviceZoneData:
538538
self._get_regulation_mode(appliance, data)
539539
self._get_gateway_mode(appliance, data)
540540

541-
# Adam & Anna: the Smile outdoor_temperature is present in DOMAIN_OBJECTS and LOCATIONS - under Home
542-
# The outdoor_temperature present in APPLIANCES is a local sensor connected to the active device
543-
if self._is_thermostat and dev_id == self.gateway_id:
544-
outdoor_temperature = self._object_value(
545-
self._home_location, "outdoor_temperature"
546-
)
547-
if outdoor_temperature is not None:
548-
data.update({"sensors": {"outdoor_temperature": outdoor_temperature}})
549-
self._count += 1
541+
self._get_gateway_outdoor_temp(dev_id, data)
550542

551543
if "c_heating_state" in data:
552544
self._process_c_heating_state(data)
553545
# Remove c_heating_state after processing
554546
data.pop("c_heating_state")
555547
self._count -= 1
556548

557-
if self._is_thermostat and self.smile(ANNA) and dev_id == self._heater_id:
558-
# Anna+Elga: base cooling_state on the elga-status-code
559-
if "elga_status_code" in data:
560-
if data["thermostat_supports_cooling"]:
561-
# Techneco Elga has cooling-capability
562-
self._cooling_present = True
563-
data["model"] = "Generic heater/cooler"
564-
self._cooling_enabled = data["elga_status_code"] in (8, 9)
565-
data["binary_sensors"]["cooling_state"] = self._cooling_active = (
566-
data["elga_status_code"] == 8
567-
)
568-
# Elga has no cooling-switch
569-
if "cooling_ena_switch" in data["switches"]:
570-
data["switches"].pop("cooling_ena_switch")
571-
self._count -= 1
572-
573-
data.pop("elga_status_code", None)
574-
self._count -= 1
575-
576-
# Loria/Thermastage: cooling-related is based on cooling_state
577-
# and modulation_level
578-
elif self._cooling_present and "cooling_state" in data["binary_sensors"]:
579-
self._cooling_enabled = data["binary_sensors"]["cooling_state"]
580-
self._cooling_active = data["sensors"]["modulation_level"] == 100
581-
# For Loria the above does not work (pw-beta issue #301)
582-
if "cooling_ena_switch" in data["switches"]:
583-
self._cooling_enabled = data["switches"]["cooling_ena_switch"]
584-
self._cooling_active = data["binary_sensors"]["cooling_state"]
585-
586-
self._cleanup_data(data)
587-
588-
return data
549+
self._update_anna_cooling(dev_id, data)
589550

590551
def _power_data_from_location(self, loc_id: str) -> DeviceZoneData:
591552
"""Helper-function for smile.py: _get_device_zone_data().
@@ -752,6 +713,19 @@ def _get_gateway_mode(self, appliance: etree, data: DeviceZoneData) -> None:
752713
data["select_gateway_mode"] = search.find("mode").text
753714
self._count += 1
754715

716+
def _get_gateway_outdoor_temp(self, dev_id: str, data: DeviceZoneData) -> None:
717+
"""Adam & Anna: the Smile outdoor_temperature is present in DOMAIN_OBJECTS and LOCATIONS.
718+
719+
Available under the Home location.
720+
"""
721+
if self._is_thermostat and dev_id == self.gateway_id:
722+
outdoor_temperature = self._object_value(
723+
self._home_location, "outdoor_temperature"
724+
)
725+
if outdoor_temperature is not None:
726+
data.update({"sensors": {"outdoor_temperature": outdoor_temperature}})
727+
self._count += 1
728+
755729
def _object_value(self, obj_id: str, measurement: str) -> float | int | None:
756730
"""Helper-function for smile.py: _get_device_zone_data() and _device_data_anna().
757731
@@ -793,6 +767,42 @@ def _process_c_heating_state(self, data: DeviceZoneData) -> None:
793767
if self._elga:
794768
data["binary_sensors"]["heating_state"] = data["c_heating_state"]
795769

770+
def _update_anna_cooling(self, dev_id: str, data: DeviceZoneData) -> None:
771+
"""Update the Anna heater_central device for cooling.
772+
773+
Support added for Techneco Elga and Thercon Loria/Thermastage.
774+
"""
775+
if self._is_thermostat and self.smile(ANNA) and dev_id == self._heater_id:
776+
# Anna+Elga: base cooling_state on the elga-status-code
777+
if "elga_status_code" in data:
778+
if data["thermostat_supports_cooling"]:
779+
# Techneco Elga has cooling-capability
780+
self._cooling_present = True
781+
data["model"] = "Generic heater/cooler"
782+
self._cooling_enabled = data["elga_status_code"] in (8, 9)
783+
data["binary_sensors"]["cooling_state"] = self._cooling_active = (
784+
data["elga_status_code"] == 8
785+
)
786+
# Elga has no cooling-switch
787+
if "cooling_ena_switch" in data["switches"]:
788+
data["switches"].pop("cooling_ena_switch")
789+
self._count -= 1
790+
791+
data.pop("elga_status_code", None)
792+
self._count -= 1
793+
794+
# Loria/Thermastage: cooling-related is based on cooling_state
795+
# and modulation_level
796+
elif self._cooling_present and "cooling_state" in data["binary_sensors"]:
797+
self._cooling_enabled = data["binary_sensors"]["cooling_state"]
798+
self._cooling_active = data["sensors"]["modulation_level"] == 100
799+
# For Loria the above does not work (pw-beta issue #301)
800+
if "cooling_ena_switch" in data["switches"]:
801+
self._cooling_enabled = data["switches"]["cooling_ena_switch"]
802+
self._cooling_active = data["binary_sensors"]["cooling_state"]
803+
804+
self._cleanup_data(data)
805+
796806
def _cleanup_data(self, data: DeviceZoneData) -> None:
797807
"""Helper-function for _get_measurement_data().
798808

0 commit comments

Comments
 (0)