this repo has no description

defensive type checks for hue api responses

+7 -2
+7 -2
src/solux/controller.py
··· 172 all_groups = bridge.get_group() 173 if isinstance(all_groups, list): 174 # hue api returns errors as a list, e.g. [{"error": {"description": "..."}}] 175 - errors = [g.get("error", {}).get("description") for g in all_groups if "error" in g] 176 if errors: 177 raise RuntimeError(f"hue bridge error: {'; '.join(errors)}") 178 raise RuntimeError(f"unexpected response from bridge: {all_groups}") 179 groups = [ 180 info["name"] 181 for gid, info in all_groups.items() 182 - if info["name"] not in ("all", "Custom group for $lights") 183 ] 184 185 for group_name in groups:
··· 172 all_groups = bridge.get_group() 173 if isinstance(all_groups, list): 174 # hue api returns errors as a list, e.g. [{"error": {"description": "..."}}] 175 + errors = [] 176 + for item in all_groups: 177 + if isinstance(item, dict) and isinstance(item.get("error"), dict): 178 + errors.append(item["error"].get("description", str(item["error"]))) 179 if errors: 180 raise RuntimeError(f"hue bridge error: {'; '.join(errors)}") 181 raise RuntimeError(f"unexpected response from bridge: {all_groups}") 182 + if not isinstance(all_groups, dict): 183 + raise RuntimeError(f"unexpected response type from bridge: {type(all_groups)}: {all_groups}") 184 groups = [ 185 info["name"] 186 for gid, info in all_groups.items() 187 + if isinstance(info, dict) and info.get("name") not in ("all", "Custom group for $lights") 188 ] 189 190 for group_name in groups: