Optimize lock/unlock behaviour

This commit is contained in:
Linus Dietz
2023-06-24 19:47:02 +02:00
parent e8315ba0fd
commit 4d8b5e5006
3 changed files with 15 additions and 6 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
name: "Volvo2Mqtt" name: "Volvo2Mqtt"
description: "Volvo AAOS MQTT bridge" description: "Volvo AAOS MQTT bridge"
version: "1.4.1" version: "1.4.2"
slug: "volvo2mqtt" slug: "volvo2mqtt"
init: false init: false
url: "https://github.com/Dielee/volvo2mqtt" url: "https://github.com/Dielee/volvo2mqtt"
+1 -1
View File
@@ -1,6 +1,6 @@
from config import settings from config import settings
VERSION = "v1.4.1" VERSION = "v1.4.2"
OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2" OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2"
VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v1/vehicles" VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v1/vehicles"
+12 -3
View File
@@ -77,10 +77,10 @@ def on_message(client, userdata, msg):
elif "lock_status" in msg.topic: elif "lock_status" in msg.topic:
if payload == "LOCK": if payload == "LOCK":
volvo.api_call(CAR_LOCK_URL, "POST", vin) volvo.api_call(CAR_LOCK_URL, "POST", vin)
update_car_data(True) update_car_data(True, {"entity_id": "lock_status", "state": "LOCKED"})
elif payload == "UNLOCK": elif payload == "UNLOCK":
volvo.api_call(CAR_UNLOCK_URL, "POST", vin) volvo.api_call(CAR_UNLOCK_URL, "POST", vin)
update_car_data(True) update_car_data(True, {"entity_id": "lock_status", "state": "UNLOCKED"})
elif "update_data" in msg.topic: elif "update_data" in msg.topic:
if payload == "PRESS": if payload == "PRESS":
update_car_data(True) update_car_data(True)
@@ -95,7 +95,7 @@ def update_loop():
time.sleep(settings["updateInterval"]) time.sleep(settings["updateInterval"])
def update_car_data(force_update=False): def update_car_data(force_update=False, overwrite={}):
global last_data_update global last_data_update
last_data_update = format_datetime(datetime.now(), format="medium", locale=settings["babelLocale"]) last_data_update = format_datetime(datetime.now(), format="medium", locale=settings["babelLocale"])
for vin in volvo.vins: for vin in volvo.vins:
@@ -103,10 +103,19 @@ def update_car_data(force_update=False):
if entity["domain"] == "button": if entity["domain"] == "button":
continue continue
ov_entity_id = ""
ov_state = ""
if bool(overwrite):
ov_entity_id = overwrite["entity_id"]
ov_state = overwrite["state"]
if entity["id"] == "climate_status": if entity["id"] == "climate_status":
state = assumed_climate_state[vin] state = assumed_climate_state[vin]
elif entity["id"] == "last_data_update": elif entity["id"] == "last_data_update":
state = last_data_update state = last_data_update
else:
if entity["id"] == ov_entity_id:
state = ov_state
else: else:
state = volvo.api_call(entity["url"], "GET", vin, entity["id"], force_update) state = volvo.api_call(entity["url"], "GET", vin, entity["id"], force_update)