Skip to content

Commit

Permalink
refactor: change backoff behavior to commands only
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Feb 11, 2020
1 parent c0907b2 commit 383ce46
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions teslajsonpy/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ def valid_result(result):

retries = 0
sleep_delay = 2
instance = args[0]
car_id = args[1]
is_wake_command = len(args) >= 3 and args[2] == "wake_up"
car_id = args[0]
is_wake_command = len(args) >= 2 and args[1] == "wake_up"
result = None
if instance.car_online.get(instance._id_to_vin(car_id)) or is_wake_command:
try:
Expand Down Expand Up @@ -348,7 +347,6 @@ async def get_vehicles(self):
"""Get vehicles json from TeslaAPI."""
return (await self.__connection.get("vehicles"))["response"]

@backoff.on_exception(min_expo, TeslaException, max_time=120, logger=__name__, min_value=15)
@wake_up
async def post(self, car_id, command, data=None, wake_if_asleep=True):
# pylint: disable=unused-argument
Expand Down Expand Up @@ -380,7 +378,6 @@ async def post(self, car_id, command, data=None, wake_if_asleep=True):
data = data or {}
return await self.__connection.post(f"vehicles/{car_id}/{command}", data=data)

@backoff.on_exception(min_expo, TeslaException, max_time=120, logger=__name__, min_value=15)
@wake_up
async def get(self, car_id, command, wake_if_asleep=False):
# pylint: disable=unused-argument
Expand Down Expand Up @@ -439,6 +436,7 @@ async def data_request(self, car_id, name, wake_if_asleep=False):
)
)["response"]

@backoff.on_exception(min_expo, TeslaException, max_time=60, logger=__name__, min_value=15)
async def command(self, car_id, name, data=None, wake_if_asleep=True):
"""Post name command to the car_id.
Expand Down

0 comments on commit 383ce46

Please sign in to comment.