|
55 | 55 | InvalidXMLError, |
56 | 56 | ResponseError, |
57 | 57 | ) |
58 | | -from plugwise.util import ( |
59 | | - check_model, |
60 | | - escape_illegal_xml_characters, |
61 | | - format_measure, |
62 | | - power_data_local_format, |
63 | | -) |
| 58 | +from plugwise.util import check_model, escape_illegal_xml_characters, format_measure |
64 | 59 |
|
65 | 60 | # This way of importing aiohttp is because of patch/mocking in testing (aiohttp timeouts) |
66 | 61 | from aiohttp import BasicAuth, ClientError, ClientResponse, ClientSession, ClientTimeout |
@@ -558,68 +553,17 @@ def _power_data_from_location(self, loc_id: str) -> DeviceData: |
558 | 553 | direct_data: DeviceData = {"sensors": {}} |
559 | 554 | loc = Munch() |
560 | 555 | log_list: list[str] = ["point_log", "cumulative_log", "interval_log"] |
561 | | - peak_list: list[str] = ["nl_peak", "nl_offpeak"] |
562 | 556 | t_string = "tariff" |
563 | 557 |
|
564 | 558 | search = self._domain_objects |
565 | 559 | loc.logs = search.find(f'./location[@id="{loc_id}"]/logs') |
566 | 560 | for loc.measurement, loc.attrs in P1_MEASUREMENTS.items(): |
567 | 561 | for loc.log_type in log_list: |
568 | | - for loc.peak_select in peak_list: |
569 | | - loc.locator = ( |
570 | | - f'./{loc.log_type}[type="{loc.measurement}"]/period/' |
571 | | - f'measurement[@{t_string}="{loc.peak_select}"]' |
572 | | - ) |
573 | | - loc = self._power_data_peak_value(loc) |
574 | | - if not loc.found: |
575 | | - continue |
576 | | - |
577 | | - direct_data = self._power_data_energy_diff( |
578 | | - loc.measurement, loc.net_string, loc.f_val, direct_data |
579 | | - ) |
580 | | - key = cast(SensorType, loc.key_string) |
581 | | - direct_data["sensors"][key] = loc.f_val |
| 562 | + self._collect_power_values(direct_data, loc, t_string) |
582 | 563 |
|
583 | 564 | self._count += len(direct_data["sensors"]) |
584 | 565 | return direct_data |
585 | 566 |
|
586 | | - def _power_data_peak_value(self, loc: Munch) -> Munch: |
587 | | - """Helper-function for _power_data_from_location() and _power_data_from_modules().""" |
588 | | - loc.found = True |
589 | | - # If locator not found look for P1 gas_consumed or phase data (without tariff) |
590 | | - if loc.logs.find(loc.locator) is None: |
591 | | - if "log" in loc.log_type and ( |
592 | | - "gas" in loc.measurement or "phase" in loc.measurement |
593 | | - ): |
594 | | - # Avoid double processing by skipping one peak-list option |
595 | | - if loc.peak_select == "nl_offpeak": |
596 | | - loc.found = False |
597 | | - return loc |
598 | | - |
599 | | - loc.locator = ( |
600 | | - f'./{loc.log_type}[type="{loc.measurement}"]/period/measurement' |
601 | | - ) |
602 | | - if loc.logs.find(loc.locator) is None: |
603 | | - loc.found = False |
604 | | - return loc |
605 | | - else: |
606 | | - loc.found = False # pragma: no cover |
607 | | - return loc # pragma: no cover |
608 | | - |
609 | | - if (peak := loc.peak_select.split("_")[1]) == "offpeak": |
610 | | - peak = "off_peak" |
611 | | - log_found = loc.log_type.split("_")[0] |
612 | | - loc.key_string = f"{loc.measurement}_{peak}_{log_found}" |
613 | | - if "gas" in loc.measurement or loc.log_type == "point_meter": |
614 | | - loc.key_string = f"{loc.measurement}_{log_found}" |
615 | | - if "phase" in loc.measurement: |
616 | | - loc.key_string = f"{loc.measurement}" |
617 | | - loc.net_string = f"net_electricity_{log_found}" |
618 | | - val = loc.logs.find(loc.locator).text |
619 | | - loc.f_val = power_data_local_format(loc.attrs, loc.key_string, val) |
620 | | - |
621 | | - return loc |
622 | | - |
623 | 567 | def _appliance_measurements( |
624 | 568 | self, |
625 | 569 | appliance: etree, |
|
0 commit comments