mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Retry enphase_envoy setup later if the wrong device is found (#98882)
This commit is contained in:
parent
b854551c77
commit
b884dafa81
@ -6,6 +6,7 @@ from pyenphase import Envoy
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.httpx_client import get_async_client
|
from homeassistant.helpers.httpx_client import get_async_client
|
||||||
|
|
||||||
@ -24,6 +25,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
if not entry.unique_id:
|
if not entry.unique_id:
|
||||||
hass.config_entries.async_update_entry(entry, unique_id=envoy.serial_number)
|
hass.config_entries.async_update_entry(entry, unique_id=envoy.serial_number)
|
||||||
|
|
||||||
|
if entry.unique_id != envoy.serial_number:
|
||||||
|
# If the serial number of the device does not match the unique_id
|
||||||
|
# of the config entry, it likely means the DHCP lease has expired
|
||||||
|
# and the device has been assigned a new IP address. We need to
|
||||||
|
# wait for the next discovery to find the device at its new address
|
||||||
|
# and update the config entry so we do not mix up devices.
|
||||||
|
raise ConfigEntryNotReady(
|
||||||
|
f"Unexpected device found at {host}; expected {entry.unique_id}, "
|
||||||
|
f"found {envoy.serial_number}"
|
||||||
|
)
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user