Skip to content

Commit

Permalink
Don't attempt to start or stop charging a disconnected car.
Browse files Browse the repository at this point in the history
Fixes #576
  • Loading branch information
RichieB2B committed Apr 25, 2024
1 parent 2a6a914 commit 75ec7d3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/TWCManager/Vehicle/TeslaAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,16 @@ def car_api_charge(self, charge):
# more than once per minute.
self.updateLastStartOrStopChargeTime()

# Don't attempt to start or stop charging a disconnected car.
if vehicle.chargingState == "Disconnected":
logger.info(
vehicle.name
+ " is disconnected. Do not "
+ startOrStop
+ " charge."
)
continue

# only start/stop charging cars parked at home.

if vehicle.update_location() is False:
Expand Down Expand Up @@ -727,16 +737,14 @@ def car_api_charge(self, charge):
"complete",
"charging",
"is_charging",
"disconnected",
"requested",
]:
# We asked the car to charge, but it responded
# that it can't, either because it's reached
# target charge state (reason == 'complete'), or
# it's already trying to charge (reason ==
# 'charging' or 'requested') or it's not
# connected to a charger (reason ==
# 'disconnected'). In these cases, it won't help
# 'charging' or 'requested').
# In these cases, it won't help
# to keep asking it to charge, so set
# vehicle.stopAskingToStartCharging = True.
#
Expand Down Expand Up @@ -1277,6 +1285,7 @@ class CarApiVehicle:
lon = 10000
atHome = False
timeToFullCharge = 0.0
chargingState = ""

# Sync values are updated by an external module such as TeslaMate
syncTimestamp = 0
Expand Down Expand Up @@ -1471,6 +1480,7 @@ def update_vehicle_data(self, cacheTime=60):
self.chargeLimit = charge["charge_limit_soc"]
self.batteryLevel = charge["battery_level"]
self.timeToFullCharge = charge["time_to_full_charge"]
self.chargingState = charge.get("charging_state", "")

self.lastVehicleStatusTime = now

Expand Down

0 comments on commit 75ec7d3

Please sign in to comment.