Retry rainmachine setup later if the wrong device is found (#98888)

pull/98915/head
J. Nick Koston 2023-08-23 14:21:18 -05:00 committed by GitHub
parent 4aa7fb0e35
commit e1db3ecf52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 1 deletions

View File

@ -219,10 +219,11 @@ async def async_setup_entry( # noqa: C901
"""Set up RainMachine as config entry."""
websession = aiohttp_client.async_get_clientsession(hass)
client = Client(session=websession)
ip_address = entry.data[CONF_IP_ADDRESS]
try:
await client.load_local(
entry.data[CONF_IP_ADDRESS],
ip_address,
entry.data[CONF_PASSWORD],
port=entry.data[CONF_PORT],
use_ssl=entry.data.get(CONF_SSL, DEFAULT_SSL),
@ -238,6 +239,7 @@ async def async_setup_entry( # noqa: C901
if not entry.unique_id or is_ip_address(entry.unique_id):
# If the config entry doesn't already have a unique ID, set one:
entry_updates["unique_id"] = controller.mac
if CONF_DEFAULT_ZONE_RUN_TIME in entry.data:
# If a zone run time exists in the config entry's data, pop it and move it to
# options:
@ -252,6 +254,17 @@ async def async_setup_entry( # noqa: C901
if entry_updates:
hass.config_entries.async_update_entry(entry, **entry_updates)
if entry.unique_id and controller.mac != entry.unique_id:
# If the mac address 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 {ip_address}; expected {entry.unique_id}, "
f"found {controller.mac}"
)
async def async_update(api_category: str) -> dict:
"""Update the appropriate API data based on a category."""
data: dict = {}