Skip to content

Commit

Permalink
Support new statistic endpoints // Remove unused multiplier options
Browse files Browse the repository at this point in the history
  • Loading branch information
Dielee committed Sep 20, 2024
1 parent e179c76 commit 0cfb1a9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 37 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ The following steps are required for authentication in exactly this order:
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": ["key1", "key2"], "odometerMultiplier": 1, "averageSpeedDivider": 1, "averageFuelConsumptionMultiplier": 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": ["key1", "key2"]}' -e TZ='Europe/Berlin' --name volvo2mqtt ghcr.io/dielee/volvo2mqtt:latest`

<b>HA Add-On:</b><br>

Expand All @@ -146,9 +146,6 @@ Here is what every option means:
| `CONF_volvoData` | `json` | `password` | **required** | Your password to login into the Volvo App.
| `CONF_volvoData` | `json` | `vin` | optional | A single VIN like "VIN1" or a list of VINs like "["VIN1", "VIN2"]". Leave this empty if you don't know your VIN. The addon will use every car that is tied to your account.
| `CONF_volvoData` | `json` | `vccapikey` | **required** | VCCAPIKEY linked with your volvo developer account. Get your Vccapi key from [here](https://developer.volvocars.com/account/). <b>Starting version 1.8.0, it is possible to define multiple keys, like this: `["vccapikey1", "vccapikey2", "vccapikey3", "etc..."]`</b>
| `CONF_volvoData` | `json` | `odometerMultiplier` | optional | The multiplier value for the odometer value, as the volvo api delivers inconsistent data. For some cars this setting is 10, for some 1. Try what's right for your car. If you leave it empty, the multiplier will be 1.
| `CONF_volvoData` | `json` | `averageSpeedDivider` | optional | The divider value for the average speed value, as the volvo api delivers inconsistent data. For some cars this setting is 10, for some 1. Try what's right for your car. If you leave it empty, the divider will be 1.
| `CONF_volvoData` | `json` | `averageFuelConsumptionMultiplier` | optional | The multiplier value for the average fuel consumption value, as the volvo api delivers inconsistent data. For some cars this setting is 10, for some 1. Try what's right for your car. If you leave it empty, the multiplier will be 1.
| `CONF_debug` | `string` | | optional | Debug option (true/false). Normally you don't need this. |
| `TZ` | `string` | | **required** | Container timezone eg "Europe/Berlin" from [here](https://docs.diladele.com/docker/timezones.html)|

Expand Down
8 changes: 8 additions & 0 deletions src/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## v1.10.0
### 🚀 Features:
- Remove unused multiplier options

### 🐛 Bug Fixes:

- Support new statistic keys #237

## v1.9.7
### 🐛 Bug Fixes:

Expand Down
5 changes: 1 addition & 4 deletions src/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "Volvo2Mqtt"
description: "Volvo AAOS MQTT bridge"
version: "1.9.7"
version: "1.10.0"
slug: "volvo2mqtt"
init: false
url: "https://github.com/Dielee/volvo2mqtt"
Expand Down Expand Up @@ -47,9 +47,6 @@ schema:
vin: str?
vccapikey:
- match(^\b\w{32}\b$)
odometerMultiplier: int(1,)
averageSpeedDivider: int(1,)
averageFuelConsumptionMultiplier: int(1,)
arch:
- aarch64
- amd64
Expand Down
2 changes: 1 addition & 1 deletion src/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from config import settings

VERSION = "v1.9.7"
VERSION = "v1.10.0"

OAUTH_TOKEN_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2"
OAUTH_AUTH_URL = "https://volvoid.eu.volvocars.com/as/authorization.oauth2"
Expand Down
51 changes: 23 additions & 28 deletions src/volvo.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ def cached_request(url, method, vin, force_update=False, key_change=False):
def parse_api_data(data, sensor_id=None):
if sensor_id != "api_backend_status":
data = data["data"]

if sensor_id == "battery_charge_level":
return data["batteryChargeLevel"]["value"] if util.keys_exists(data, "batteryChargeLevel") else None
elif sensor_id == "battery_capacity":
Expand Down Expand Up @@ -588,14 +587,7 @@ def parse_api_data(data, sensor_id=None):
elif sensor_id == "lock_status":
return data["centralLock"]["value"] if util.keys_exists(data, "centralLock") else None
elif sensor_id == "odometer":
multiplier = 1
if util.keys_exists(settings["volvoData"], "odometerMultiplier"):
multiplier = settings["volvoData"]["odometerMultiplier"]
if isinstance(multiplier, str):
multiplier = 1
elif multiplier < 1:
multiplier = 1
return util.convert_metric_values(int(data["odometer"]["value"]) * multiplier) \
return util.convert_metric_values(int(data["odometer"]["value"])) \
if util.keys_exists(data, "odometer") else None
elif sensor_id == "window_front_left":
return window_states[data["frontLeftWindow"]["value"]] if util.keys_exists(data, "frontLeftWindow") \
Expand Down Expand Up @@ -643,30 +635,25 @@ def parse_api_data(data, sensor_id=None):
return fuel_amount
return None
elif sensor_id == "average_fuel_consumption":
average_fuel_con = 0
if util.keys_exists(data, "averageFuelConsumption"):
average_fuel_con = float(data["averageFuelConsumption"]["value"])
if average_fuel_con > 0:
multiplier = 1
if util.keys_exists(settings["volvoData"], "averageFuelConsumptionMultiplier"):
multiplier = settings["volvoData"]["averageFuelConsumptionMultiplier"]
if isinstance(multiplier, str):
multiplier = 1
elif multiplier < 1:
multiplier = 1
return average_fuel_con * multiplier
elif util.keys_exists(data, "averageFuelConsumptionAutomatic"):
average_fuel_con = float(data["averageFuelConsumptionAutomatic"]["value"])

if average_fuel_con > 0:
return average_fuel_con
return None
elif sensor_id == "average_speed":
average_speed = 0
if util.keys_exists(data, "averageSpeed"):
average_speed = float(data["averageSpeed"]["value"])
if average_speed > 1:
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 util.convert_metric_values(average_speed / divider)
elif util.keys_exists(data, "averageSpeedAutomatic"):
average_speed = float(data["averageSpeedAutomatic"]["value"])

if average_speed != 0:
return util.convert_metric_values(average_speed)

return None
elif sensor_id == "location":
coordinates = {}
Expand Down Expand Up @@ -705,7 +692,15 @@ def parse_api_data(data, sensor_id=None):
elif sensor_id == "service_warning_status":
return data["serviceWarning"]["value"] if util.keys_exists(data, "serviceWarning") else None
elif sensor_id == "average_energy_consumption":
return data["averageEnergyConsumption"]["value"] if util.keys_exists(data, "averageEnergyConsumption") else None
average_energy_con = 0
if util.keys_exists(data, "averageEnergyConsumption"):
average_energy_con = data["averageEnergyConsumption"]["value"]
elif util.keys_exists(data, "averageEnergyConsumptionAutomatic"):
average_energy_con = data["averageEnergyConsumptionAutomatic"]["value"]

if average_energy_con != 0:
return average_energy_con
return None
elif sensor_id == "washer_fluid_warning":
return data["washerFluidLevelWarning"]["value"] if util.keys_exists(data, "washerFluidLevelWarning") else None
elif sensor_id == "warnings":
Expand Down

0 comments on commit 0cfb1a9

Please sign in to comment.