Prevent the wrong WiZ device from being used when the IP is a different device (#67250)

This commit is contained in:
J. Nick Koston 2022-02-25 09:37:19 -10:00 committed by GitHub
parent 99bc2a7c9e
commit e81ca64aa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -60,6 +60,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await bulb.async_close()
raise ConfigEntryNotReady(f"{ip_address}: {err}") from err
if bulb.mac != entry.unique_id:
# The ip address of the bulb has changed and its likely offline
# and another WiZ device has taken the IP. Avoid setting up
# since its the wrong device. As soon as the device comes back
# online the ip will get updated and setup will proceed.
raise ConfigEntryNotReady(
"Found bulb {bulb.mac} at {ip_address}, expected {entry.unique_id}"
)
async def _async_update() -> None:
"""Update the WiZ device."""
try:

View File

@ -50,3 +50,11 @@ async def test_cleanup_on_failed_first_update(hass: HomeAssistant) -> None:
_, entry = await async_setup_integration(hass, wizlight=bulb)
assert entry.state == config_entries.ConfigEntryState.SETUP_RETRY
bulb.async_close.assert_called_once()
async def test_wrong_device_now_has_our_ip(hass: HomeAssistant) -> None:
"""Test setup is retried when the wrong device is found."""
bulb = _mocked_wizlight(None, None, FAKE_SOCKET)
bulb.mac = "dddddddddddd"
_, entry = await async_setup_integration(hass, wizlight=bulb)
assert entry.state == config_entries.ConfigEntryState.SETUP_RETRY