Skip to content

Commit

Permalink
fix: add retry to get_vehicles
Browse files Browse the repository at this point in the history
get_vehicles is the first command used by the controller. In case of a
transient connection error, it will retry for up to 10 seconds.
  • Loading branch information
alandtse committed May 31, 2020
1 parent 62a4bd9 commit 1b6660d
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions teslajsonpy/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import backoff
import wrapt
from aiohttp import ClientConnectorError

from teslajsonpy.battery_sensor import Battery, Range
from teslajsonpy.binary_sensor import (
Expand Down Expand Up @@ -344,6 +345,7 @@ def register_websocket_callback(self, callback) -> int:
self.__websocket_listeners.append(callback)
return len(self.__websocket_listeners) - 1

@backoff.on_exception(min_expo, ClientConnectorError, max_time=10, logger=__name__)
async def get_vehicles(self):
"""Get vehicles json from TeslaAPI."""
return (await self.__connection.get("vehicles"))["response"]
Expand Down

0 comments on commit 1b6660d

Please sign in to comment.