Initial public release

This commit is contained in:
ajp_anton
2026-05-30 15:44:40 +00:00
commit cc4e0c2c0f
56 changed files with 11840 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
from __future__ import annotations
from copy import deepcopy
from ha_deconz_bridge.state import ControllerCommand, ControllerState
from ha_deconz_bridge.translate import controller_command_to_state
class FakeControllerBackend:
def __init__(self, resources: dict[str, dict[str, object]]) -> None:
self._resources = deepcopy(resources)
def fetch_controller_resource(self, controller_id: str) -> dict[str, object]:
return deepcopy(self._resources[controller_id])
def read_controller_state(self, controller_id: str) -> ControllerState:
resource = self._resources[controller_id]
state = resource.get("state", {})
return self.normalize_event(controller_id, state)
def write_controller_command(self, controller_id: str, command: ControllerCommand) -> None:
state = controller_command_to_state(command)
resource = self._resources[controller_id]
raw_state: dict[str, object] = {
"reachable": True,
"on": state.on,
}
if state.brightness is not None:
raw_state["bri"] = state.brightness
if state.mode == "rgb" and state.xy is not None:
raw_state["colormode"] = "xy"
raw_state["xy"] = list(state.xy)
elif state.mode == "color_temp" and state.color_temp is not None:
raw_state["colormode"] = "ct"
raw_state["ct"] = state.color_temp
resource["state"] = raw_state
def normalize_event(
self,
controller_id: str,
raw_state: dict[str, object],
) -> ControllerState:
from ha_deconz_bridge.backends.deconz import DeconzBackend
return DeconzBackend._normalize_state(raw_state)
def push_state(self, controller_id: str, raw_state: dict[str, object]) -> None:
self._resources[controller_id]["state"] = deepcopy(raw_state)