Skip to content

Commit

Permalink
Add: Reload integration on connection failure
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajNyiri committed Dec 12, 2023
1 parent 4885759 commit 32fe97c
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions custom_components/lights_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,23 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

async def async_update_data():
LOGGER.debug("async_update_data - entry")
await sendCommand(
hass.data[DOMAIN][entry.entry_id],
hass.data[DOMAIN][entry.entry_id]["connection"]["client"],
hass.data[DOMAIN][entry.entry_id]["connection"]["service"],
getLightStateCommand(),
)
await sendCommand(
hass.data[DOMAIN][entry.entry_id],
hass.data[DOMAIN][entry.entry_id]["connection"]["client"],
hass.data[DOMAIN][entry.entry_id]["connection"]["service"],
getModeStateCommand(),
)

if not hass.data[DOMAIN][entry.entry_id]["connection"]["connected"]:
LOGGER.debug("Not connected, reconnecting...")
await setupConnection(hass, address, entry)
LOGGER.debug("Not connected, reloading...")
await hass.config_entries.async_reload(entry.entry_id)
else:
await sendCommand(
hass.data[DOMAIN][entry.entry_id],
hass.data[DOMAIN][entry.entry_id]["connection"]["client"],
hass.data[DOMAIN][entry.entry_id]["connection"]["service"],
getLightStateCommand(),
)
await sendCommand(
hass.data[DOMAIN][entry.entry_id],
hass.data[DOMAIN][entry.entry_id]["connection"]["client"],
hass.data[DOMAIN][entry.entry_id]["connection"]["service"],
getModeStateCommand(),
)

lightsAppCoordinator = DataUpdateCoordinator(
hass,
Expand Down

0 comments on commit 32fe97c

Please sign in to comment.