Skip to content

Commit 17e6798

Browse files
committed
Various improvements
1 parent 51f9db4 commit 17e6798

3 files changed

Lines changed: 89 additions & 50 deletions

File tree

plugwise/common.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def _get_groups(self) -> None:
224224
self._count += 5
225225

226226
def _get_lock_state(
227-
self, xml: etree.Element, data: GwEntityData, stretch_v2: bool = False
227+
self, appl: Appliance, data: GwEntityData, stretch_v2: bool = False
228228
) -> None:
229229
"""Helper-function for _get_measurement_data().
230230
@@ -235,10 +235,12 @@ def _get_lock_state(
235235
if stretch_v2:
236236
actuator = "actuators"
237237
func_type = "relay"
238-
if xml.find("type").text not in SPECIAL_PLUG_TYPES:
239-
locator = f"./{actuator}/{func_type}/lock"
240-
if (found := xml.find(locator)) is not None:
241-
data["switches"]["lock"] = found.text == "true"
238+
if appl.type in SPECIAL_PLUG_TYPES:
239+
return
240+
241+
if (actuator := getattr(appl, actuator, None)) is not None:
242+
if func_type := actuator.get(func_type) is not None:
243+
data["switches"]["lock"] = func_type.lock
242244
self._count += 1
243245

244246
def _get_module_data(

plugwise/helper.py

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,11 @@
5757
from packaging import version
5858

5959

60-
def search_actuator_functionalities(
61-
appliance: etree.Element, actuator: str
62-
) -> etree.Element | None:
60+
def search_actuator_functionalities(appl: Appliance, actuator: str) -> Appliance | None:
6361
"""Helper-function for finding the relevant actuator xml-structure."""
64-
locator = f"./actuator_functionalities/{actuator}"
65-
if (search := appliance.find(locator)) is not None:
66-
return search
62+
if (af := getattr(appl, "actuator_functionalities", None)) is not None:
63+
if (af_actuator := af.get(actuator)) is not None:
64+
return af_actuator
6765

6866
return None
6967

@@ -379,15 +377,15 @@ def _collect_appliance_data(
379377
measurements: dict[str, DATA | UOM],
380378
) -> etree.Element | None:
381379
"""Collect initial appliance data."""
382-
if (appliance := self._domain_objects.get_appliance(entity_id)) is not None:
380+
if (appliance := self.data.get_appliance(entity_id)) is not None:
383381
# print(f"HOI9 {appliance}")
384382
self._appliance_measurements(appliance, data, measurements)
385383
self._get_lock_state(appliance, data)
386384

387385
for toggle, name in TOGGLES.items():
388386
self._get_toggle_state(appliance, toggle, name, data)
389387

390-
if appliance.find("type").text in ACTUATOR_CLASSES:
388+
if appliance.type in ACTUATOR_CLASSES:
391389
self._get_actuator_functionalities(appliance, entity, data)
392390

393391
return appliance
@@ -419,55 +417,68 @@ def _appliance_measurements(
419417
measurements: dict[str, DATA | UOM],
420418
) -> None:
421419
"""Helper-function for _get_measurement_data() - collect appliance measurement data."""
420+
print(f"HOI10 {appliance}")
422421
for measurement, attrs in measurements.items():
423-
# print(f"HOI10 {appliance}")
424422
# print(f"HOI10 {appliance.logs}")
425-
if "point_log" not in appliance.logs:
423+
if appliance.logs.get("point_log") is None:
426424
continue
427425

428-
# print(f"HOI10 {appliance.logs.point_log}")
429-
430-
if (
431-
measurement := next(
432-
(m for m in appliance.logs if m.type == "measurement"), None
433-
)
434-
) is not None:
435-
if skip_obsolete_measurements(appliance, measurement):
436-
continue
437-
438-
if new_name := getattr(attrs, ATTR_NAME, None):
439-
measurement = new_name
440-
441-
match measurement:
442-
case "elga_status_code":
443-
data["elga_status_code"] = int(appl_p_loc.text)
444-
case "select_dhw_mode":
445-
if self._dhw_allowed_modes:
446-
data["select_dhw_mode"] = appl_p_loc.text
447-
448-
common_match_cases(measurement, attrs, appl_p_loc, data)
449-
450-
i_locator = f'.//logs/interval_log[type="{measurement}"]/period/measurement'
451-
if (appl_i_loc := appliance.find(i_locator)) is not None:
452-
name = cast(SensorType, f"{measurement}_interval")
453-
data["sensors"][name] = format_measure(
454-
appl_i_loc.text, ENERGY_WATT_HOUR
455-
)
426+
# print(f'HOI10a {appliance.logs["point_log"]}')
427+
428+
for m in appliance.logs["point_log"]:
429+
if m.type == measurement:
430+
print(f'HOI10b {measurement}')
431+
# if (
432+
# measurement := next(
433+
# (m for m in appliance.logs["point_log"] if m.type == measurement), None
434+
# )
435+
# ) is not None:
436+
# print(f'HOI10b {measurement}')
437+
# if skip_obsolete_measurements(appliance, measurement):
438+
# continue
439+
#
440+
# if new_name := getattr(attrs, ATTR_NAME, None):
441+
# measurement = new_name
442+
#
443+
# match measurement:
444+
# case "elga_status_code":
445+
# data["elga_status_code"] = int(appl_p_loc.text)
446+
# case "select_dhw_mode":
447+
# if self._dhw_allowed_modes:
448+
# data["select_dhw_mode"] = appl_p_loc.text
449+
#
450+
# common_match_cases(measurement, attrs, appl_p_loc, data)
451+
#
452+
# if appliance.logs.get("interval_log") is None:
453+
# continue
454+
#
455+
# if (
456+
# measurement := next(
457+
# (m for m in appliance.logs["interval_log"] if m.type == "measurement"), None
458+
# )
459+
# ) is not None:
460+
# name = cast(SensorType, f"{measurement}_interval")
461+
# data["sensors"][name] = format_measure(
462+
# appl_i_loc.text, ENERGY_WATT_HOUR
463+
# )
456464

457465
self._count = count_data_items(self._count, data)
458466

459467
def _get_toggle_state(
460-
self, xml: etree.Element, toggle: str, name: ToggleNameType, data: GwEntityData
468+
self, appl: Appliance, toggle: str, name: ToggleNameType, data: GwEntityData
461469
) -> None:
462470
"""Helper-function for _get_measurement_data().
463471
464472
Obtain the toggle state of a 'toggle' = switch.
465473
"""
466-
if xml.find("type").text == "heater_central":
467-
locator = f"./actuator_functionalities/toggle_functionality[type='{toggle}']/state"
468-
if (state := xml.find(locator)) is not None:
469-
data["switches"][name] = state.text == "on"
470-
self._count += 1
474+
if appl.type != "heater_central":
475+
return
476+
477+
if (actuator := getattr(appl, "actuator_functionalities", None)) is not None:
478+
if (tf := actuator.get("toggle_functionality")) is not None:
479+
if tf.type == toggle:
480+
data["switches"][name] = tf.state
481+
self._count += 1
471482

472483
def _get_plugwise_notifications(self) -> None:
473484
"""Collect the Plugwise notifications."""
@@ -563,7 +574,7 @@ def _get_actuator_mode(
563574
return None
564575

565576
if (search := search_actuator_functionalities(appliance, key)) is not None:
566-
return str(search.find("mode").text)
577+
return search.mode
567578

568579
return None
569580

plugwise/model.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ class BaseFunctionality(WithID):
106106
updated_date: str | None = None
107107

108108

109+
class GatewayModeControlFunctionality(BaseFunctionality):
110+
"""Gateway mode control functionality"""
111+
112+
type: str
113+
mode: str
114+
gateway_mode_control: WithID | None = None
115+
116+
117+
class RegulationModeControlFunctionality(BaseFunctionality):
118+
"""Regulation mode control functionality"""
119+
120+
type: str
121+
mode: str
122+
regulation_mode_control: WithID | None = None
123+
124+
109125
class RelayFunctionality(BaseFunctionality):
110126
"""Relay functionality."""
111127

@@ -125,6 +141,16 @@ class ThermostatFunctionality(BaseFunctionality):
125141
thermostat: WithID | None = None
126142

127143

144+
class ToggleFunctionality(BaseFunctionality):
145+
"""Toggle functionality."""
146+
147+
type: str
148+
state: str
149+
cooling_toggle: WithID | None = None
150+
domestic_hot_water_toggle: WithID | None = None
151+
proximity_sensor_toggle: WithID | None = None
152+
153+
128154
class OffsetFunctionality(BaseFunctionality):
129155
"""Offset functionality."""
130156

0 commit comments

Comments
 (0)