mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Prevent the wrong WiZ device from being used when the IP is a different device (#67250)
This commit is contained in:
parent
99bc2a7c9e
commit
e81ca64aa4
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user