Skip to content

Commit

Permalink
Convert disabled_by to DeviceEntryDisabler on load (#63944)
Browse files Browse the repository at this point in the history
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
  • Loading branch information
agners and balloob committed Jan 12, 2022
1 parent bdea7fa commit 42706f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion homeassistant/helpers/device_registry.py
Expand Up @@ -553,7 +553,9 @@ async def async_load(self) -> None:
configuration_url=device["configuration_url"],
# type ignores (if tuple arg was cast): likely https://github.com/python/mypy/issues/8625
connections={tuple(conn) for conn in device["connections"]}, # type: ignore[misc]
disabled_by=device["disabled_by"],
disabled_by=DeviceEntryDisabler(device["disabled_by"])
if device["disabled_by"]
else None,
entry_type=DeviceEntryType(device["entry_type"])
if device["entry_type"]
else None,
Expand Down
10 changes: 10 additions & 0 deletions tests/helpers/test_device_registry.py
Expand Up @@ -782,6 +782,7 @@ async def test_loading_saving_data(hass, registry, area_registry):
identifiers={("hue", "abc")},
manufacturer="manufacturer",
model="light",
entry_type=device_registry.DeviceEntryType.SERVICE,
)

assert orig_light4.id == orig_light3.id
Expand Down Expand Up @@ -821,6 +822,15 @@ async def test_loading_saving_data(hass, registry, area_registry):
assert orig_light == new_light
assert orig_light4 == new_light4

# Ensure enums converted
for (old, new) in (
(orig_via, new_via),
(orig_light, new_light),
(orig_light4, new_light4),
):
assert old.disabled_by is new.disabled_by
assert old.entry_type is new.entry_type

# Ensure a save/load cycle does not keep suggested area
new_kitchen_light = registry2.async_get_device({("hue", "999")})
assert orig_kitchen_light.suggested_area == "Kitchen"
Expand Down

0 comments on commit 42706f7

Please sign in to comment.