From cce105608ec4ae6695b2832d99c646e151a87f5f Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Tue, 27 Oct 2026 08:43:42 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Verbraucher:=20Shelly=20Temperaturen,=20Top?= =?UTF-8?q?ics=20beim=20Hinzuf=C3=BCgen=20initialisieren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/control/consumer/consumer_data.py | 1 + packages/helpermodules/command.py | 4 ++-- .../modules/consumers/shelly/shelly_em/consumer.py | 3 ++- .../modules/consumers/shelly/shelly_pm/consumer.py | 3 ++- .../devices/shelly/shelly/status_handler.py | 14 ++++++++++++++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/control/consumer/consumer_data.py b/packages/control/consumer/consumer_data.py index 9bd5493a8c..ba39bac58e 100644 --- a/packages/control/consumer/consumer_data.py +++ b/packages/control/consumer/consumer_data.py @@ -77,6 +77,7 @@ class Get: set_power: Optional[float] = None state: Optional[bool] = False state_str: Optional[str] = field(default=None, metadata={"topic": "get/state_str"}) + temperatures: Optional[List[float]] = None voltages: List[float] = field(default_factory=voltages_list_factory) diff --git a/packages/helpermodules/command.py b/packages/helpermodules/command.py index d6526dc066..e572e96e88 100644 --- a/packages/helpermodules/command.py +++ b/packages/helpermodules/command.py @@ -1227,8 +1227,8 @@ def addConsumer(self, connection_id: str, payload: dict) -> None: MessageType.ERROR) Pub().pub(f'openWB/consumer/{new_id}/module', consumer_default) Pub().pub(f"openWB/consumer/{new_id}/config", asdict(ConsumerConfig())) - self._publish_default_metadata_fields(f"openWB/consumer/{new_id}", ConsumerGet()) - self._publish_default_metadata_fields(f"openWB/consumer/{new_id}", ConsumerSet()) + {Pub().pub(f"openWB/consumer/{new_id}/get/"+k, v) for (k, v) in asdict(ConsumerGet()).items()} + {Pub().pub(f"openWB/consumer/{new_id}/set/"+k, v) for (k, v) in asdict(ConsumerSet()).items()} Pub().pub(f"openWB/consumer/{new_id}/extra_meter", None) Pub().pub(f"openWB/consumer/{new_id}/usage", asdict(Usage(type=consumer_default["usage"][0]))) self.max_id_hierarchy = new_id diff --git a/packages/modules/consumers/shelly/shelly_em/consumer.py b/packages/modules/consumers/shelly/shelly_em/consumer.py index cc36cd877c..06949070fa 100644 --- a/packages/modules/consumers/shelly/shelly_em/consumer.py +++ b/packages/modules/consumers/shelly/shelly_em/consumer.py @@ -3,7 +3,7 @@ from modules.common.component_state import ConsumerState from modules.common.configurable_consumer import ConfigurableConsumer from modules.consumers.shelly.shelly_em.config import ShellyEM -from modules.devices.shelly.shelly.status_handler import get_generation, request_status, parse_data +from modules.devices.shelly.shelly.status_handler import get_generation, request_status, parse_data, parse_temperatures def create_consumer(config: ShellyEM): @@ -22,6 +22,7 @@ def update() -> ConsumerState: consumer_state = ConsumerState( power=power, powers=powers, + temperatures=parse_temperatures(status, generation), ) if voltages is not None: consumer_state.voltages = voltages diff --git a/packages/modules/consumers/shelly/shelly_pm/consumer.py b/packages/modules/consumers/shelly/shelly_pm/consumer.py index 26c4035965..048296f4b0 100644 --- a/packages/modules/consumers/shelly/shelly_pm/consumer.py +++ b/packages/modules/consumers/shelly/shelly_pm/consumer.py @@ -5,7 +5,7 @@ from modules.common.component_state import ConsumerState from modules.common.configurable_consumer import ConfigurableConsumer from modules.consumers.shelly.shelly_pm.config import ShellyPM -from modules.devices.shelly.shelly.status_handler import get_generation, request_status, parse_data +from modules.devices.shelly.shelly.status_handler import get_generation, request_status, parse_data, parse_temperatures def create_consumer(config: ShellyPM): @@ -63,6 +63,7 @@ def update() -> ConsumerState: voltages=voltages, currents=currents, powers=powers, + temperatures=parse_temperatures(status, generation), ) return ConfigurableConsumer(consumer_config=config, diff --git a/packages/modules/devices/shelly/shelly/status_handler.py b/packages/modules/devices/shelly/shelly/status_handler.py index 0dcb1a6df3..2bb60c4e8c 100644 --- a/packages/modules/devices/shelly/shelly/status_handler.py +++ b/packages/modules/devices/shelly/shelly/status_handler.py @@ -31,6 +31,20 @@ def request_status(address: str, generation: Optional[int]) -> Dict: return req.get_http_session().get(status_url, timeout=3).json() +def parse_temperatures(status: Dict, generation: int) -> Optional[List[Optional[float]]]: + temperatures: List[Optional[float]] = [None, None, None] + for index in range(3): + try: + if generation == 1: + value = status['ext_temperature'][str(index)]['tC'] + else: + value = status[f'temperature:{100 + index}']['tC'] + temperatures[index] = float(value) + except (KeyError, TypeError, ValueError): + pass + return temperatures if any(value is not None for value in temperatures) else None + + def parse_data(phase: int, factor: float, status: Dict) -> Tuple[ List[float], Optional[List[float]], Optional[List[float]], Optional[List[float]], float, Optional[float]]: try: From add1db241eb95ec33f7e53f8c154b2e06d25601f Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Tue, 27 Oct 2026 08:50:29 +0100 Subject: [PATCH 2/4] ammend --- packages/modules/common/store/_consumer.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/modules/common/store/_consumer.py b/packages/modules/common/store/_consumer.py index 006eb09392..504d0fd094 100644 --- a/packages/modules/common/store/_consumer.py +++ b/packages/modules/common/store/_consumer.py @@ -29,8 +29,7 @@ def update(self) -> None: if self.state.imported is not None and self.state.exported is not None: pub_to_broker(f"openWB/set/consumer/{self.num}/get/imported", self.state.imported, 2) pub_to_broker(f"openWB/set/consumer/{self.num}/get/exported", self.state.exported, 2) - if self.state.temperatures is not None: - pub_to_broker(f"openWB/set/consumer/{self.num}/get/temperatures", self.state.temperatures) + pub_to_broker(f"openWB/set/consumer/{self.num}/get/temperatures", self.state.temperatures) class PurgeConsumerState(ValueStore[ConsumerState]): From 9e02f5cd1abad1b504f1888dd6442e596e73ad11 Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Tue, 27 Oct 2026 08:57:12 +0100 Subject: [PATCH 3/4] Review --- packages/modules/devices/shelly/shelly/status_handler.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/modules/devices/shelly/shelly/status_handler.py b/packages/modules/devices/shelly/shelly/status_handler.py index 2bb60c4e8c..4d076d1dea 100644 --- a/packages/modules/devices/shelly/shelly/status_handler.py +++ b/packages/modules/devices/shelly/shelly/status_handler.py @@ -31,18 +31,18 @@ def request_status(address: str, generation: Optional[int]) -> Dict: return req.get_http_session().get(status_url, timeout=3).json() -def parse_temperatures(status: Dict, generation: int) -> Optional[List[Optional[float]]]: - temperatures: List[Optional[float]] = [None, None, None] +def parse_temperatures(status: Dict, generation: int) -> Optional[List[float]]: + temperatures: List[float] = [] for index in range(3): try: if generation == 1: value = status['ext_temperature'][str(index)]['tC'] else: value = status[f'temperature:{100 + index}']['tC'] - temperatures[index] = float(value) + temperatures.append(float(value)) except (KeyError, TypeError, ValueError): pass - return temperatures if any(value is not None for value in temperatures) else None + return temperatures if len(temperatures) > 0 else None def parse_data(phase: int, factor: float, status: Dict) -> Tuple[ From fc194a942b75ea42f6ace1ffe91afef35df51f2c Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Tue, 27 Oct 2026 08:58:15 +0100 Subject: [PATCH 4/4] logging --- packages/modules/devices/shelly/shelly/status_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/modules/devices/shelly/shelly/status_handler.py b/packages/modules/devices/shelly/shelly/status_handler.py index 4d076d1dea..42ec365d8b 100644 --- a/packages/modules/devices/shelly/shelly/status_handler.py +++ b/packages/modules/devices/shelly/shelly/status_handler.py @@ -41,7 +41,7 @@ def parse_temperatures(status: Dict, generation: int) -> Optional[List[float]]: value = status[f'temperature:{100 + index}']['tC'] temperatures.append(float(value)) except (KeyError, TypeError, ValueError): - pass + log.exception(f"Error parsing temperature for index {index} in status: {status}") return temperatures if len(temperatures) > 0 else None