|
28 | 28 | REG_OPER_TIME_IMM3, |
29 | 29 | REG_PID, |
30 | 30 | REG_RETURN_LINE, |
| 31 | + COMP_POWER_STATUS, |
31 | 32 | COMP_STATUS, |
32 | 33 | COMP_STATUS_ITEC, |
33 | 34 | REG_SUPPLY_LINE, |
@@ -87,6 +88,11 @@ def __init__(self, device_data: dict, api_interface: "ThermiaAPI"): |
87 | 88 | self.__visible_operational_statuses_map = None |
88 | 89 | self.__running_operational_statuses = None |
89 | 90 |
|
| 91 | + self.__power_statuses = None |
| 92 | + self.__all_power_statuses_map = None |
| 93 | + self.__visible_power_statuses_map = None |
| 94 | + self.__running_power_statuses = None |
| 95 | + |
90 | 96 | self.update_data() |
91 | 97 |
|
92 | 98 | def update_data(self): |
@@ -126,6 +132,15 @@ def update_data(self): |
126 | 132 | ) |
127 | 133 | self.__running_operational_statuses = self.__get_running_operational_statuses() |
128 | 134 |
|
| 135 | + self.__power_statuses = self.__get_power_statuses_from_operational_status() |
| 136 | + self.__all_power_statuses_map = ( |
| 137 | + self.__get_all_power_statuses_from_power_status() |
| 138 | + ) |
| 139 | + self.__visible_power_statuses_map = ( |
| 140 | + self.__get_all_visible_power_statuses_from_power_status() |
| 141 | + ) |
| 142 | + self.__running_power_statuses = self.__get_running_power_statuses() |
| 143 | + |
129 | 144 | def get_register_indexes(self): |
130 | 145 | return self.__register_indexes |
131 | 146 |
|
@@ -517,6 +532,99 @@ def __get_running_operational_statuses( |
517 | 532 |
|
518 | 533 | return [] |
519 | 534 |
|
| 535 | + def __get_power_statuses_from_operational_status(self) -> Optional[Dict]: |
| 536 | + data = self.__get_register_from_operational_status(COMP_POWER_STATUS) |
| 537 | + |
| 538 | + if data is None: |
| 539 | + return None |
| 540 | + |
| 541 | + return data.get("valueNames", []) |
| 542 | + |
| 543 | + def __get_all_power_statuses_from_power_status( |
| 544 | + self, |
| 545 | + ) -> Optional[ChainMap]: |
| 546 | + data = self.__power_statuses |
| 547 | + |
| 548 | + if data is None: |
| 549 | + return ChainMap() |
| 550 | + |
| 551 | + power_modes_map = map( |
| 552 | + lambda values: { |
| 553 | + values.get("value"): { |
| 554 | + "name": values.get("name").split("COMP_VALUE_STEP_")[1], |
| 555 | + "visible": values.get("visible"), |
| 556 | + } |
| 557 | + }, |
| 558 | + data, |
| 559 | + ) |
| 560 | + |
| 561 | + power_modes_list = list(power_modes_map) |
| 562 | + return ChainMap(*power_modes_list) |
| 563 | + |
| 564 | + def __get_all_visible_power_statuses_from_power_status( |
| 565 | + self, |
| 566 | + ) -> Optional[ChainMap]: |
| 567 | + data = self.__all_power_statuses_map |
| 568 | + |
| 569 | + if data is None: |
| 570 | + return ChainMap() |
| 571 | + |
| 572 | + power_modes_map = map( |
| 573 | + lambda item: ( |
| 574 | + {item[0]: item[1].get("name")} if item[1].get("visible") else {} |
| 575 | + ), |
| 576 | + data.items(), |
| 577 | + ) |
| 578 | + |
| 579 | + power_modes_list = list(filter(lambda x: x != {}, power_modes_map)) |
| 580 | + return ChainMap(*power_modes_list) |
| 581 | + |
| 582 | + def __get_running_power_statuses( |
| 583 | + self, |
| 584 | + ) -> List[str]: |
| 585 | + data = self.__get_register_from_operational_status(COMP_POWER_STATUS) |
| 586 | + |
| 587 | + if data is None: |
| 588 | + return [] |
| 589 | + |
| 590 | + current_register_value = get_dict_value_or_none(data, "registerValue") |
| 591 | + |
| 592 | + data = self.__all_power_statuses_map |
| 593 | + |
| 594 | + if data is None: |
| 595 | + return [] |
| 596 | + |
| 597 | + data_items_list = list(data.items()) |
| 598 | + |
| 599 | + current_power_status = [ |
| 600 | + value.get("name") |
| 601 | + for key, value in data_items_list |
| 602 | + if key == current_register_value |
| 603 | + ] |
| 604 | + |
| 605 | + if len(current_power_status) == 1: |
| 606 | + return current_power_status |
| 607 | + |
| 608 | + if ( |
| 609 | + len(current_power_status) != 1 |
| 610 | + and current_register_value > 0 |
| 611 | + and len(data_items_list) > 1 |
| 612 | + ): |
| 613 | + # Attempt to get multiple statuses by binary sum of the values |
| 614 | + data_items_list.sort(key=lambda x: x[0], reverse=True) |
| 615 | + list_of_current_power_statuses = [] |
| 616 | + |
| 617 | + for key, value in data_items_list: |
| 618 | + if key <= current_register_value: |
| 619 | + current_register_value -= key |
| 620 | + if value.get("visible"): |
| 621 | + list_of_current_power_statuses.append(value.get("name")) |
| 622 | + |
| 623 | + if current_register_value == 0: |
| 624 | + return list_of_current_power_statuses |
| 625 | + |
| 626 | + return [] |
| 627 | + |
520 | 628 | @property |
521 | 629 | def name(self): |
522 | 630 | return get_dict_value_or_none(self.__info, "name") |
@@ -699,94 +807,26 @@ def available_operational_statuses_map(self) -> Optional[ChainMap]: |
699 | 807 | return self.__visible_operational_statuses_map |
700 | 808 |
|
701 | 809 | @property |
702 | | - def operational_status_auxiliary_heater_3kw(self): |
703 | | - return self.__get_value_by_key_and_register_name_from_operational_status( |
704 | | - "COMP_POWER_STATUS", "COMP_VALUE_STEP_3KW" |
705 | | - ) |
706 | | - |
707 | | - @property |
708 | | - def operational_status_auxiliary_heater_6kw(self): |
709 | | - return self.__get_value_by_key_and_register_name_from_operational_status( |
710 | | - "COMP_POWER_STATUS", "COMP_VALUE_STEP_6KW" |
711 | | - ) |
712 | | - |
713 | | - @property |
714 | | - def operational_status_auxiliary_heater_9kw(self): |
715 | | - return self.__get_value_by_key_and_register_name_from_operational_status( |
716 | | - "COMP_POWER_STATUS", "COMP_VALUE_STEP_9KW" |
717 | | - ) |
718 | | - |
719 | | - @property |
720 | | - def operational_status_auxiliary_heater_12kw(self): |
721 | | - return self.__get_value_by_key_and_register_name_from_operational_status( |
722 | | - "COMP_POWER_STATUS", "COMP_VALUE_STEP_12KW" |
723 | | - ) |
724 | | - |
725 | | - @property |
726 | | - def operational_status_auxiliary_heater_15kw(self): |
727 | | - return self.__get_value_by_key_and_register_name_from_operational_status( |
728 | | - "COMP_POWER_STATUS", "COMP_VALUE_STEP_15KW" |
729 | | - ) |
730 | | - |
731 | | - @property |
732 | | - def operational_status_compressor_status(self) -> Optional[bool]: |
733 | | - if ( |
734 | | - self.__visible_operational_statuses_map is None |
735 | | - or "COMPR" not in self.__visible_operational_statuses_map.values() |
736 | | - ): |
737 | | - return None |
738 | | - |
739 | | - return "COMPR" in self.running_operational_statuses |
740 | | - |
741 | | - @property |
742 | | - def operational_status_brine_pump_status(self) -> Optional[bool]: |
743 | | - if ( |
744 | | - self.__visible_operational_statuses_map is None |
745 | | - or "BRINEPUMP" not in self.__visible_operational_statuses_map.values() |
746 | | - ): |
747 | | - return None |
748 | | - |
749 | | - return "BRINEPUMP" in self.running_operational_statuses |
| 810 | + def running_power_statuses(self) -> List[str]: |
| 811 | + data = self.__running_power_statuses |
750 | 812 |
|
751 | | - @property |
752 | | - def operational_status_radiator_pump_status(self) -> Optional[bool]: |
753 | | - if ( |
754 | | - self.__visible_operational_statuses_map is None |
755 | | - or "RADIATORPUMP" not in self.__visible_operational_statuses_map.values() |
756 | | - ): |
757 | | - return None |
| 813 | + if data is None: |
| 814 | + return [] |
758 | 815 |
|
759 | | - return "RADIATORPUMP" in self.running_operational_statuses |
| 816 | + return data |
760 | 817 |
|
761 | 818 | @property |
762 | | - def operational_status_cooling_status(self) -> Optional[bool]: |
763 | | - if ( |
764 | | - self.__visible_operational_statuses_map is None |
765 | | - or "COOLING" not in self.__visible_operational_statuses_map.values() |
766 | | - ): |
767 | | - return None |
768 | | - |
769 | | - return "COOLING" in self.running_operational_statuses |
| 819 | + def available_power_statuses(self) -> Optional[List[str]]: |
| 820 | + data = self.__visible_power_statuses_map |
770 | 821 |
|
771 | | - @property |
772 | | - def operational_status_hot_water_status(self) -> Optional[bool]: |
773 | | - if ( |
774 | | - self.__visible_operational_statuses_map is None |
775 | | - or "HOT_WATER" not in self.__visible_operational_statuses_map.values() |
776 | | - ): |
777 | | - return None |
| 822 | + if data is None: |
| 823 | + return [] |
778 | 824 |
|
779 | | - return "HOT_WATER" in self.running_operational_statuses |
| 825 | + return list(data.values()) |
780 | 826 |
|
781 | 827 | @property |
782 | | - def operational_status_heating_status(self) -> Optional[bool]: |
783 | | - if ( |
784 | | - self.__visible_operational_statuses_map is None |
785 | | - or "HEATING" not in self.__visible_operational_statuses_map.values() |
786 | | - ): |
787 | | - return None |
788 | | - |
789 | | - return "HEATING" in self.running_operational_statuses |
| 828 | + def available_power_statuses_map(self) -> Optional[ChainMap]: |
| 829 | + return self.__visible_power_statuses_map |
790 | 830 |
|
791 | 831 | @property |
792 | 832 | def operational_status_integral(self): |
|
0 commit comments