mirror of
https://github.com/Dielee/volvo2mqtt.git
synced 2026-08-13 03:09:52 +02:00
Optimize climate timer for multiple cars
This commit is contained in:
+5
-5
@@ -14,7 +14,7 @@ mqtt_client: mqtt.Client
|
|||||||
subscribed_topics = []
|
subscribed_topics = []
|
||||||
assumed_climate_state = {}
|
assumed_climate_state = {}
|
||||||
last_data_update = None
|
last_data_update = None
|
||||||
climate_timer: Timer
|
climate_timer = {}
|
||||||
|
|
||||||
|
|
||||||
def connect():
|
def connect():
|
||||||
@@ -56,16 +56,16 @@ def on_message(client, userdata, msg):
|
|||||||
api_thread.start()
|
api_thread.start()
|
||||||
assumed_climate_state[vin] = "ON"
|
assumed_climate_state[vin] = "ON"
|
||||||
# Starting timer to disable climate after 30 mins
|
# Starting timer to disable climate after 30 mins
|
||||||
climate_timer = Timer(30 * 60, volvo.disable_climate, (vin, ))
|
climate_timer[vin] = Timer(30 * 60, volvo.disable_climate, (vin, ))
|
||||||
climate_timer.start()
|
climate_timer[vin].start()
|
||||||
update_car_data()
|
update_car_data()
|
||||||
elif payload == "OFF":
|
elif payload == "OFF":
|
||||||
api_thread = Thread(target=volvo.api_call, args=(CLIMATE_STOP_URL, "POST", vin))
|
api_thread = Thread(target=volvo.api_call, args=(CLIMATE_STOP_URL, "POST", vin))
|
||||||
api_thread.start()
|
api_thread.start()
|
||||||
assumed_climate_state[vin] = "OFF"
|
assumed_climate_state[vin] = "OFF"
|
||||||
# Stop timer if active
|
# Stop timer if active
|
||||||
if climate_timer.is_alive():
|
if climate_timer[vin].is_alive():
|
||||||
climate_timer.cancel()
|
climate_timer[vin].cancel()
|
||||||
update_car_data()
|
update_car_data()
|
||||||
elif "lock_status" in msg.topic:
|
elif "lock_status" in msg.topic:
|
||||||
if payload == "LOCK":
|
if payload == "LOCK":
|
||||||
|
|||||||
Reference in New Issue
Block a user