|
57 | 57 | from packaging import version |
58 | 58 |
|
59 | 59 |
|
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: |
63 | 61 | """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 |
67 | 65 |
|
68 | 66 | return None |
69 | 67 |
|
@@ -379,15 +377,15 @@ def _collect_appliance_data( |
379 | 377 | measurements: dict[str, DATA | UOM], |
380 | 378 | ) -> etree.Element | None: |
381 | 379 | """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: |
383 | 381 | # print(f"HOI9 {appliance}") |
384 | 382 | self._appliance_measurements(appliance, data, measurements) |
385 | 383 | self._get_lock_state(appliance, data) |
386 | 384 |
|
387 | 385 | for toggle, name in TOGGLES.items(): |
388 | 386 | self._get_toggle_state(appliance, toggle, name, data) |
389 | 387 |
|
390 | | - if appliance.find("type").text in ACTUATOR_CLASSES: |
| 388 | + if appliance.type in ACTUATOR_CLASSES: |
391 | 389 | self._get_actuator_functionalities(appliance, entity, data) |
392 | 390 |
|
393 | 391 | return appliance |
@@ -419,55 +417,68 @@ def _appliance_measurements( |
419 | 417 | measurements: dict[str, DATA | UOM], |
420 | 418 | ) -> None: |
421 | 419 | """Helper-function for _get_measurement_data() - collect appliance measurement data.""" |
| 420 | + print(f"HOI10 {appliance}") |
422 | 421 | for measurement, attrs in measurements.items(): |
423 | | - # print(f"HOI10 {appliance}") |
424 | 422 | # print(f"HOI10 {appliance.logs}") |
425 | | - if "point_log" not in appliance.logs: |
| 423 | + if appliance.logs.get("point_log") is None: |
426 | 424 | continue |
427 | 425 |
|
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 | +# ) |
456 | 464 |
|
457 | 465 | self._count = count_data_items(self._count, data) |
458 | 466 |
|
459 | 467 | 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 |
461 | 469 | ) -> None: |
462 | 470 | """Helper-function for _get_measurement_data(). |
463 | 471 |
|
464 | 472 | Obtain the toggle state of a 'toggle' = switch. |
465 | 473 | """ |
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 |
471 | 482 |
|
472 | 483 | def _get_plugwise_notifications(self) -> None: |
473 | 484 | """Collect the Plugwise notifications.""" |
@@ -563,7 +574,7 @@ def _get_actuator_mode( |
563 | 574 | return None |
564 | 575 |
|
565 | 576 | if (search := search_actuator_functionalities(appliance, key)) is not None: |
566 | | - return str(search.find("mode").text) |
| 577 | + return search.mode |
567 | 578 |
|
568 | 579 | return None |
569 | 580 |
|
|
0 commit comments