···172172 all_groups = bridge.get_group()
173173 if isinstance(all_groups, list):
174174 # hue api returns errors as a list, e.g. [{"error": {"description": "..."}}]
175175- errors = [g.get("error", {}).get("description") for g in all_groups if "error" in g]
175175+ errors = []
176176+ for item in all_groups:
177177+ if isinstance(item, dict) and isinstance(item.get("error"), dict):
178178+ errors.append(item["error"].get("description", str(item["error"])))
176179 if errors:
177180 raise RuntimeError(f"hue bridge error: {'; '.join(errors)}")
178181 raise RuntimeError(f"unexpected response from bridge: {all_groups}")
182182+ if not isinstance(all_groups, dict):
183183+ raise RuntimeError(f"unexpected response type from bridge: {type(all_groups)}: {all_groups}")
179184 groups = [
180185 info["name"]
181186 for gid, info in all_groups.items()
182182- if info["name"] not in ("all", "Custom group for $lights")
187187+ if isinstance(info, dict) and info.get("name") not in ("all", "Custom group for $lights")
183188 ]
184189185190 for group_name in groups: