From 53ddfde1776a76f997025ba8f8867626c4658a40 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Wed, 14 Oct 2026 15:23:56 +0200 Subject: [PATCH] Update unmeasured_home_consumption --- packages/control/counter_all/counter_all.py | 23 ++----- .../counter_home_consumption_test.py | 69 +++---------------- 2 files changed, 12 insertions(+), 80 deletions(-) diff --git a/packages/control/counter_all/counter_all.py b/packages/control/counter_all/counter_all.py index 21db99a618..d8c2e48de5 100644 --- a/packages/control/counter_all/counter_all.py +++ b/packages/control/counter_all/counter_all.py @@ -168,23 +168,6 @@ def _calc_home_consumption_from_counter( return home_consumption, not_home_consumption - def _calc_unmeasured_home_consumption_from_counter(self, element: Dict) -> float: - elements = self.get_elements_for_downstream_calculation(element["id"]) - element_for_calculation = {"id": element["id"], "type": ComponentType.COUNTER.value, "children": elements} - unmeasured_home_consumption = self._get_local_power_from_counter(element_for_calculation) - - for child in elements: - comp = self._get_component(child) - - if comp.data.get.fault_state < 2: - if child["type"] == ComponentType.COUNTER.value: - unmeasured_home_consumption += self._calc_unmeasured_home_consumption_from_counter(child) - else: - log.warning( - f"Komponente {element['type']}{comp.num} ist im Fehlerzustand und wird nicht berücksichtigt.") - - return unmeasured_home_consumption - def _calc_home_consumption(self) -> Tuple[float, float, Dict]: evu_id = self.get_id_evu_counter() @@ -210,9 +193,11 @@ def _calc_home_consumption(self) -> Tuple[float, float, Dict]: def _calc_unmeasured_home_consumption(self) -> float: evu_id = self.get_id_evu_counter() - evu_element = {"id": evu_id, "type": ComponentType.COUNTER.value} + elements = self.get_elements_for_downstream_calculation(evu_id) + element_for_calculation = {"id": evu_id, "type": ComponentType.COUNTER.value, "children": elements} - unmeasured_home_consumption = self._calc_unmeasured_home_consumption_from_counter(evu_element) + # wir checken nur den EVU-Zähler, da bei ihm alles zusammenläuft. + unmeasured_home_consumption = self._get_local_power_from_counter(element_for_calculation) unmeasured_home_consumption -= self.data.set.smarthome_power_excluded_from_home_consumption return unmeasured_home_consumption diff --git a/packages/control/counter_all/counter_home_consumption_test.py b/packages/control/counter_all/counter_home_consumption_test.py index b1a7b05ad0..b286b7c34e 100644 --- a/packages/control/counter_all/counter_home_consumption_test.py +++ b/packages/control/counter_all/counter_home_consumption_test.py @@ -729,43 +729,7 @@ def test_set_home_consumption_sets_unmeasured_home_consumption_rest_power(): assert c.data.set.unmeasured_home_consumption == 700 -def test_set_home_consumption_adds_child_counter_rest_to_unmeasured_home_consumption(): - data.data_init(Mock()) - c = CounterAll() - c.data.get.hierarchy = [{ - "id": 0, - "type": "counter", - "children": [{"id": 8, "type": "counter", "children": []}], - }] - - data.data.counter_data = { - "counter0": Mock( - spec=Counter, - num=0, - data=Mock( - spec=CounterData, - get=Mock(spec=CounterGet, power=1000, fault_state=0), - config=Mock(spec=CounterConfig, is_home_consumption_counter=CounterMode.AUTO_HOME_CONSUMPTION.value), - ), - ), - "counter8": Mock( - spec=Counter, - num=8, - data=Mock( - spec=CounterData, - get=Mock(spec=CounterGet, power=300, fault_state=0), - config=Mock(spec=CounterConfig, is_home_consumption_counter=CounterMode.NOT_HOME_CONSUMPTION.value), - ), - ), - } - - c.set_home_consumption() - - assert c.data.set.home_consumption == 700 - assert c.data.set.unmeasured_home_consumption == 1000 - - -def test_set_home_consumption_adds_child_counter_rest_behind_chargepoint_to_unmeasured_home_consumption(): +def test_set_home_consumption_ignores_child_counter_rest_for_unmeasured_home_consumption(): data.data_init(Mock()) c = CounterAll() c.data.get.hierarchy = [{ @@ -811,17 +775,18 @@ def test_set_home_consumption_adds_child_counter_rest_behind_chargepoint_to_unme c.set_home_consumption() assert c.data.set.home_consumption == 2000 - assert c.data.set.unmeasured_home_consumption == 2000 + assert c.data.set.unmeasured_home_consumption == 0 -def test_calc_unmeasured_home_consumption_uses_downstream_elements_on_each_counter(monkeypatch): +def test_calc_unmeasured_home_consumption_subtracts_smarthome_excluded_power(): data.data_init(Mock()) c = CounterAll() c.data.get.hierarchy = [{ "id": 0, "type": "counter", - "children": [{"id": 8, "type": "counter", "children": []}], + "children": [{"id": 3, "type": "cp", "children": []}], }] + c.data.set.smarthome_power_excluded_from_home_consumption = 300 data.data.counter_data = { "counter0": Mock( @@ -829,40 +794,22 @@ def test_calc_unmeasured_home_consumption_uses_downstream_elements_on_each_count num=0, data=Mock( spec=CounterData, - get=Mock(spec=CounterGet, power=5000, fault_state=0), + get=Mock(spec=CounterGet, power=1000, fault_state=0), config=Mock(spec=CounterConfig, is_home_consumption_counter=CounterMode.AUTO_HOME_CONSUMPTION.value), ), ), - "counter8": Mock( - spec=Counter, - num=8, - data=Mock( - spec=CounterData, - get=Mock(spec=CounterGet, power=5000, fault_state=0), - config=Mock(spec=CounterConfig, is_home_consumption_counter=CounterMode.HOME_CONSUMPTION.value), - ), - ), } data.data.cp_data = { "cp3": Mock( spec=Chargepoint, data=Mock( spec=ChargepointData, - get=Mock(spec=Get, power=3000, fault_state=0), + get=Mock(spec=Get, power=200, fault_state=0), ), ), } - def get_elements_for_downstream_calculation(counter_id): - if counter_id == 0: - return [{"id": 8, "type": "counter", "children": []}] - if counter_id == 8: - return [{"id": 3, "type": "cp", "children": []}] - return [] - - monkeypatch.setattr(c, "get_elements_for_downstream_calculation", get_elements_for_downstream_calculation) - - assert c._calc_unmeasured_home_consumption() == 2000 + assert c._calc_unmeasured_home_consumption() == 500 def test_calc_unmeasured_home_consumption_subtracts_inverter_power():