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

Improvements around location use #306

Open
wants to merge 5 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
4 changes: 4 additions & 0 deletions lib/TWCManager/TWCMaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,10 @@ def recordVehicleVIN(self, slaveTWC):
},
)

# If vehicle is charging, it's at home no matter what we previously thought.
self.getModuleByName("TeslaAPI").vehicleIsDefinitelyHome(slaveTWC.currentVIN)


def releaseBackgroundTasksLock(self):
self.backgroundTasksLock.release()

Expand Down
28 changes: 27 additions & 1 deletion lib/TWCManager/Vehicle/TeslaAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def car_api_charge(self, charge):
# When multiple cars are enrolled in the car API, only start/stop
# charging cars parked at home.

if vehicle.update_location() is False:
if vehicle.update_location(3600) is False:
result = "error"
continue

Expand Down Expand Up @@ -1149,6 +1149,32 @@ def updateChargeAtHome(self):
car.update_charge()
self.lastChargeCheck = time.time()

def vehicleIsDefinitelyHome(self, vin):
for car in self.carApiVehicles:
if car.VIN == vin:
if not car.atHome:
updated = car.update_location(0)
if updated and not car.atHome:
logger.log(
logging.INFO2,
car.name
+ " was connected to a TWC, so is definitely home."
)
logger.log(
logging.INFO2,
+ "Resetting home location to ("
+ str(car.lat)
+ ", "
+ str(car.lon)
+ ")",
)
self.master.setHomeLat(car.lat)
self.master.setHomeLon(car.lon)
self.master.queue_background_task({"cmd": "sunrise"})
self.master.queue_background_task({"cmd": "saveSettings"})
car.atHome = True
return

def wakeVehicle(self, vehicle):
apiResponseDict = None
vehicle.lastAPIAccessTime = time.time()
Expand Down