示例#1
0
def _setup_entry(opp: OpenPeerPower, entry: ConfigEntry):
    """Config entry set up in executor."""
    config = entry.data

    username = config[CONF_USERNAME]
    password = config[CONF_PASSWORD]
    client_id = config[CONF_CLIENT_ID]
    client_secret = config[CONF_CLIENT_SECRET]
    flume_token_full_path = opp.config.path(
        f"{BASE_TOKEN_FILENAME}-{username}")

    http_session = Session()

    try:
        flume_auth = FlumeAuth(
            username,
            password,
            client_id,
            client_secret,
            flume_token_file=flume_token_full_path,
            http_session=http_session,
        )
        flume_devices = FlumeDeviceList(flume_auth, http_session=http_session)
    except RequestException as ex:
        raise ConfigEntryNotReady from ex
    except Exception as ex:  # pylint: disable=broad-except
        raise ConfigEntryAuthFailed from ex

    return flume_auth, flume_devices, http_session
示例#2
0
def _validate_input(hass: core.HomeAssistant, data: dict,
                    clear_token_file: bool):
    """Validate in the executor."""
    flume_token_full_path = hass.config.path(
        f"{BASE_TOKEN_FILENAME}-{data[CONF_USERNAME]}")
    if clear_token_file and os.path.exists(flume_token_full_path):
        os.unlink(flume_token_full_path)

    return FlumeDeviceList(
        FlumeAuth(
            data[CONF_USERNAME],
            data[CONF_PASSWORD],
            data[CONF_CLIENT_ID],
            data[CONF_CLIENT_SECRET],
            flume_token_file=flume_token_full_path,
        ))