From 4bd6a7a9915b772b814c9963d6560ade013fe217 Mon Sep 17 00:00:00 2001
From: Linus Dietz <45101649+Dielee@users.noreply.github.com>
Date: Mon, 26 Jun 2023 14:23:53 +0200
Subject: [PATCH] Add divider option for average speed
---
README.md | 4 ++--
src/config.yaml | 4 +++-
src/const.py | 2 +-
src/translations/en.yaml | 4 ++--
src/volvo.py | 9 ++++++++-
5 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
index c8b4ef8..7ecb95f 100644
--- a/README.md
+++ b/README.md
@@ -57,7 +57,7 @@ NOTE: Energy status currently available only for cars in the Europe / Middle Eas
Just install this addon with the following command.
Please note to fill in your settings inside the environment variables.
-`docker run -d --pull=always -e CONF_updateInterval=300 -e CONF_babelLocale='de' -e CONF_mqtt='@json {"broker": "", "username": "", "password": "", "port": 1883}' -e CONF_volvoData='@json {"username": "", "password": "", "vin": "", "vccapikey": "", "odometerMultiplier": 1}' -e TZ='Europe/Berlin' --name volvo2mqtt ghcr.io/dielee/volvo2mqtt:latest`
+`docker run -d --pull=always -e CONF_updateInterval=300 -e CONF_babelLocale='de' -e CONF_mqtt='@json {"broker": "", "username": "", "password": "", "port": 1883}' -e CONF_volvoData='@json {"username": "", "password": "", "vin": "", "vccapikey": "", "odometerMultiplier": 1, "averageSpeedDivider": 1}' -e TZ='Europe/Berlin' --name volvo2mqtt ghcr.io/dielee/volvo2mqtt:latest`
HA Add-On:
@@ -70,7 +70,7 @@ Here is what every option means:
| `CONF_updateInterval` | `int` | **required** | Update intervall in seconds. |
| `CONF_babelLocale` | `string` | **required** | Select your country from this [list](https://www.ibm.com/docs/en/radfws/9.7?topic=overview-locales-code-pages-supported). "Locale name" is the column you need! |
| `CONF_mqtt` | `json` | **required** | Broker = Mqtt Broker IP / Username and Passwort are optional! Broker port can be changed. If no value is given, port 1883 will be used. |
-| `CONF_volvoData` | `json` | **required** | Username and password are REQUIRED. Car vin can be a single vin or a list of multiple vins like `["vin1", "vin2"]`. If no vin is provided, ALL of your vehicles will be used. Vccapi key is REQUIRED. Get your Vccapi key from [here](https://developer.volvocars.com/account/). Odometer Multiplier is sometimes 10, sometimes 1. Try what's right for your car. If you leave it empty, the multiplier will be 1. |
+| `CONF_volvoData` | `json` | **required** | Username and password are REQUIRED. Car vin can be a single vin or a list of multiple vins like `["vin1", "vin2"]`. If no vin is provided, ALL of your vehicles will be used. Vccapi key is REQUIRED. Get your Vccapi key from [here](https://developer.volvocars.com/account/). Odometer Multiplier is sometimes 10, sometimes 1. The same is applicable for average speed divider. Try what's right for your car. If you leave it empty, the multiplier and divider will be 1. |
| `CONF_debug` | `string` | | Debug option (true/false) - optional! |
| `TZ` | `string` | | Container timezone eg "Europe/Berlin" from [here](https://docs.diladele.com/docker/timezones.html)|
diff --git a/src/config.yaml b/src/config.yaml
index 28567c9..4f94110 100644
--- a/src/config.yaml
+++ b/src/config.yaml
@@ -1,6 +1,6 @@
name: "Volvo2Mqtt"
description: "Volvo AAOS MQTT bridge"
-version: "1.5.4"
+version: "1.5.5"
slug: "volvo2mqtt"
init: false
url: "https://github.com/Dielee/volvo2mqtt"
@@ -21,6 +21,7 @@ options:
vin: ""
vccapikey: null
odometerMultiplier: 1
+ averageSpeedDivider: 1
schema:
updateInterval: int(10,)
babelLocale: str
@@ -37,6 +38,7 @@ schema:
vin: str?
vccapikey: str
odometerMultiplier: int(1,)
+ averageSpeedDivider: int(1,)
arch:
- aarch64
- amd64
diff --git a/src/const.py b/src/const.py
index 7739ce8..51df6d5 100644
--- a/src/const.py
+++ b/src/const.py
@@ -1,6 +1,6 @@
from config import settings
-VERSION = "v1.5.4"
+VERSION = "v1.5.5"
OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2"
VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v1/vehicles"
diff --git a/src/translations/en.yaml b/src/translations/en.yaml
index af5c41f..3357ae4 100644
--- a/src/translations/en.yaml
+++ b/src/translations/en.yaml
@@ -15,5 +15,5 @@ configuration:
name: MQTT Broker settings
description: Broker is your mqtt broker IP eg "192.168.0.1". Mqtt username and password are optional. Broker port can be changed. If no value is given, port 1883 will be used.
volvoData:
- name: Volvo APP credentials
- description: You have to enter your Volvo app credentials. The username is normally your email, and the password is the password you use for your Volvo app. The vin can stay empty. The Add-On will use any vin inside your Volvo account. VCCAPI key is required and comes from your Volvo developer account. Odometer multiplier is sometimes 10, sometimes 1. Leave it empty if you don't know what's right. Take a look at the GitHub repo for more information!
\ No newline at end of file
+ name: Volvo configuration options
+ description: You have to enter your Volvo app credentials. The username is normally your email, and the password is the password you use for your Volvo app. The vin can stay empty. The Add-On will use any vin inside your Volvo account. VCCAPI key is required and comes from your Volvo developer account. Odometer multiplier is sometimes 10, sometimes 1. The same is applicable for average speed divider. Leave it as it is if you don't know what's right. Take a look at the GitHub repo for more information!
\ No newline at end of file
diff --git a/src/volvo.py b/src/volvo.py
index 79669c7..4bb824b 100644
--- a/src/volvo.py
+++ b/src/volvo.py
@@ -344,7 +344,14 @@ def parse_api_data(data, sensor_id=None):
if util.keys_exists(data, "averageSpeed"):
average_speed = int(data["averageSpeed"]["value"])
if average_speed > 0:
- return average_speed
+ divider = 1
+ if util.keys_exists(settings["volvoData"], "averageSpeedDivider"):
+ divider = settings["volvoData"]["averageSpeedDivider"]
+ if isinstance(divider, str):
+ divider = 1
+ elif divider < 1:
+ divider = 1
+ return average_speed / divider
else:
return None
else: