Beispiel #1
0
 def get_thermostat(self, location_id, device_id) -> Response:
     url = self._url(f'devices/thermostats/{device_id}')
     token = self._get_auth_token().json()["access_token"]
     headers = {'Authorization': f'Bearer {token}'}
     params = {
         'apikey': self.client_id,
         'locationId': location_id
     }
     return requests_retry_session().get(url, headers=headers, params=params)
Beispiel #2
0
 def _get_auth_token(self) -> Response:
     resp = requests_retry_session().post(
             self.TOKEN_URL,
             auth=HTTPBasicAuth(self.client_id, self.client_secret),
             data={
                 'grant_type': 'refresh_token',
                 'refresh_token': self.refresh_token
             }
     )
     return resp
Beispiel #3
0
    def change_thermostat(self, location_id, device_id, **kwargs) -> Response:
        # get the current state
        result = self.get_thermostat(location_id=location_id, device_id=device_id).json()
        changeable_values = result['changeableValues']

        # update dictionary with new parameters
        for k, v in kwargs.items():
            if k in changeable_values:
                changeable_values[k] = v
            else:
                raise ValueError("Unknown parameter: '{}'".format(k))

        # update device
        url = self._url(f'devices/thermostats/{device_id}')
        token = self._get_auth_token().json()["access_token"]
        headers = {'Authorization': f'Bearer {token}', 'Content-Type': 'application/json'}
        params = {
            'apikey': self.client_id,
            'locationId': location_id
        }
        data = json.dumps(changeable_values)
        return requests_retry_session().post(url, headers=headers, params=params, data=data)
Beispiel #4
0
 def get_variable(self, device_id, variable_name) -> Response:
     headers = {'Authorization': f'Bearer {self.auth_token}'}
     return requests_retry_session().get(
         self._url(f'{device_id}/{variable_name}'), headers=headers)
Beispiel #5
0
 def get_device_information(self, device_id) -> Response:
     headers = {'Authorization': f'Bearer {self.auth_token}'}
     return requests_retry_session().get(self._url(f'{device_id}'),
                                         headers=headers)
Beispiel #6
0
 def get_locations(self) -> Response:
     url = self._url('locations')
     token = self._get_auth_token().json()["access_token"]
     headers = {'Authorization': f'Bearer {token}'}
     params = {'apikey': self.client_id}
     return requests_retry_session().get(url, headers=headers, params=params)