Пример #1
0
async def validate_input(hass, host, port):
    """Validate the user input allows us to connect."""
    volumio = Volumio(host, port, async_get_clientsession(hass))

    try:
        return await volumio.get_system_info()
    except CannotConnectError as error:
        raise CannotConnect from error
Пример #2
0
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up Volumio from a config entry."""

    volumio = Volumio(entry.data[CONF_HOST], entry.data[CONF_PORT],
                      async_get_clientsession(hass))
    try:
        info = await volumio.get_system_version()
    except CannotConnectError as error:
        raise ConfigEntryNotReady from error

    hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
        DATA_VOLUMIO: volumio,
        DATA_INFO: info,
    }

    await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

    return True
Пример #3
0
async def async_setup_entry(opp: OpenPeerPower, entry: ConfigEntry):
    """Set up Volumio from a config entry."""

    volumio = Volumio(entry.data[CONF_HOST], entry.data[CONF_PORT],
                      async_get_clientsession(opp))
    try:
        info = await volumio.get_system_version()
    except CannotConnectError as error:
        raise ConfigEntryNotReady from error

    opp.data.setdefault(DOMAIN, {})[entry.entry_id] = {
        DATA_VOLUMIO: volumio,
        DATA_INFO: info,
    }

    opp.config_entries.async_setup_platforms(entry, PLATFORMS)

    return True