From fff2ccd6f4a70d76128c0f2698cce32ea17407af Mon Sep 17 00:00:00 2001 From: Linus Dietz <45101649+Dielee@users.noreply.github.com> Date: Mon, 22 Jan 2024 08:08:13 +0100 Subject: [PATCH] Add option for dynamic interval settings #160 --- src/CHANGELOG.md | 5 +++++ src/config.yaml | 2 +- src/const.py | 6 ++++-- src/mqtt.py | 13 +++++++++++-- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 8ddf452..c3e7139 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -1,3 +1,8 @@ +## v1.8.24 +### 🚀 Features: + +- Add option for dynamic interval settings #160 + ## v1.8.23 ### 🚀 Features: diff --git a/src/config.yaml b/src/config.yaml index b814ebf..2f6e77c 100644 --- a/src/config.yaml +++ b/src/config.yaml @@ -1,6 +1,6 @@ name: "Volvo2Mqtt" description: "Volvo AAOS MQTT bridge" -version: "1.8.23" +version: "1.8.24" slug: "volvo2mqtt" init: false url: "https://github.com/Dielee/volvo2mqtt" diff --git a/src/const.py b/src/const.py index dc60486..7b91c15 100644 --- a/src/const.py +++ b/src/const.py @@ -1,6 +1,6 @@ from config import settings -VERSION = "v1.8.23" +VERSION = "v1.8.24" OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2" VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles" @@ -20,6 +20,7 @@ FUEL_BATTERY_STATE_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicle STATISTICS_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/statistics" ENGINE_DIAGNOSTICS_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/engine" VEHICLE_DIAGNOSTICS_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/diagnostics" +WARNINGS_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/warnings" API_BACKEND_STATUS = "https://oip-dev-bff.euwest1.production.volvo.care/api/v1/backend-status" LENGTH_KILOMETERS = "km" @@ -130,7 +131,8 @@ supported_entities = [ {"name": "Time to Service", "domain": "sensor", "id": "time_to_service", "icon": "wrench-clock", "url": VEHICLE_DIAGNOSTICS_URL}, {"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": "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"}, ] old_entity_ids = ["months_to_service", "service_warning_trigger", "distance_to_empty"] diff --git a/src/mqtt.py b/src/mqtt.py index 4075e44..fabb3af 100644 --- a/src/mqtt.py +++ b/src/mqtt.py @@ -114,6 +114,8 @@ def on_message(client, userdata, msg): elif "update_data" in msg.topic: if payload == "PRESS": update_car_data(True) + elif "update_interval" in msg.topic: + settings.update({"updateInterval": int(payload)}) elif "schedule" in msg.topic: try: d = json.loads(payload) @@ -226,7 +228,7 @@ def update_car_data(force_update=False, overwrite={}): last_data_update = format_datetime(datetime.now(util.TZ), format="medium", locale=settings["babelLocale"]) for vin in volvo.vins: for entity in volvo.supported_endpoints[vin]: - if entity["domain"] == "button": + if entity["domain"] in ["button"]: continue ov_entity_id = "" @@ -243,6 +245,8 @@ def update_car_data(force_update=False, overwrite={}): state = last_data_update elif entity["id"] == "active_schedules": state = active_schedules[vin] + elif entity["id"] == "update_interval": + state = settings["updateInterval"] elif entity["id"] == "api_backend_status": if force_update: state = volvo.get_backend_status() @@ -347,11 +351,16 @@ def create_ha_devices(): if entity.get("domain") == "device_tracker" or entity.get("id") == "active_schedules": config["json_attributes_topic"] = f"homeassistant/{entity['domain']}/{vin}_{entity['id']}/attributes" - elif entity.get("domain") in ["switch", "lock", "button"]: + elif entity.get("domain") in ["switch", "lock", "button", "number"]: command_topic = f"homeassistant/{entity['domain']}/{vin}_{entity['id']}/command" config["command_topic"] = command_topic subscribed_topics.append(command_topic) mqtt_client.subscribe(command_topic) + + if entity["domain"] == "number": + config["min"] = entity["min"] + config["max"] = entity["max"] + config["mode"] = entity["mode"] elif entity.get("domain") == "image": config["url_topic"] = f"homeassistant/{entity['domain']}/{vin}_{entity['id']}/image_url"