From e61073150e0da8e076c2c8a1c00d2561ca41f535 Mon Sep 17 00:00:00 2001 From: jacobswe Date: Wed, 14 Feb 2024 11:42:52 -0500 Subject: [PATCH] Fix #1781: compact_items expects dict but sometimes passed list (#1862) * Fix #1781: compact_items expects dict but sometimes passed list * Make type checks guard clauses --- custom_components/mass/services.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/custom_components/mass/services.py b/custom_components/mass/services.py index 4e09413a..9d9c9a0f 100644 --- a/custom_components/mass/services.py +++ b/custom_components/mass/services.py @@ -59,6 +59,8 @@ def compact_item(item: dict[str, Any]) -> dict[str, Any]: item[key] = compact_item(value) elif isinstance(value, list): for subitem in value: + if not isinstance(subitem, dict): + continue compact_item(subitem) # item[key] = [compact_item(x) if isinstance(x, dict) else x for x in value] return item @@ -66,6 +68,8 @@ def compact_item(item: dict[str, Any]) -> dict[str, Any]: dict_result: dict[str, list[dict[str, Any]]] = result.to_dict() for media_type_key in dict_result: for item in dict_result[media_type_key]: + if not isinstance(item, dict): + continue compact_item(item) return dict_result