From 4174d88ad757ffc7aa360f30f7237b7c6922052d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 16 Mar 2024 10:19:07 -1000 Subject: [PATCH] Add a guard to handle unhashable platforms in config (#113607) Someone might set the platform to [fitbit] instead of fitbit I have not seen anyone do this, but its good to guard against it --- homeassistant/config.py | 4 ++-- tests/test_config.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/config.py b/homeassistant/config.py index a95da351a54..f536b2b2913 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections import OrderedDict -from collections.abc import Callable, Iterable, Sequence +from collections.abc import Callable, Hashable, Iterable, Sequence from contextlib import suppress from dataclasses import dataclass from enum import StrEnum @@ -1415,7 +1415,7 @@ def extract_platform_integrations( platform = item.get(CONF_PLATFORM) except AttributeError: continue - if platform: + if platform and isinstance(platform, Hashable): platform_integrations.setdefault(domain, set()).add(platform) return platform_integrations diff --git a/tests/test_config.py b/tests/test_config.py index af4b653e4f6..9d1cb9e3ce7 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -2348,6 +2348,7 @@ def test_extract_platform_integrations() -> None: [ (b"zone", {"platform": "not str"}), ("zone", {"platform": "hello"}), + ("switch", {"platform": ["un", "hash", "able"]}), ("zonex", []), ("zoney", ""), ("notzone", {"platform": "nothello"}), @@ -2363,6 +2364,7 @@ def test_extract_platform_integrations() -> None: assert config_util.extract_platform_integrations(config, {"zone"}) == { "zone": {"hello", "hello 2"} } + assert config_util.extract_platform_integrations(config, {"switch"}) == {} assert config_util.extract_platform_integrations(config, {"zonex"}) == {} assert config_util.extract_platform_integrations(config, {"zoney"}) == {} assert config_util.extract_platform_integrations(