From 53cf8f0a11ba1f4a513e54ec2ad8ac040354e5f8 Mon Sep 17 00:00:00 2001 From: javydekoning Date: Sun, 9 Nov 2025 21:03:01 +0100 Subject: [PATCH 1/2] feat: Fix bug when switching multiple lights --- xcomfort/bridge.py | 43 ++++++++++++++++++++++++++++++------------- xcomfort/devices.py | 8 +++++++- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/xcomfort/bridge.py b/xcomfort/bridge.py index 318ab18..6becff3 100644 --- a/xcomfort/bridge.py +++ b/xcomfort/bridge.py @@ -1,4 +1,5 @@ """Bridge module for xComfort integration.""" + import asyncio from enum import Enum import logging @@ -152,21 +153,30 @@ def _handle_SET_STATE_INFO(self, payload): for item in payload["item"]: if "deviceId" in item: deviceId = item["deviceId"] - device = self._devices[deviceId] - _LOGGER.debug("State update for device %s: %s", device.name, item) - device.handle_state(item) + device = self._devices.get(deviceId) + if device: + _LOGGER.debug("State update for device %s: %s", device.name, item) + device.handle_state(item) + else: + _LOGGER.warning("Received state update for unknown device %s: %s", deviceId, item) elif "roomId" in item: roomId = item["roomId"] - room = self._rooms[roomId] - _LOGGER.debug("State update for room %s: %s", room.name, item) - room.handle_state(item) + room = self._rooms.get(roomId) + if room: + _LOGGER.debug("State update for room %s: %s", room.name, item) + room.handle_state(item) + else: + _LOGGER.warning("Received state update for unknown room %s: %s", roomId, item) elif "compId" in item: compId = item["compId"] - comp = self._comps[compId] - _LOGGER.debug("State update for component %s: %s", comp.name, item) - comp.handle_state(item) + comp = self._comps.get(compId) + if comp: + _LOGGER.debug("State update for component %s: %s", comp.name, item) + comp.handle_state(item) + else: + _LOGGER.warning("Received state update for unknown component %s: %s", compId, item) else: _LOGGER.warning("Unknown state info item (no deviceId, roomId, or compId): %s", item) @@ -287,8 +297,9 @@ def _handle_SET_ALL_DATA(self, payload): self.state = State.Ready self.on_initialized.set() _LOGGER.info("Bridge initialization complete - all data loaded") - _LOGGER.info("Loaded %d devices, %d components, %d rooms", - len(self._devices), len(self._comps), len(self._rooms)) + _LOGGER.info( + "Loaded %d devices, %d components, %d rooms", len(self._devices), len(self._comps), len(self._rooms) + ) if "devices" in payload: _LOGGER.debug("Processing %d devices from SET_ALL_DATA", len(payload["devices"])) @@ -342,8 +353,14 @@ def _handle_SET_HOME_DATA(self, payload): home_scenes = payload.get("homeScenes", []) self.home_scenes_count = len(home_scenes) - _LOGGER.debug("Bridge info updated: id=%s, name=%s, type=%s, fw=%s, scenes=%s", - self.bridge_id, self.bridge_name, self.bridge_type, self.fw_version, self.home_scenes_count) + _LOGGER.debug( + "Bridge info updated: id=%s, name=%s, type=%s, fw=%s, scenes=%s", + self.bridge_id, + self.bridge_name, + self.bridge_type, + self.fw_version, + self.home_scenes_count, + ) def _handle_UNKNOWN(self, message_type, payload): """Handle unknown message types.""" diff --git a/xcomfort/devices.py b/xcomfort/devices.py index 7a9df55..44003eb 100644 --- a/xcomfort/devices.py +++ b/xcomfort/devices.py @@ -155,10 +155,16 @@ def interpret_dimmvalue_from_payload(self, switch, payload): if not switch: return self.state.value.dimmvalue if self.state.value is not None else 99 - return payload["dimmvalue"] + # Return dimmvalue if present, otherwise default to 99 (full brightness) + return payload.get("dimmvalue", 99) def handle_state(self, payload): """Handle light state updates.""" + # Only process if this is a switch state update + if "switch" not in payload: + _LOGGER.debug("Light %s received non-switch payload, ignoring: %s", self.name, payload) + return + switch = payload["switch"] dimmvalue = self.interpret_dimmvalue_from_payload(switch, payload) _LOGGER.debug("Light %s state update: switch=%s, dimmvalue=%s", self.name, switch, dimmvalue) From 8a6b7205dc501c282e2a87a9bade5f3510658d58 Mon Sep 17 00:00:00 2001 From: javydekoning Date: Sun, 9 Nov 2025 21:04:45 +0100 Subject: [PATCH 2/2] feat: Fix linters --- pyproject.toml | 2 +- xcomfort/devices.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e85ff71..c400017 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "xcomfort" -version = "0.4.0" +version = "0.4.1" description = "Integration with Eaton xComfort Bridge" readme = "README.md" license = {text = "MIT"} diff --git a/xcomfort/devices.py b/xcomfort/devices.py index 44003eb..3604422 100644 --- a/xcomfort/devices.py +++ b/xcomfort/devices.py @@ -164,7 +164,7 @@ def handle_state(self, payload): if "switch" not in payload: _LOGGER.debug("Light %s received non-switch payload, ignoring: %s", self.name, payload) return - + switch = payload["switch"] dimmvalue = self.interpret_dimmvalue_from_payload(switch, payload) _LOGGER.debug("Light %s state update: switch=%s, dimmvalue=%s", self.name, switch, dimmvalue)