forked from peter/volvo2mqtt
Add "Time to Service" sensor
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
## v1.8.13
|
||||||
|
### 🐛 Bug Fixes:
|
||||||
|
|
||||||
|
- Add "Time to Service" sensor #125
|
||||||
|
<b>Breaking change: The "Months to Service" sensor will be automatically deleted.
|
||||||
|
"Time to Service" contains this information now.
|
||||||
|
|
||||||
## v1.8.12
|
## v1.8.12
|
||||||
### 🐛 Bug Fixes:
|
### 🐛 Bug Fixes:
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
name: "Volvo2Mqtt"
|
name: "Volvo2Mqtt"
|
||||||
description: "Volvo AAOS MQTT bridge"
|
description: "Volvo AAOS MQTT bridge"
|
||||||
version: "1.8.12"
|
version: "1.8.13"
|
||||||
slug: "volvo2mqtt"
|
slug: "volvo2mqtt"
|
||||||
init: false
|
init: false
|
||||||
url: "https://github.com/Dielee/volvo2mqtt"
|
url: "https://github.com/Dielee/volvo2mqtt"
|
||||||
|
|||||||
+4
-2
@@ -1,6 +1,6 @@
|
|||||||
from config import settings
|
from config import settings
|
||||||
|
|
||||||
VERSION = "v1.8.12"
|
VERSION = "v1.8.13"
|
||||||
|
|
||||||
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"
|
||||||
@@ -114,7 +114,9 @@ supported_entities = [
|
|||||||
{"name": "Average Speed", "domain": "sensor", "id": "average_speed", "unit": "km/h" if not units.get(settings["babelLocale"]) else units[settings["babelLocale"]]["average_speed"]["unit"], "icon": "speedometer", "url": STATISTICS_URL, "state_class": "measurement"},
|
{"name": "Average Speed", "domain": "sensor", "id": "average_speed", "unit": "km/h" if not units.get(settings["babelLocale"]) else units[settings["babelLocale"]]["average_speed"]["unit"], "icon": "speedometer", "url": STATISTICS_URL, "state_class": "measurement"},
|
||||||
{"name": "Hours to Service", "domain": "sensor", "id": "hours_to_service", "unit": "hour", "icon": "wrench-clock", "url": VEHICLE_DIAGNOSTICS_URL},
|
{"name": "Hours to Service", "domain": "sensor", "id": "hours_to_service", "unit": "hour", "icon": "wrench-clock", "url": VEHICLE_DIAGNOSTICS_URL},
|
||||||
{"name": "Distance to Service", "domain": "sensor", "id": "km_to_service", "unit": "km" if not units.get(settings["babelLocale"]) else units[settings["babelLocale"]]["distance_to_service"]["unit"], "icon": "wrench-clock", "url": VEHICLE_DIAGNOSTICS_URL},
|
{"name": "Distance to Service", "domain": "sensor", "id": "km_to_service", "unit": "km" if not units.get(settings["babelLocale"]) else units[settings["babelLocale"]]["distance_to_service"]["unit"], "icon": "wrench-clock", "url": VEHICLE_DIAGNOSTICS_URL},
|
||||||
{"name": "Months to Service", "domain": "sensor", "id": "months_to_service", "unit": "month", "icon": "wrench-clock", "url": VEHICLE_DIAGNOSTICS_URL},
|
{"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": "Service warning status", "domain": "sensor", "id": "service_warning_status", "icon": "alert-outline", "url": VEHICLE_DIAGNOSTICS_URL},
|
||||||
{"name": "Service warning trigger", "domain": "sensor", "id": "service_warning_trigger", "icon": "alert-outline", "url": VEHICLE_DIAGNOSTICS_URL}
|
{"name": "Service warning trigger", "domain": "sensor", "id": "service_warning_trigger", "icon": "alert-outline", "url": VEHICLE_DIAGNOSTICS_URL}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
old_entity_ids = ["months_to_service"]
|
||||||
|
|||||||
+7
-2
@@ -10,8 +10,7 @@ from datetime import datetime
|
|||||||
from babel.dates import format_datetime
|
from babel.dates import format_datetime
|
||||||
from config import settings
|
from config import settings
|
||||||
from const import CLIMATE_START_URL, CLIMATE_STOP_URL, CAR_LOCK_URL, \
|
from const import CLIMATE_START_URL, CLIMATE_STOP_URL, CAR_LOCK_URL, \
|
||||||
CAR_UNLOCK_URL, availability_topic, icon_states
|
CAR_UNLOCK_URL, availability_topic, icon_states, old_entity_ids
|
||||||
|
|
||||||
|
|
||||||
mqtt_client: mqtt.Client
|
mqtt_client: mqtt.Client
|
||||||
subscribed_topics = []
|
subscribed_topics = []
|
||||||
@@ -361,3 +360,9 @@ def send_heartbeat():
|
|||||||
def send_offline():
|
def send_offline():
|
||||||
mqtt_client.publish(availability_topic, "offline")
|
mqtt_client.publish(availability_topic, "offline")
|
||||||
|
|
||||||
|
|
||||||
|
def delete_old_entities():
|
||||||
|
for vin in volvo.vins:
|
||||||
|
for entity in old_entity_ids:
|
||||||
|
topic = f"homeassistant/sensor/volvoAAOS2mqtt/{vin}_{entity}/config"
|
||||||
|
mqtt_client.publish(topic, payload="", retain=True)
|
||||||
|
|||||||
+7
-3
@@ -116,6 +116,7 @@ def get_vehicles():
|
|||||||
else:
|
else:
|
||||||
initialize_climate(vins)
|
initialize_climate(vins)
|
||||||
initialize_scheduler(vins)
|
initialize_scheduler(vins)
|
||||||
|
mqtt.delete_old_entities()
|
||||||
logging.info("Vin: " + str(vins) + " found!")
|
logging.info("Vin: " + str(vins) + " found!")
|
||||||
|
|
||||||
|
|
||||||
@@ -364,7 +365,7 @@ def api_call(url, method, vin, sensor_id=None, force_update=False, key_change=Fa
|
|||||||
return None
|
return None
|
||||||
elif response.status_code == 403 and "message" in data:
|
elif response.status_code == 403 and "message" in data:
|
||||||
if "Out of call volume quota" in data["message"]:
|
if "Out of call volume quota" in data["message"]:
|
||||||
logging.warn("Quota extended. Try to change VCCAPIKEY!")
|
logging.warning("Quota extended. Try to change VCCAPIKEY!")
|
||||||
change_vcc_api_key()
|
change_vcc_api_key()
|
||||||
api_call(url, method, vin, sensor_id, force_update, True)
|
api_call(url, method, vin, sensor_id, force_update, True)
|
||||||
else:
|
else:
|
||||||
@@ -548,8 +549,11 @@ def parse_api_data(data, sensor_id=None):
|
|||||||
if km_to_service > 0:
|
if km_to_service > 0:
|
||||||
return util.convert_metric_values(data["distanceToService"]["value"])
|
return util.convert_metric_values(data["distanceToService"]["value"])
|
||||||
return None
|
return None
|
||||||
elif sensor_id == "months_to_service":
|
elif sensor_id == "time_to_service":
|
||||||
return data["timeToService"]["value"] if util.keys_exists(data, "timeToService") else None
|
if util.keys_exists(data, "timeToService"):
|
||||||
|
return str(data["timeToService"]["value"]) + " " + data["timeToService"]["unit"]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
elif sensor_id == "service_warning_status":
|
elif sensor_id == "service_warning_status":
|
||||||
return data["serviceWarning"]["value"] if util.keys_exists(data, "serviceWarning") else None
|
return data["serviceWarning"]["value"] if util.keys_exists(data, "serviceWarning") else None
|
||||||
elif sensor_id == "service_warning_trigger":
|
elif sensor_id == "service_warning_trigger":
|
||||||
|
|||||||
Reference in New Issue
Block a user