Skip to content

Commit

Permalink
Adds catch exception when loads devices
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 26, 2022
1 parent 95fdc7c commit d688c16
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions custom_components/sonoff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,20 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):


async def internal_normal_setup(hass: HomeAssistant, entry: ConfigEntry):
registry: XRegistry = hass.data[DOMAIN][entry.entry_id]
if registry.cloud.auth:
homes = entry.options.get("homes")
devices = await registry.cloud.get_devices(homes)
_LOGGER.debug(f"{len(devices)} devices loaded from Cloud")
devices = None

store = Store(hass, 1, f"{DOMAIN}/{entry.data['username']}.json")
await store.async_save(devices)
else:
devices = None
try:
registry: XRegistry = hass.data[DOMAIN][entry.entry_id]
if registry.cloud.auth:
homes = entry.options.get("homes")
devices = await registry.cloud.get_devices(homes)
_LOGGER.debug(f"{len(devices)} devices loaded from Cloud")

store = Store(hass, 1, f"{DOMAIN}/{entry.data['username']}.json")
await store.async_save(devices)

except Exception as e:
_LOGGER.warning("Can't load devices", exc_info=e)

await internal_cache_setup(hass, entry, devices)

Expand Down

0 comments on commit d688c16

Please sign in to comment.