diff --git a/packages/helpermodules/command.py b/packages/helpermodules/command.py index be0cb0c5f9..11ee114bf1 100644 --- a/packages/helpermodules/command.py +++ b/packages/helpermodules/command.py @@ -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( diff --git a/packages/helpermodules/command_test.py b/packages/helpermodules/command_test.py index d9115dfbd4..d01f479802 100644 --- a/packages/helpermodules/command_test.py +++ b/packages/helpermodules/command_test.py @@ -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 @@ -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 diff --git a/packages/helpermodules/subdata.py b/packages/helpermodules/subdata.py index a115217f78..f0f76c693b 100644 --- a/packages/helpermodules/subdata.py +++ b/packages/helpermodules/subdata.py @@ -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) diff --git a/packages/modules/common/component_type.py b/packages/modules/common/component_type.py index 8ae99c397b..2f8cb58a65 100644 --- a/packages/modules/common/component_type.py +++ b/packages/modules/common/component_type.py @@ -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: