Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions packages/control/counter_all/counter_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down
69 changes: 8 additions & 61 deletions packages/control/counter_all/counter_home_consumption_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [{
Expand Down Expand Up @@ -811,58 +775,41 @@ 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(
spec=Counter,
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():
Expand Down
Loading