Skip to content

Commit ae165f4

Browse files
committed
Break out _create_special_dicts() as common function
1 parent 43f7da0 commit ae165f4

3 files changed

Lines changed: 31 additions & 35 deletions

File tree

plugwise/common.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
from plugwise.constants import (
1111
ANNA,
12+
DHW_SETPOINT,
1213
GROUP_TYPES,
1314
NONE,
1415
PRIORITY_DEVICE_CLASSES,
1516
SPECIAL_PLUG_TYPES,
1617
SWITCH_GROUP_TYPES,
18+
ActuatorData,
1719
ApplianceType,
1820
GwEntityData,
1921
ModuleData,
@@ -289,3 +291,31 @@ def _get_module_data(
289291
break
290292

291293
return module_data
294+
295+
def _create_special_dicts(
296+
self, item: str, data: GwEntityData, temp_dict: ActuatorData
297+
) -> tuple[str, ActuatorData]:
298+
"""Create dhw_temperature and boiler_temperature dicts.
299+
300+
The initial item-names are updated and a current key is added.
301+
Also, the copied sensor data is removed.
302+
"""
303+
if item == DHW_SETPOINT:
304+
item = "dhw_temperature"
305+
if DHW_SETPOINT in data["sensors"]:
306+
data["sensors"].pop(DHW_SETPOINT)
307+
self._count -= 1
308+
if "dhw_temperature" in data["sensors"]:
309+
temp_dict["current"] = data["sensors"]["dhw_temperature"]
310+
data["sensors"].pop("dhw_temperature")
311+
elif "water_temperature" in data["sensors"]:
312+
temp_dict["current"] = data["sensors"]["water_temperature"]
313+
self._count += 1
314+
315+
if item == "maximum_boiler_temperature":
316+
item = "boiler_temperature"
317+
if "water_temperature" in data["sensors"]:
318+
temp_dict["current"] = data["sensors"]["water_temperature"]
319+
data["sensors"].pop("water_temperature")
320+
321+
return item, temp_dict

plugwise/helper.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
ATTR_NAME,
1919
DATA,
2020
DEVICE_MEASUREMENTS,
21-
DHW_SETPOINT,
2221
DOMAIN_OBJECTS,
2322
ENERGY_WATT_HOUR,
2423
GROUP_MEASUREMENTS,
@@ -587,34 +586,6 @@ def _get_actuator_functionalities(
587586
act_item = cast(ActuatorType, item)
588587
data[act_item] = temp_dict
589588

590-
def _create_special_dicts(
591-
self, item: str, data: GwEntityData, temp_dict: ActuatorData
592-
) -> tuple[str, ActuatorData]:
593-
"""Create dhw_temperature and boiler_temperature dicts.
594-
595-
The initial item-names are updated and a current key is added.
596-
Also, the copied sensor data is removed.
597-
"""
598-
if item == DHW_SETPOINT:
599-
item = "dhw_temperature"
600-
if DHW_SETPOINT in data["sensors"]:
601-
data["sensors"].pop(DHW_SETPOINT)
602-
self._count -= 1
603-
if "dhw_temperature" in data["sensors"]:
604-
temp_dict["current"] = data["sensors"]["dhw_temperature"]
605-
data["sensors"].pop("dhw_temperature")
606-
elif "water_temperature" in data["sensors"]:
607-
temp_dict["current"] = data["sensors"]["water_temperature"]
608-
self._count += 1
609-
610-
if item == "maximum_boiler_temperature":
611-
item = "boiler_temperature"
612-
if "water_temperature" in data["sensors"]:
613-
temp_dict["current"] = data["sensors"]["water_temperature"]
614-
data["sensors"].pop("water_temperature")
615-
616-
return item, temp_dict
617-
618589
def _get_actuator_mode(
619590
self, appliance: etree.Element, entity_id: str, key: str
620591
) -> str | None:

plugwise/legacy/helper.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,7 @@ def _get_actuator_functionalities(
366366
self._count += 1
367367

368368
if temp_dict:
369-
if item == "maximum_boiler_temperature":
370-
item = "boiler_temperature"
371-
if "water_temperature" in data["sensors"]:
372-
temp_dict["current"] = data["sensors"]["water_temperature"]
373-
data["sensors"].pop("water_temperature")
374-
369+
item, temp_dict = self._create_special_dicts(item, data, temp_dict)
375370
act_item = cast(ActuatorType, item)
376371
data[act_item] = temp_dict
377372

0 commit comments

Comments
 (0)