this repo has no description

defensive type checks for hue api responses

+7 -2
+7 -2
src/solux/controller.py
··· 172 172 all_groups = bridge.get_group() 173 173 if isinstance(all_groups, list): 174 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] 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"]))) 176 179 if errors: 177 180 raise RuntimeError(f"hue bridge error: {'; '.join(errors)}") 178 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}") 179 184 groups = [ 180 185 info["name"] 181 186 for gid, info in all_groups.items() 182 - if info["name"] not in ("all", "Custom group for $lights") 187 + if isinstance(info, dict) and info.get("name") not in ("all", "Custom group for $lights") 183 188 ] 184 189 185 190 for group_name in groups: