Skip to content

Commit

Permalink
Handle 429 on wake
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeBishop committed May 15, 2024
1 parent 6bebc7b commit d58a954
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/TWCManager/Vehicle/TeslaAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,8 +1235,16 @@ def wakeVehicle(self, vehicle):
try:
req = requests.post(url, headers=headers, verify=self.verifyCert)
logger.log(logging.INFO8, "Car API cmd wake_up" + str(req))
req.raise_for_status()
apiResponseDict = json.loads(req.text)
except requests.exceptions.RequestException:
if req.status_code == 401 and "expired" in req.text:
# If the token is expired, refresh it and try again
self.apiRefresh()
return self.wakeVehicle(vehicle)
elif req.status_code == 429:
# We're explicitly being told to back off
self.errorCount = max(30, self.errorCount)
return False
except json.decoder.JSONDecodeError:
return False
Expand Down

0 comments on commit d58a954

Please sign in to comment.