Skip to content

Commit 3cd2671

Browse files
committed
Break out check_reg_mode(), lowers complexity
1 parent 5ca9a2c commit 3cd2671

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

plugwise/__init__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ def _device_data_adam(
196196

197197
return device_data
198198

199+
def check_reg_mode(self, mode: str) -> bool:
200+
"""Helper-function for device_data_climate()."""
201+
gateway = self.gw_devices[self.gateway_id]
202+
return (
203+
"regulation_modes" in gateway and gateway["select_regulation_mode"] == mode
204+
)
205+
199206
def _device_data_climate(
200207
self, device: DeviceData, device_data: DeviceData
201208
) -> DeviceData:
@@ -220,20 +227,16 @@ def _device_data_climate(
220227
self._count += 2
221228

222229
# Operation modes: auto, heat, heat_cool, cool and off
223-
gateway = self.gw_devices[self.gateway_id]
224230
device_data["mode"] = "auto"
225231
self._count += 1
226232
if sel_schedule == "None":
227233
device_data["mode"] = "heat"
228234
if self._cooling_present:
229-
device_data["mode"] = "heat_cool"
230-
if (
231-
"regulation_modes" in gateway
232-
and gateway["select_regulation_mode"] == "cooling"
233-
):
234-
device_data["mode"] = "cool"
235-
236-
if "regulation_modes" in gateway and gateway["select_regulation_mode"] == "off":
235+
device_data["mode"] = (
236+
"cool" if self.check_reg_mode("cooling") else "heat_cool"
237+
)
238+
239+
if self.check_reg_mode("off"):
237240
device_data["mode"] = "off"
238241

239242
if "None" not in avail_schedules:

0 commit comments

Comments
 (0)