How to use the wled.WLEDConnectionError function in wled

To help you get started, we’ve selected a few wled examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github home-assistant / home-assistant / homeassistant / components / wled / __init__.py View on Github external
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up WLED from a config entry."""

    # Create WLED instance for this entry
    session = async_get_clientsession(hass)
    wled = WLED(entry.data[CONF_HOST], loop=hass.loop, session=session)

    # Ensure we can connect and talk to it
    try:
        await wled.update()
    except WLEDConnectionError as exception:
        raise ConfigEntryNotReady from exception

    hass.data.setdefault(DOMAIN, {})
    hass.data[DOMAIN][entry.entry_id] = {DATA_WLED_CLIENT: wled}

    # Set up all platforms for this device/entry.
    for component in WLED_COMPONENTS:
        hass.async_create_task(
            hass.config_entries.async_forward_entry_setup(entry, component)
        )

    async def interval_update(now: dt_util.dt.datetime = None) -> None:
        """Poll WLED device function, dispatches event after update."""
        try:
            await wled.update()
        except WLEDError:
github home-assistant / home-assistant / homeassistant / components / wled / config_flow.py View on Github external
if user_input is None and not prepare:
            if source == SOURCE_ZEROCONF:
                return self._show_confirm_dialog()
            return self._show_setup_form()

        if source == SOURCE_ZEROCONF:
            # pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
            user_input[CONF_HOST] = self.context.get(CONF_HOST)

        errors = {}
        session = async_get_clientsession(self.hass)
        wled = WLED(user_input[CONF_HOST], loop=self.hass.loop, session=session)

        try:
            device = await wled.update()
        except WLEDConnectionError:
            if source == SOURCE_ZEROCONF:
                return self.async_abort(reason="connection_error")
            errors["base"] = "connection_error"
            return self._show_setup_form(errors)

        # Check if already configured
        mac_address = device.info.mac_address
        for entry in self._async_current_entries():
            if entry.data[CONF_MAC] == mac_address:
                # This mac address is already configured
                return self.async_abort(reason="already_configured")

        title = user_input[CONF_HOST]
        if source == SOURCE_ZEROCONF:
            # pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
            title = self.context.get(CONF_NAME)