Skip to content

Commit

Permalink
Setup: rethrow exceptions as ConfigEntryNotReady
Browse files Browse the repository at this point in the history
For Home Assistant to retry setup, exceptions thrown from
async_entry_setup need to be a specific exception class.

This is required to handle devices that are offline at the time
Home Assistant boots (eg, HA comes up before the WiFi router
after a power outage, or a device gets switched off at the wall, and
turned on after HA is up).

Issue #1683
  • Loading branch information
make-all committed Feb 27, 2024
1 parent c171e19 commit 4adb7d4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion custom_components/tuya_local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
get_device_id(entry.data),
)
config = {**entry.data, **entry.options, "name": entry.title}
setup_device(hass, config)
try:
setup_device(hass, config)
except Exception as e:
raise ConfigEntryNotReady("tuya-local device not ready") from e

Check failure on line 317 in custom_components/tuya_local/__init__.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F821)

custom_components/tuya_local/__init__.py:317:15: F821 Undefined name `ConfigEntryNotReady`

device_conf = get_config(entry.data[CONF_TYPE])
if device_conf is None:
_LOGGER.error(NOT_FOUND, config[CONF_TYPE])
Expand Down

0 comments on commit 4adb7d4

Please sign in to comment.