mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
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
This commit is contained in:
parent
5dccd8204c
commit
4174d88ad7
@ -3,7 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from collections.abc import Callable, Iterable, Sequence
|
from collections.abc import Callable, Hashable, Iterable, Sequence
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
@ -1415,7 +1415,7 @@ def extract_platform_integrations(
|
|||||||
platform = item.get(CONF_PLATFORM)
|
platform = item.get(CONF_PLATFORM)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
continue
|
continue
|
||||||
if platform:
|
if platform and isinstance(platform, Hashable):
|
||||||
platform_integrations.setdefault(domain, set()).add(platform)
|
platform_integrations.setdefault(domain, set()).add(platform)
|
||||||
return platform_integrations
|
return platform_integrations
|
||||||
|
|
||||||
|
@ -2348,6 +2348,7 @@ def test_extract_platform_integrations() -> None:
|
|||||||
[
|
[
|
||||||
(b"zone", {"platform": "not str"}),
|
(b"zone", {"platform": "not str"}),
|
||||||
("zone", {"platform": "hello"}),
|
("zone", {"platform": "hello"}),
|
||||||
|
("switch", {"platform": ["un", "hash", "able"]}),
|
||||||
("zonex", []),
|
("zonex", []),
|
||||||
("zoney", ""),
|
("zoney", ""),
|
||||||
("notzone", {"platform": "nothello"}),
|
("notzone", {"platform": "nothello"}),
|
||||||
@ -2363,6 +2364,7 @@ def test_extract_platform_integrations() -> None:
|
|||||||
assert config_util.extract_platform_integrations(config, {"zone"}) == {
|
assert config_util.extract_platform_integrations(config, {"zone"}) == {
|
||||||
"zone": {"hello", "hello 2"}
|
"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, {"zonex"}) == {}
|
||||||
assert config_util.extract_platform_integrations(config, {"zoney"}) == {}
|
assert config_util.extract_platform_integrations(config, {"zoney"}) == {}
|
||||||
assert config_util.extract_platform_integrations(
|
assert config_util.extract_platform_integrations(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user