Skip to content

Commit

Permalink
Supports when IP address change is detected during setup (rel #144)
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Oct 18, 2023
1 parent 3ff4ce4 commit 8ee0028
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions custom_components/echonetlite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,20 @@ def unload_config_entry():

echonetlite = ECHONETConnector(instance, hass.data[DOMAIN]["api"], entry)
try:
await asyncio.wait_for(echonetlite.async_update(), timeout=20)
await asyncio.wait_for(
echonetlite.async_update(), timeout=60
) # 20 secs * retry 3 times = 60
hass.data[DOMAIN][entry.entry_id].append(
{"instance": instance, "echonetlite": echonetlite}
)
except asyncio.exceptions.TimeoutError as ex:
except (asyncio.TimeoutError, asyncio.CancelledError) as ex:
raise ConfigEntryNotReady(
f"Connection error while connecting to {host}: {ex}"
) from ex
except KeyError as ex:
raise ConfigEntryNotReady(
f"IP address change was detected during setup of {host}"
) from ex

_LOGGER.debug(f"Plaform entry data - {entry.data}")

Expand Down
2 changes: 1 addition & 1 deletion custom_components/echonetlite/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async def validate_input(
_LOGGER.info(f"ECHONET registed node IP hanged from {old_host} to {host}.")
_LOGGER.info(f"New instances data is {instances}")
if server._state.get(old_host):
server._state.pop(old_host)
server._state[host] = server._state.pop(old_host)
hass.config_entries.async_update_entry(
config_entry, data={"instances": instances}
)
Expand Down

0 comments on commit 8ee0028

Please sign in to comment.