diff --git a/lib/TWCManager/TWCMaster.py b/lib/TWCManager/TWCMaster.py index f72590c1..593397e1 100644 --- a/lib/TWCManager/TWCMaster.py +++ b/lib/TWCManager/TWCMaster.py @@ -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() diff --git a/lib/TWCManager/Vehicle/TeslaAPI.py b/lib/TWCManager/Vehicle/TeslaAPI.py index b88a21cd..87a7c9ee 100644 --- a/lib/TWCManager/Vehicle/TeslaAPI.py +++ b/lib/TWCManager/Vehicle/TeslaAPI.py @@ -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 @@ -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()