mirror of
https://github.com/USA-RedDragon/badnest.git
synced 2025-01-18 18:40:42 +00:00
Merge pull request #23 from USA-RedDragon/api-fix-token-expiration
API: Handle KeyError to fix the expiration of tokens
This commit is contained in:
commit
4a6c88a6ef
@ -126,7 +126,10 @@ class NestThermostatAPI(NestAPI):
|
||||
return devices
|
||||
except requests.exceptions.RequestException as e:
|
||||
_LOGGER.error(e)
|
||||
_LOGGER.error('Failed to get devices, trying to log in again')
|
||||
_LOGGER.error('Failed to get devices, trying again')
|
||||
return self.get_devices()
|
||||
except KeyError:
|
||||
_LOGGER.debug('Failed to get devices, trying to log in again')
|
||||
self.login()
|
||||
return self.get_devices()
|
||||
|
||||
@ -193,7 +196,10 @@ class NestThermostatAPI(NestAPI):
|
||||
self.mode = temp_mode
|
||||
except requests.exceptions.RequestException as e:
|
||||
_LOGGER.error(e)
|
||||
_LOGGER.error('Failed to update, trying to log in again')
|
||||
_LOGGER.error('Failed to update, trying again')
|
||||
self.update()
|
||||
except KeyError:
|
||||
_LOGGER.debug('Failed to update, trying to log in again')
|
||||
self.login()
|
||||
self.update()
|
||||
|
||||
@ -297,6 +303,7 @@ class NestTemperatureSensorAPI(NestAPI):
|
||||
self.update()
|
||||
|
||||
def get_devices(self):
|
||||
try:
|
||||
r = self._session.post(
|
||||
f"{API_URL}/api/0.1/user/{self._user_id}/app_launch",
|
||||
json={
|
||||
@ -312,8 +319,17 @@ class NestTemperatureSensorAPI(NestAPI):
|
||||
devices.append(bucket.replace('kryptonite.', ''))
|
||||
|
||||
return devices
|
||||
except requests.exceptions.RequestException as e:
|
||||
_LOGGER.error(e)
|
||||
_LOGGER.error('Failed to get devices, trying again')
|
||||
return self.get_devices()
|
||||
except KeyError:
|
||||
_LOGGER.debug('Failed to get devices, trying to log in again')
|
||||
self.login()
|
||||
return self.get_devices()
|
||||
|
||||
def update(self):
|
||||
try:
|
||||
r = self._session.post(
|
||||
f"{API_URL}/api/0.1/user/{self._user_id}/app_launch",
|
||||
json={
|
||||
@ -329,6 +345,14 @@ class NestTemperatureSensorAPI(NestAPI):
|
||||
sensor_data = bucket["value"]
|
||||
self.temperature = sensor_data["current_temperature"]
|
||||
self.battery_level = sensor_data["battery_level"]
|
||||
except requests.exceptions.RequestException as e:
|
||||
_LOGGER.error(e)
|
||||
_LOGGER.error('Failed to update, trying again')
|
||||
self.update()
|
||||
except KeyError:
|
||||
_LOGGER.debug('Failed to update, trying to log in again')
|
||||
self.login()
|
||||
self.update()
|
||||
|
||||
|
||||
class NestCameraAPI(NestAPI):
|
||||
|
Loading…
x
Reference in New Issue
Block a user