From 3d2285f59ef151cb4aa36adfda8cfee265c3d4e1 Mon Sep 17 00:00:00 2001 From: Linus Dietz <45101649+Dielee@users.noreply.github.com> Date: Tue, 23 Jan 2024 09:25:25 +0100 Subject: [PATCH] Add option to disable updates #160 --- src/CHANGELOG.md | 5 +++++ src/config.yaml | 2 +- src/const.py | 4 ++-- src/mqtt.py | 21 +++++++++++++++------ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 7ac58de..7a27ee5 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -1,3 +1,8 @@ +## v1.8.26 +### 🚀 Features: + +- Add option to disable updates #160 + ## v1.8.25 ### 🚀 Features: diff --git a/src/config.yaml b/src/config.yaml index 2f6e77c..dec9d43 100644 --- a/src/config.yaml +++ b/src/config.yaml @@ -1,6 +1,6 @@ name: "Volvo2Mqtt" description: "Volvo AAOS MQTT bridge" -version: "1.8.24" +version: "1.8.26" slug: "volvo2mqtt" init: false url: "https://github.com/Dielee/volvo2mqtt" diff --git a/src/const.py b/src/const.py index 5dfd4c6..7916e97 100644 --- a/src/const.py +++ b/src/const.py @@ -1,6 +1,6 @@ from config import settings -VERSION = "v1.8.25" +VERSION = "v1.8.26" OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2" VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles" @@ -132,7 +132,7 @@ supported_entities = [ {"name": "Service warning status", "domain": "sensor", "id": "service_warning_status", "icon": "alert-outline", "url": VEHICLE_DIAGNOSTICS_URL}, {"name": "Washer Fluid Level warning", "domain": "sensor", "id": "washer_fluid_warning", "icon": "alert-outline", "url": VEHICLE_DIAGNOSTICS_URL}, {"name": "API Backend status", "domain": "sensor", "id": "api_backend_status", "icon": "alert"}, - {"name": "Update Interval", "domain": "number", "id": "update_interval", "unit": "seconds", "icon": "timer", "min": 60, "max": 600, "mode": "box"}, + {"name": "Update Interval", "domain": "number", "id": "update_interval", "unit": "seconds", "icon": "timer", "min": -1, "max": 600, "mode": "box"}, {"name": "Warnings", "domain": "sensor", "id": "warnings", "icon": "alert", "url": WARNINGS_URL} ] diff --git a/src/mqtt.py b/src/mqtt.py index f79a55f..4115195 100644 --- a/src/mqtt.py +++ b/src/mqtt.py @@ -115,7 +115,12 @@ def on_message(client, userdata, msg): if payload == "PRESS": update_car_data(True) elif "update_interval" in msg.topic: - settings.update({"updateInterval": int(payload)}) + update_interval = int(payload) + if update_interval >= 60 or update_interval == -1: + settings.update({"updateInterval": int(update_interval)}) + else: + logging.warning("Interval " + str(update_interval) + " seconds is to low. Doing nothing!") + update_car_data() elif "schedule" in msg.topic: try: d = json.loads(payload) @@ -216,11 +221,15 @@ def start_climate(vin): def update_loop(): create_ha_devices() while True: - logging.info("Sending mqtt update...") - send_heartbeat() - update_car_data() - logging.info("Mqtt update done. Next run in " + str(settings["updateInterval"]) + " seconds.") - time.sleep(settings["updateInterval"]) + if settings["updateInterval"] > 0: + logging.info("Sending mqtt update...") + send_heartbeat() + update_car_data() + logging.info("Mqtt update done. Next run in " + str(settings["updateInterval"]) + " seconds.") + time.sleep(settings["updateInterval"]) + else: + logging.info("Data update is disabled, doing nothing for 30 seconds") + time.sleep(30) def update_car_data(force_update=False, overwrite={}):