def _update_headers(self): """Get the access token from automatic.""" if self._headers is None or self._token_expires <= dt_util.now(): resp = requests.post(URL_AUTHORIZE, data=self._access_token_payload) resp.raise_for_status() json = resp.json() access_token = json[ATTR_ACCESS_TOKEN] self._token_expires = dt_util.now() + timedelta(seconds=json[ATTR_EXPIRES_IN]) self._headers = {"Authorization": "Bearer {}".format(access_token)}
def _update_headers(self): """Get the access token from automatic.""" if self._headers is None or self._token_expires <= dt_util.now(): resp = requests.post(URL_AUTHORIZE, data=self._access_token_payload) resp.raise_for_status() json = resp.json() access_token = json[ATTR_ACCESS_TOKEN] self._token_expires = dt_util.now() + timedelta( seconds=json[ATTR_EXPIRES_IN]) self._headers = {'Authorization': 'Bearer {}'.format(access_token)}
def __init__(self, config: dict, see) -> None: """Initialize the automatic device scanner.""" self._devices = config.get(CONF_DEVICES, None) self._access_token_payload = { 'username': config.get(CONF_USERNAME), 'password': config.get(CONF_PASSWORD), 'client_id': config.get(CONF_CLIENT_ID), 'client_secret': config.get(CONF_SECRET), 'grant_type': 'password', 'scope': SCOPE } self._headers = None self._token_expires = dt_util.now() self.last_results = {} self.last_trips = {} self.see = see self.scan_devices()
def __init__(self, hass, config: dict, see) -> None: """Initialize the automatic device scanner.""" self.hass = hass self._devices = config.get(CONF_DEVICES, None) self._access_token_payload = { "username": config.get(CONF_USERNAME), "password": config.get(CONF_PASSWORD), "client_id": config.get(CONF_CLIENT_ID), "client_secret": config.get(CONF_SECRET), "grant_type": "password", "scope": SCOPE, } self._headers = None self._token_expires = dt_util.now() self.last_results = {} self.last_trips = {} self.see = see self._update_info() track_utc_time_change(self.hass, self._update_info, second=range(0, 60, 30))
def __init__(self, hass, config: dict, see) -> None: """Initialize the automatic device scanner.""" self.hass = hass self._devices = config.get(CONF_DEVICES, None) self._access_token_payload = { 'username': config.get(CONF_USERNAME), 'password': config.get(CONF_PASSWORD), 'client_id': config.get(CONF_CLIENT_ID), 'client_secret': config.get(CONF_SECRET), 'grant_type': 'password', 'scope': SCOPE } self._headers = None self._token_expires = dt_util.now() self.last_results = {} self.last_trips = {} self.see = see self._update_info() track_utc_time_change(self.hass, self._update_info, second=list(range(0, 60, 30)))