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
2 changes: 1 addition & 1 deletion packages/helpermodules/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ def addConsumer(self, connection_id: str, payload: dict) -> None:
self._publish_default_metadata_fields(f"openWB/set/consumer/{new_id}", ConsumerGet())
self._publish_default_metadata_fields(f"openWB/set/consumer/{new_id}", ConsumerSet())
Pub().pub(f"openWB/set/consumer/{new_id}/extra_meter", None)
Pub().pub(f"openWB/set/consumer/{new_id}/usage", asdict(Usage()))
Pub().pub(f"openWB/set/consumer/{new_id}/usage", asdict(Usage(type=consumer_default["usage"][0])))
self.max_id_hierarchy = new_id
Pub().pub("openWB/set/command/max_id/hierarchy", new_id)
pub_user_message(
Expand Down
33 changes: 33 additions & 0 deletions packages/helpermodules/command_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from unittest.mock import Mock
from types import SimpleNamespace

import pytest

from control.chargepoint.chargepoint import Chargepoint
from control.chargepoint.chargepoint_state_update import ChargepointStateUpdate
from control.consumer.usage import ConsumerUsage
import dataclass_utils
from helpermodules import command
from helpermodules.command import Command
from helpermodules.measurement_logging import process_log
from helpermodules.subdata import SubData
Expand Down Expand Up @@ -74,3 +77,33 @@ def test_getDailyLog(regular_daily_log_entry,
assert len(mock_pub.method_calls) == 1
assert mock_pub.method_calls[0][1][0] == 'openWB/set/log/daily/20250616'
assert mock_pub.method_calls[0][1][1] == regular_daily_log_entry_processed_legacy_converted


@pytest.mark.parametrize("usage_type", [ConsumerUsage.SUSPENDABLE_TUNABLE, ConsumerUsage.METER_ONLY])
def test_add_consumer_uses_module_default_usage_type(usage_type, mock_pub, monkeypatch):
consumer_setup = SimpleNamespace(
id=0,
type="test_consumer",
name="Test-Verbraucher",
info={},
configuration=SimpleNamespace(),
vendor="test",
usage=(usage_type,),
)
descriptor = SimpleNamespace(configuration_factory=Mock(return_value=consumer_setup))
monkeypatch.setattr(command.importlib, "import_module", Mock(return_value=SimpleNamespace(
device_descriptor=descriptor)))
monkeypatch.setattr(command, "pub_user_message", Mock())
monkeypatch.setattr(SubData, "counter_all_data", Mock())
SubData.counter_all_data.get_id_evu_counter.return_value = 0
SubData.counter_all_data.data.get.hierarchy = []
SubData.counter_all_data.data.get.loadmanagement_prios = []
command_instance = Command.__new__(Command)
command_instance.max_id_hierarchy = 0

command_instance.addConsumer("test", {"data": {"vendor": "test", "type": "test_consumer"}})

usage_calls = [call for call in mock_pub.pub.call_args_list
if call.args[0] == "openWB/set/consumer/1/usage"]
assert len(usage_calls) == 1
assert usage_calls[0].args[1]["type"] == usage_type.value
3 changes: 3 additions & 0 deletions packages/helpermodules/subdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,9 @@ def process_consumer_topic(self, client: mqtt.Client, var: Dict[str, Consumer],
var.pop("consumer"+index)
else:
if f"consumer{index}" not in var:
if re.search(
r"openWB/consumer/[0-9]+/(module|config|usage|extra_meter)$", msg.topic) is None:
return
var[f"consumer{index}"] = Consumer(int(index))
if re.search("openWB/consumer/[0-9]+/module$", msg.topic) is not None:
consumer_config = decode_payload(msg.payload)
Expand Down
20 changes: 17 additions & 3 deletions packages/modules/common/component_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,28 @@ def type_topic_mapping_comp(component_type: str) -> str:


def component_type_to_readable_text(component_type: ComponentType):
if component_type == ComponentType.BAT:
if component_type == ComponentType.BACKUP_CLOUD:
return "Backup Cloud"
elif component_type == ComponentType.BAT:
return "Speicher"
elif component_type == ComponentType.COUNTER:
return "Zähler"
elif component_type == ComponentType.CHARGEPOINT:
return "Ladepunkt"
elif component_type == ComponentType.CONSUMER:
return "Verbraucher"
elif component_type == ComponentType.COUNTER:
return "Zähler"
elif component_type == ComponentType.FLEXIBLE_TARIFF:
return "Dynamischer Tarif"
elif component_type == ComponentType.GRID_FEE:
return "Netzentgelt"
elif component_type == ComponentType.INVERTER:
return "Wechselrichter"
elif component_type == ComponentType.IO:
return "IO-Geräte"
elif component_type == ComponentType.VEHICLE:
return "Fahrzeug"
else:
return "Unbekannter Komponenten-Typ"


class ComponentDescriptor:
Expand Down
Loading