Skip to content

Commit

Permalink
Break out check_reg_mode(), lowers complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
bouwew committed Oct 17, 2023
1 parent 31248e8 commit 26c3537
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions plugwise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ def _device_data_adam(

return device_data

def check_reg_mode(self, mode: str) -> bool:
"""Helper-function for device_data_climate()."""
gateway = self.gw_devices[self.gateway_id]
return (
"regulation_modes" in gateway and gateway["select_regulation_mode"] == mode
)

def _device_data_climate(
self, device: DeviceData, device_data: DeviceData
) -> DeviceData:
Expand Down Expand Up @@ -228,20 +235,16 @@ def _device_data_climate(
self._count += 3

# Operation modes: auto, heat, heat_cool, cool and off
gateway = self.gw_devices[self.gateway_id]
device_data["mode"] = "auto"
self._count += 1
if sel_schedule == "None":
device_data["mode"] = "heat"
if self._cooling_present:
device_data["mode"] = "heat_cool"
if (
"regulation_modes" in gateway
and gateway["select_regulation_mode"] == "cooling"
):
device_data["mode"] = "cool"

if "regulation_modes" in gateway and gateway["select_regulation_mode"] == "off":
device_data["mode"] = (
"cool" if self.check_reg_mode("cooling") else "heat_cool"
)

if self.check_reg_mode("off"):
device_data["mode"] = "off"

if "None" not in avail_schedules:
Expand Down

0 comments on commit 26c3537

Please sign in to comment.