From 1574fa968c9d6ee6bc655b57b63e01986a3690b8 Mon Sep 17 00:00:00 2001 From: Linus Dietz <45101649+Dielee@users.noreply.github.com> Date: Sat, 24 Jun 2023 17:53:12 +0200 Subject: [PATCH] Bump version --- src/mqtt.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/mqtt.py b/src/mqtt.py index d7e4260..5d324b0 100644 --- a/src/mqtt.py +++ b/src/mqtt.py @@ -70,10 +70,10 @@ def on_message(client, userdata, msg): elif "lock_status" in msg.topic: if payload == "LOCK": 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": 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: if payload == "PRESS": update_car_data(True) @@ -88,7 +88,7 @@ def update_loop(): time.sleep(settings["updateInterval"]) -def update_car_data(force_update=False): +def update_car_data(force_update=False, overwrite={}): global last_data_update last_data_update = format_datetime(datetime.now(), format="medium", locale=settings["babelLocale"]) for vin in volvo.vins: @@ -96,12 +96,21 @@ def update_car_data(force_update=False): if entity["domain"] == "button": continue + ov_entity_id = "" + ov_state = "" + if bool(overwrite): + ov_entity_id = overwrite["entity_id"] + ov_state = overwrite["state"] + if entity["id"] == "climate_status": state = assumed_climate_state[vin] elif entity["id"] == "last_data_update": state = last_data_update else: - state = volvo.api_call(entity["url"], "GET", vin, entity["id"], force_update) + if entity["id"] == ov_entity_id: + state = ov_state + else: + state = volvo.api_call(entity["url"], "GET", vin, entity["id"], force_update) if entity["domain"] == "device_tracker": topic = f"homeassistant/{entity['domain']}/{vin}_{entity['id']}/attributes"