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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
43 changes: 30 additions & 13 deletions xcomfort/bridge.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bridge module for xComfort integration."""

import asyncio
from enum import Enum
import logging
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"]))
Expand Down Expand Up @@ -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."""
Expand Down
8 changes: 7 additions & 1 deletion xcomfort/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading