Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stopAskingToStartCharging behaviour #589

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions lib/TWCManager/TWCSlave.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,20 +543,6 @@ def send_master_heartbeat(self):
# Car is not charging and is not reporting an error state, so
# try starting charge via car api.
self.master.startCarsCharging()
elif self.reportedAmpsActual >= 1.0:
# At least one plugged in car is successfully charging. We don't
# know which car it is, so we must set
# vehicle.stopAskingToStartCharging = False on all vehicles such
# that if any vehicle is not charging without us calling
# car_api_charge(False), we'll try to start it charging again at
# least once. This probably isn't necessary but might prevent
# some unexpected case from never starting a charge. It also
# seems less confusing to see in the output that we always try
# to start API charging after the car stops taking a charge.
for vehicle in self.master.getModuleByName(
"TeslaAPI"
).getCarApiVehicles():
vehicle.stopAskingToStartCharging = False

self.master.getModulesByType("Interface")[0]["ref"].send(
bytearray(b"\xFB\xE0")
Expand Down
13 changes: 10 additions & 3 deletions lib/TWCManager/Vehicle/TeslaAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,17 @@ def car_api_charge(self, charge):

if not vehicle.atHome:
# Vehicle is not at home, so don't change its charge state.
logger.info(
message = (
vehicle.name
+ " is not at home. Do not "
+ startOrStop
+ " charge."
)
# Stop asking to start charging when not at home.
if startOrStop == "start":
vehicle.stopAskingToStartCharging = True
message += " Stop asking to start charging."
logger.info(message)
continue

# If you send charge_start/stop less than 1 second after calling
Expand Down Expand Up @@ -1264,6 +1269,7 @@ def wakeVehicle(self, vehicle):
elif req.status_code == 429:
# We're explicitly being told to back off
self.errorCount = max(30, self.errorCount)
RichieB2B marked this conversation as resolved.
Show resolved Hide resolved
self.updateCarApiLastErrorTime(vehicle)
return False
except json.decoder.JSONDecodeError:
return False
Expand Down Expand Up @@ -1435,6 +1441,7 @@ def get_car_api(self, url, checkReady=True, provesOnline=True):
elif req.status_code == 429:
# We're explicitly being told to back off
self.errorCount = max(30, self.errorCount)
self.carapi.updateCarApiLastErrorTime(self)
return False, None
except json.decoder.JSONDecodeError:
pass
Expand Down Expand Up @@ -1474,7 +1481,7 @@ def get_car_api(self, url, checkReady=True, provesOnline=True):
self.carapi.updateCarApiLastErrorTime(self)
return (False, None)

def update_location(self, cacheTime=60):
def update_location(self, cacheTime=300):
if self.syncSource == "TeslaAPI":
return self.update_vehicle_data(cacheTime)

Expand All @@ -1485,7 +1492,7 @@ def update_location(self, cacheTime=60):

return True

def update_vehicle_data(self, cacheTime=60):
def update_vehicle_data(self, cacheTime=300):
url = (
"/".join([self.carapi.getCarApiBaseURL(), str(self.VIN), "vehicle_data"])
+ "?endpoints="
Expand Down
Loading