Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert disabled_by to DeviceEntryDisabler on load #63944

Merged
merged 7 commits into from Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/helpers/device_registry.py
Expand Up @@ -732,7 +732,7 @@ def async_config_entry_disabled_by_changed(

if not config_entry.disabled_by:
for device in devices:
if device.disabled_by is not DeviceEntryDisabler.CONFIG_ENTRY:
if device.disabled_by != DeviceEntryDisabler.CONFIG_ENTRY:
agners marked this conversation as resolved.
Show resolved Hide resolved
continue
registry.async_update_device(device.id, disabled_by=None)
return
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/helpers/entity_registry.py
Expand Up @@ -447,7 +447,7 @@ def async_device_modified(self, event: Event) -> None:
self.async_update_entity(entity.entity_id, disabled_by=None)
return

if device.disabled_by is dr.DeviceEntryDisabler.CONFIG_ENTRY:
if device.disabled_by == dr.DeviceEntryDisabler.CONFIG_ENTRY:
# Handled by async_config_entry_disabled
return

Expand Down
2 changes: 1 addition & 1 deletion tests/components/deconz/test_gateway.py
Expand Up @@ -176,7 +176,7 @@ async def test_gateway_setup(hass, aioclient_mock):
)

assert gateway_entry.configuration_url == f"http://{HOST}:{PORT}"
assert gateway_entry.entry_type is dr.DeviceEntryType.SERVICE
assert gateway_entry.entry_type == dr.DeviceEntryType.SERVICE


async def test_gateway_device_configuration_url_when_addon(hass, aioclient_mock):
Expand Down
2 changes: 1 addition & 1 deletion tests/components/picnic/test_sensor.py
Expand Up @@ -434,7 +434,7 @@ async def test_device_registry_entry(self):
)
assert picnic_service.model == DEFAULT_USER_RESPONSE["user_id"]
assert picnic_service.name == "Picnic: Commonstreet 123a"
assert picnic_service.entry_type is DeviceEntryType.SERVICE
assert picnic_service.entry_type == DeviceEntryType.SERVICE

async def test_auth_token_is_saved_on_update(self):
"""Test that auth-token changes in the session object are reflected by the config entry."""
Expand Down
14 changes: 7 additions & 7 deletions tests/helpers/test_device_registry.py
Expand Up @@ -217,8 +217,8 @@ async def test_loading_from_storage(hass, hass_storage):
assert entry.area_id == "12345A"
assert entry.name_by_user == "Test Friendly Name"
assert entry.hw_version == "hw_version"
assert entry.entry_type is device_registry.DeviceEntryType.SERVICE
assert entry.disabled_by is device_registry.DeviceEntryDisabler.USER
assert entry.entry_type == device_registry.DeviceEntryType.SERVICE
assert entry.disabled_by == device_registry.DeviceEntryDisabler.USER
assert isinstance(entry.config_entries, set)
assert isinstance(entry.connections, set)
assert isinstance(entry.identifiers, set)
Expand Down Expand Up @@ -913,7 +913,7 @@ async def test_update(registry):
assert updated_entry.name_by_user == "Test Friendly Name"
assert updated_entry.identifiers == new_identifiers
assert updated_entry.via_device_id == "98765B"
assert updated_entry.disabled_by is device_registry.DeviceEntryDisabler.USER
assert updated_entry.disabled_by == device_registry.DeviceEntryDisabler.USER

assert registry.async_get_device({("hue", "456")}) is None
assert registry.async_get_device({("bla", "123")}) is None
Expand Down Expand Up @@ -1508,10 +1508,10 @@ async def test_disable_config_entry_disables_devices(hass, registry):

entry1 = registry.async_get(entry1.id)
assert entry1.disabled
assert entry1.disabled_by is device_registry.DeviceEntryDisabler.CONFIG_ENTRY
assert entry1.disabled_by == device_registry.DeviceEntryDisabler.CONFIG_ENTRY
entry2 = registry.async_get(entry2.id)
assert entry2.disabled
assert entry2.disabled_by is device_registry.DeviceEntryDisabler.USER
assert entry2.disabled_by == device_registry.DeviceEntryDisabler.USER

await hass.config_entries.async_set_disabled_by(config_entry.entry_id, None)
await hass.async_block_till_done()
Expand All @@ -1520,7 +1520,7 @@ async def test_disable_config_entry_disables_devices(hass, registry):
assert not entry1.disabled
entry2 = registry.async_get(entry2.id)
assert entry2.disabled
assert entry2.disabled_by is device_registry.DeviceEntryDisabler.USER
assert entry2.disabled_by == device_registry.DeviceEntryDisabler.USER


async def test_only_disable_device_if_all_config_entries_are_disabled(hass, registry):
Expand Down Expand Up @@ -1556,7 +1556,7 @@ async def test_only_disable_device_if_all_config_entries_are_disabled(hass, regi

entry1 = registry.async_get(entry1.id)
assert entry1.disabled
assert entry1.disabled_by is device_registry.DeviceEntryDisabler.CONFIG_ENTRY
assert entry1.disabled_by == device_registry.DeviceEntryDisabler.CONFIG_ENTRY

await hass.config_entries.async_set_disabled_by(config_entry1.entry_id, None)
await hass.async_block_till_done()
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/test_entity_platform.py
Expand Up @@ -864,7 +864,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
assert device.identifiers == {("hue", "1234")}
assert device.configuration_url == "http://192.168.0.100/config"
assert device.connections == {(dr.CONNECTION_NETWORK_MAC, "abcd")}
assert device.entry_type is dr.DeviceEntryType.SERVICE
assert device.entry_type == dr.DeviceEntryType.SERVICE
assert device.manufacturer == "test-manuf"
assert device.model == "test-model"
assert device.name == "test-name"
Expand Down