tangled
alpha
login
or
join now
zzstoatzz.io
/
solux
0
fork
atom
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
fix: coerce groups string to list in load_state
zzstoatzz.io
1 month ago
5319d9c3
75d0c3bb
+6
-9
2 changed files
expand all
collapse all
unified
split
src
solux
controller.py
state.py
-8
src/solux/controller.py
···
166
166
transition_seconds: float = 60.0,
167
167
) -> None:
168
168
"""apply light state to groups."""
169
169
-
print(f"DEBUG apply_state: groups={groups!r}, type={type(groups)}")
170
169
bridge = get_bridge()
171
170
172
171
if groups is None:
173
172
all_groups = bridge.get_group()
174
174
-
print(f"DEBUG all_groups type={type(all_groups)}, value={all_groups!r}")
175
173
if isinstance(all_groups, list):
176
174
# hue api returns errors as a list, e.g. [{"error": {"description": "..."}}]
177
175
errors = []
178
176
for item in all_groups:
179
179
-
print(f"DEBUG item={item!r}, type={type(item)}")
180
177
if isinstance(item, dict) and isinstance(item.get("error"), dict):
181
178
errors.append(item["error"].get("description", str(item["error"])))
182
179
if errors:
···
189
186
for gid, info in all_groups.items()
190
187
if isinstance(info, dict) and info.get("name") not in ("all", "Custom group for $lights")
191
188
]
192
192
-
print(f"DEBUG resolved groups={groups!r}")
193
189
194
194
-
print(f"DEBUG iterating over groups={groups!r}")
195
190
for group_name in groups:
196
196
-
print(f"DEBUG setting group_name={group_name!r}, type={type(group_name)}")
197
191
bridge.set_group(
198
192
group_name,
199
193
{"on": light_state.on, "bri": light_state.bri, "ct": light_state.ct},
···
204
198
def update(groups: list[str] | None = None) -> None:
205
199
"""main update - checks state, applies lights."""
206
200
external = load_state()
207
207
-
print(f"DEBUG update: external.groups={external.groups!r}, type={type(external.groups)}")
208
201
light_state, description = resolve_state(external)
209
202
target_groups = external.groups or groups
210
210
-
print(f"DEBUG update: target_groups={target_groups!r}, type={type(target_groups)}")
211
203
212
204
print(f"[{description}] bri={light_state.bri}, ct={light_state.ct}, on={light_state.on} | {target_groups}")
213
205
apply_state(light_state, target_groups)
+6
-1
src/solux/state.py
···
66
66
if datetime.now().astimezone() > expires:
67
67
return State() # expired - return to auto
68
68
69
69
+
# ensure groups is a list, not a string
70
70
+
groups = data.get("groups")
71
71
+
if isinstance(groups, str):
72
72
+
groups = [groups]
73
73
+
69
74
return State(
70
75
mode=Mode(data.get("mode", "auto")),
71
76
updated_at=data.get("updated_at", ""),
···
73
78
brightness=data.get("brightness"),
74
79
color_temp=data.get("color_temp"),
75
80
on=data.get("on"),
76
76
-
groups=data.get("groups"),
81
81
+
groups=groups,
77
82
expires_at=data.get("expires_at"),
78
83
metadata=data.get("metadata", {}),
79
84
)