From ad691b6153005118d4a63af044a2e3df1f3fe9b8 Mon Sep 17 00:00:00 2001 From: Dielee Date: Thu, 6 Jul 2023 13:26:56 +0200 Subject: [PATCH] Update CHANGELOG.md --- src/CHANGELOG.md | 5 +++++ src/config.yaml | 2 +- src/const.py | 4 ++-- src/mqtt.py | 18 ++++++++++++------ src/volvo.py | 14 ++++++++++++++ 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 6323f42..f5a79dc 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -1,3 +1,8 @@ +## v1.7.5 +### 🚀 Features: + +- Added support for `LOCKING` and `UNLOCKING` state (Lock entity) + ## v1.7.4 ### 🐛 Bug Fixes: diff --git a/src/config.yaml b/src/config.yaml index 4ed8679..0e7bc0d 100644 --- a/src/config.yaml +++ b/src/config.yaml @@ -1,6 +1,6 @@ name: "Volvo2Mqtt" description: "Volvo AAOS MQTT bridge" -version: "1.7.4" +version: "1.7.5" slug: "volvo2mqtt" init: false url: "https://github.com/Dielee/volvo2mqtt" diff --git a/src/const.py b/src/const.py index 47670f5..ebe9e5f 100644 --- a/src/const.py +++ b/src/const.py @@ -1,6 +1,6 @@ from config import settings -VERSION = "v1.7.4" +VERSION = "v1.7.5" OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2" VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v1/vehicles" @@ -52,7 +52,7 @@ door_states = {"CLOSED": "OFF", "OPEN": "ON"} engine_states = {"RUNNING": "ON", "STOPPED": "OFF", "true": "ON", "false": "OFF"} icon_states = { - "lock_status": {"UNLOCKED": "lock-open-alert", "LOCKED": "lock"}, + "lock_status": {"UNLOCKED": "lock-open-alert", "LOCKED": "lock", "UNLOCKING": "lock-reset", "LOCKING": "lock-reset"}, "door_front_left": {"ON": "car-door", "OFF": "car-door-lock"}, "door_front_right": {"ON": "car-door", "OFF": "car-door-lock"}, "door_rear_left": {"ON": "car-door", "OFF": "car-door-lock"}, diff --git a/src/mqtt.py b/src/mqtt.py index ebf95bb..090afe8 100644 --- a/src/mqtt.py +++ b/src/mqtt.py @@ -96,15 +96,21 @@ def on_message(client, userdata, msg): update_car_data() elif "lock_status" in msg.topic: if payload == "LOCK": - volvo.api_call(CAR_LOCK_URL, "POST", vin) + # Start the api call in another thread for HA performance + Thread(target=volvo.api_call, args=(CAR_LOCK_URL, "POST", vin)).start() - # Force set unlocked state in HA because of slow api response - update_car_data(True, {"entity_id": "lock_status", "vin": vin, "state": "LOCKED"}) + # Force set locking state + update_car_data(False, {"entity_id": "lock_status", "vin": vin, "state": "LOCKING"}) + # Fetch API lock state until locking finished + Thread(target=volvo.check_lock_status, args=(vin, "UNLOCKED")).start() elif payload == "UNLOCK": - volvo.api_call(CAR_UNLOCK_URL, "POST", vin) + # Start the api call in another thread for HA performance + Thread(target=volvo.api_call, args=(CAR_UNLOCK_URL, "POST", vin)).start() - # Force set unlocked state in HA because of slow api response - update_car_data(True, {"entity_id": "lock_status", "vin": vin, "state": "UNLOCKED"}) + # Force set unlocking state + update_car_data(False, {"entity_id": "lock_status", "vin": vin, "state": "UNLOCKING"}) + # Fetch API lock state until unlocking finished + Thread(target=volvo.check_lock_status, args=(vin, "LOCKED")).start() elif "update_data" in msg.topic: if payload == "PRESS": update_car_data(True) diff --git a/src/volvo.py b/src/volvo.py index 35eb03c..bdc29cb 100644 --- a/src/volvo.py +++ b/src/volvo.py @@ -179,6 +179,20 @@ def disable_climate(vin): mqtt.update_car_data() +def check_lock_status(vin, old_state): + max_runs = 10 + done_runs = 0 + lock_state = api_call(LOCK_STATE_URL, "GET", vin, "lock_status", True) + while lock_state == old_state: + done_runs = done_runs + 1 + if done_runs >= max_runs: + break + lock_state = api_call(LOCK_STATE_URL, "GET", vin, "lock_status", True) + time.sleep(2) + + mqtt.update_car_data() + + def check_engine_status(vin): endpoint_url = "" engine_state_supported = False