Compare commits

...
20 Commits
Author SHA1 Message Date
Linus Dietz f661985865 Add average fuel consumption multiplier for #30 // Rewrite README.md settings section 2023-06-27 07:56:54 +02:00
Linus Dietz da2d8395ec Optimize filter for average speed 2023-06-27 07:16:29 +02:00
Linus Dietz 4bd6a7a991 Add divider option for average speed 2023-06-26 14:23:53 +02:00
Linus Dietz 988fb3bd21 Add new empty setting options to settings.json 2023-06-26 14:12:24 +02:00
Linus DietzandGitHub 15fd137cc6 Add thanks to for sunroof endpoint 2023-06-26 12:59:01 +02:00
Linus Dietz af4eeb3a72 Change sunroof data endpoint 2023-06-26 12:37:56 +02:00
Linus Dietz cae32d7745 Bump version 2023-06-26 12:24:10 +02:00
Linus DietzandGitHub f1b265740b Add XC90 2023 T8 2023-06-26 12:10:52 +02:00
Linus Dietz bb689c3ee2 Fix sunroof data path 2023-06-26 11:44:14 +02:00
Linus DietzandGitHub 75363b5c0f Add new sensors 2023-06-26 11:28:27 +02:00
Linus DietzandGitHub 91eb8a9429 Add badges 2023-06-26 10:45:22 +02:00
Linus DietzandGitHub 638cfcd730 Add readme image 2023-06-26 09:32:27 +02:00
Linus Dietz 983e84e6fe Add readme image 2023-06-26 09:27:29 +02:00
Linus DietzandGitHub f8eb7cee41 Add lovelace sample 2023-06-26 09:25:46 +02:00
Linus Dietz 1e071154c5 Bump version 2023-06-26 08:55:23 +02:00
Linus Dietz 6d938eab7a Filter zero data from volvo api 2023-06-26 08:50:30 +02:00
Linus Dietz 86980408e7 Filter zero data from volvo api 2023-06-26 08:43:20 +02:00
Linus Dietz a0800db907 Change average speed icon 2023-06-26 08:37:41 +02:00
Linus Dietz d5565cd52a Move windows and doors to binary_sensor domain 2023-06-26 08:36:50 +02:00
Linus DietzandGitHub 9f5b4f4017 Only build on new release 2023-06-26 08:17:51 +02:00
9 changed files with 205 additions and 52 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ name: Create and publish a Docker image
on:
release:
types: [created, edited]
types: [created]
workflow_dispatch:
env:
+114 -13
View File
@@ -1,7 +1,19 @@
# Volvo2Mqtt
![Supports aarch64 Architecture][aarch64-shield]
![Supports amd64 Architecture][amd64-shield]
![Supports armhf Architecture][armhf-shield]
![Supports armv7 Architecture][armv7-shield]
![Supports i386 Architecture][i386-shield]
<br>
![Project Maintenance][maintenance-shield]
[![GitHub Release][releases-shield]][releases]
[![GitHub Activity][commits-shield]][commits]
This component establishes a connection between the newer AAOS Volvo cars and Home Assistant via MQTT.<br>
Maybe this component works also with other Volvo cars. Please try out the native Volvo [integration](https://www.home-assistant.io/integrations/volvooncall/) before using this component! If the native component doesn't work for your car, try this mqtt bridge.
<p>
Home Assistant thread can be found [here](https://community.home-assistant.io/t/volvo2mqtt-connect-your-aaos-volvo/585699).
## Confirmed working with
- XC40 BEV (2023)
@@ -13,6 +25,7 @@ Maybe this component works also with other Volvo cars. Please try out the native
- XC90 T8 PHEV (2023)
- XC60 PHEV (2023)
- XC60 PHEV (2022)
- XC90 PHEV T8 (2023)
- V90 PHEV T8 (2019)*
*only partly working
@@ -28,12 +41,14 @@ Please let me know if your car works with this addon so I can expand the list!<b
- Sensor "Charging System Status"
- Sensor "Charging Connection Status"
- Sensor "Estimated Charging Finish Time"
- Sensor "Door Lock Status"
- Sensor "Door Lock Status (All doors, tank lid, and engine hood)"
- Sensor "Window Lock Status (All windows and sunroof - Thanks to @navet)"
- Sensor "Engine Status"
- Sensor "Window Lock Status"
- Sensor "Odometer"
- Sensor "Tire Status"
- Sensor "Fuel Status"
- Sensor "Average Fuel Consumption"
- Sensor "Average Speed"
- Car Device Tracker
- Multiple cars
@@ -45,7 +60,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, "averageFuelConsumptionMultiplier": 1}' -e TZ='Europe/Berlin' --name volvo2mqtt ghcr.io/dielee/volvo2mqtt:latest`
<b>HA Add-On:</b><br>
@@ -53,15 +68,101 @@ Please note to fill in your settings inside the environment variables.
Here is what every option means:
| Name | Type | Default | Description |
| -------------------- | :-------: | :----------: | --------------------------------------------------------------- |
| `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, <b>ALL</b> 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_debug` | `string` | | Debug option (true/false) - optional! |
| `TZ` | `string` | | Container timezone eg "Europe/Berlin" from [here](https://docs.diladele.com/docker/timezones.html)|
| Environment Variable Name | Type | Json Option | Default | Description |
| ------------------------- | :-------: | :-----------------------------------: | :----------: | --------------------------------------------------------------- |
| `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` | `broker` | **required** | Your MQTT Broker IP. Eg. 192.168.0.5.
| `CONF_mqtt` | `json` | `port` | 1883 | Your MQTT Broker Port. If no value is given, port 1883 will be used. |
| `CONF_mqtt` | `json` | `username` | optional | MQTT Username for your broker.
| `CONF_mqtt` | `json` | `password` | optional | MQTT Password for your broker.
| `CONF_volvoData` | `json` | `username` | **required** | Normally your email address to login into the Volvo App.
| `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** | API key linked with your volvo developer account. Get your Vccapi key from [here](https://developer.volvocars.com/account/)
| `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)|
If you like my work:
## Lovelace sample card
<details>
<summary>Show me more!</summary><blockquote>
<br>
![alt text](https://raw.githubusercontent.com/Dielee/volvo2mqtt/main/img/lovelace_sample.png)<br>
<details>
<summary>Lovelace card sample</summary>
```
type: vertical-stack
title: Autostatus
cards:
- type: custom:vertical-stack-in-card
cards:
- type: custom:mushroom-lock-card
entity: lock.volvo_<your vin>_lock_status
name: Verrigelungsstatus
- type: horizontal-stack
cards:
- type: custom:mushroom-entity-card
entity: sensor.volvo_<your vin>_electric_range
name: Reichweite
layout: vertical
- type: custom:mushroom-entity-card
entity: sensor.volvo_<your vin>_battery_charge_level
name: Batteriestatus
layout: vertical
- type: custom:mushroom-entity-card
entity: sensor.volvo_<your vin>_estimated_charging_time
layout: vertical
name: Ladezeit
- type: horizontal-stack
cards:
- type: custom:mushroom-entity-card
entity: switch.volvo_<your vin>_climate_status
tap_action:
action: toggle
layout: vertical
name: Klimatisieren/Heizen
- type: custom:mushroom-template-card
primary: Daten aktualisieren
secondary: '{{ states(''sensor.volvo_<your vin>_last_data_update'')}}'
icon: mdi:update
layout: vertical
entity: button.volvo_<your vin>_update_data
- type: conditional
conditions:
- entity: sensor.volvo_<your vin>_estimated_charging_time
state_not: '0'
card:
type: custom:mushroom-entity-card
entity: sensor.volvo_<your vin>_estimated_charging_finish_time
name: Ladung vorraussichtlich abgeschlossen
show_name: true
- type: map
entities:
- entity: device_tracker.volvo_<your vin>_location
default_zoom: 16
dark_mode: false
hours_to_show: 0
auto_fit: true
aspect_ratio: '16:9'
```
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/U7U8MFXCF)
</details>
</blockquote></details>
[aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg
[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg
[armhf-shield]: https://img.shields.io/badge/armhf-yes-green.svg
[armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg
[i386-shield]: https://img.shields.io/badge/i386-yes-green.svg
[releases]: https://github.com/Dielee/volvo2mqtt/releases
[releases-shield]: https://img.shields.io/github/release/Dielee/volvo2mqtt.svg
[maintenance-shield]: https://img.shields.io/maintenance/yes/2023.svg
[commits-shield]: https://img.shields.io/github/commit-activity/y/Dielee/volvo2mqtt.svg
[commits]: https://github.com/Dielee/volvo2mqtt/commits/main
Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

+5 -1
View File
@@ -1,6 +1,6 @@
name: "Volvo2Mqtt"
description: "Volvo AAOS MQTT bridge"
version: "1.5.1"
version: "1.5.6"
slug: "volvo2mqtt"
init: false
url: "https://github.com/Dielee/volvo2mqtt"
@@ -21,6 +21,8 @@ options:
vin: ""
vccapikey: null
odometerMultiplier: 1
averageSpeedDivider: 1
averageFuelConsumptionMultiplier: 1
schema:
updateInterval: int(10,)
babelLocale: str
@@ -37,6 +39,8 @@ schema:
vin: str?
vccapikey: str
odometerMultiplier: int(1,)
averageSpeedDivider: int(1,)
averageFuelConsumptionMultiplier: int(1,)
arch:
- aarch64
- amd64
+17 -14
View File
@@ -1,6 +1,6 @@
from config import settings
VERSION = "v1.5.1"
VERSION = "v1.5.6"
OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2"
VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v1/vehicles"
@@ -28,6 +28,9 @@ charging_system_states = {"CHARGING_SYSTEM_CHARGING": "Charging", "CHARGING_SYST
charging_connection_states = {"CONNECTION_STATUS_DISCONNECTED": "Disconnected", "CONNECTION_STATUS_UNSPECIFIED": "Unspecified",
"CONNECTION_STATUS_CONNECTED_DC": "Connected DC", "CONNECTION_STATUS_CONNECTED_AC": "Connected AC"}
window_states = {"CLOSED": "OFF", "OPEN": "ON"}
door_states = {"CLOSED": "OFF", "OPEN": "ON"}
supported_entities = [
{"name": "Battery Charge Level", "domain": "sensor", "id": "battery_charge_level", "unit": "%", "icon": "car-battery", "url": RECHARGE_STATE_URL},
{"name": "Battery Charge Level", "domain": "sensor", "id": "battery_charge_level", "unit": "%", "icon": "car-battery", "url": BATTERY_CHARGE_STATE_URL},
@@ -38,18 +41,18 @@ supported_entities = [
{"name": "Estimated Charging Finish Time", "domain": "sensor", "id": "estimated_charging_finish_time", "icon": "timer-sync-outline", "url": RECHARGE_STATE_URL},
{"name": "Odometer", "domain": "sensor", "id": "odometer", "unit": "km" if settings["babelLocale"] != "en_US" else "mi", "icon": "counter", "url": ODOMETER_STATE_URL},
{"name": "Last Data Update", "domain": "sensor", "id": "last_data_update", "icon": "timer", "url": ""},
{"name": "Window Front Left", "domain": "sensor", "id": "window_front_left", "icon": "car-door-lock", "url": WINDOWS_STATE_URL},
{"name": "Window Front Right", "domain": "sensor", "id": "window_front_right", "icon": "car-door-lock", "url": WINDOWS_STATE_URL},
{"name": "Window Rear Left", "domain": "sensor", "id": "window_rear_left", "icon": "car-door-lock", "url": WINDOWS_STATE_URL},
{"name": "Window Rear Right", "domain": "sensor", "id": "window_rear_right", "icon": "car-door-lock", "url": WINDOWS_STATE_URL},
{"name": "Door Front Left", "domain": "sensor", "id": "door_front_left", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Door Front Right", "domain": "sensor", "id": "door_front_right", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Door Rear Left", "domain": "sensor", "id": "door_rear_left", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Door Rear Right", "domain": "sensor", "id": "door_rear_right", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Tailgate", "domain": "sensor", "id": "tailgate", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Engine Hood", "domain": "sensor", "id": "engine_hood", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Tank Lid", "domain": "sensor", "id": "tank_lid", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Sunroof", "domain": "sensor", "id": "sunroof", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Window Front Left", "domain": "binary_sensor", "device_class": "window", "id": "window_front_left", "icon": "car-door-lock", "url": WINDOWS_STATE_URL},
{"name": "Window Front Right", "domain": "binary_sensor", "device_class": "window", "id": "window_front_right", "icon": "car-door-lock", "url": WINDOWS_STATE_URL},
{"name": "Window Rear Left", "domain": "binary_sensor", "device_class": "window", "id": "window_rear_left", "icon": "car-door-lock", "url": WINDOWS_STATE_URL},
{"name": "Window Rear Right", "domain": "binary_sensor", "device_class": "window", "id": "window_rear_right", "icon": "car-door-lock", "url": WINDOWS_STATE_URL},
{"name": "Door Front Left", "domain": "binary_sensor", "device_class": "door", "id": "door_front_left", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Door Front Right", "domain": "binary_sensor", "device_class": "door", "id": "door_front_right", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Door Rear Left", "domain": "binary_sensor", "device_class": "door", "id": "door_rear_left", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Door Rear Right", "domain": "binary_sensor", "device_class": "door", "id": "door_rear_right", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Tailgate", "domain": "binary_sensor", "device_class": "door", "id": "tailgate", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Engine Hood", "domain": "binary_sensor", "device_class": "door", "id": "engine_hood", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Tank Lid", "domain": "binary_sensor", "device_class": "door", "id": "tank_lid", "icon": "car-door-lock", "url": LOCK_STATE_URL},
{"name": "Sunroof", "domain": "binary_sensor", "device_class": "door", "id": "sunroof", "icon": "car-door-lock", "url": WINDOWS_STATE_URL},
{"name": "Air Conditioning", "domain": "switch", "id": "climate_status", "icon": "air-conditioner"},
{"name": "Lock state", "domain": "lock", "id": "lock_status", "icon": "lock", "url": LOCK_STATE_URL},
{"name": "Force Update Data", "domain": "button", "id": "update_data", "icon": "update", "url": ""},
@@ -61,5 +64,5 @@ supported_entities = [
{"name": "Engine State", "domain": "sensor", "id": "engine_state", "icon": "engine", "url": ENGINE_STATE_URL},
{"name": "Fuel Level", "domain": "sensor", "id": "fuel_level", "unit": "liters", "icon": "fuel", "url": FUEL_STATE_URL},
{"name": "Average Fuel Consumption", "domain": "sensor", "id": "average_fuel_consumption", "unit": "liters", "icon": "fuel", "url": STATISTICS_URL},
{"name": "Average Speed", "domain": "sensor", "id": "average_speed", "unit": "km/h" if settings["babelLocale"] != "en_US" else "mp/h", "icon": "fuel", "url": STATISTICS_URL}
{"name": "Average Speed", "domain": "sensor", "id": "average_speed", "unit": "km/h" if settings["babelLocale"] != "en_US" else "mp/h", "icon": "speedometer", "url": STATISTICS_URL}
]
+6 -3
View File
@@ -150,13 +150,16 @@ def create_ha_devices():
"unique_id": f"volvoAAOS2mqtt_{vin}_{entity['id']}",
"availability_topic": availability_topic
}
if entity.get('unit'):
if entity.get("device_class"):
config["device_class"] = entity["device_class"]
if entity.get("unit"):
config["unit_of_measurement"] = entity["unit"]
if entity.get('domain') == "device_tracker":
if entity.get("domain") == "device_tracker":
config["json_attributes_topic"] = f"homeassistant/{entity['domain']}/{vin}_{entity['id']}/attributes"
if entity.get('domain') in ["switch", "lock", "button"]:
if entity.get("domain") in ["switch", "lock", "button"]:
command_topic = f"homeassistant/{entity['domain']}/{vin}_{entity['id']}/command"
config["command_topic"] = command_topic
subscribed_topics.append(command_topic)
+4 -1
View File
@@ -12,6 +12,9 @@
"username": "",
"password": "",
"vin": "",
"vccapikey": ""
"vccapikey": "",
"odometerMultiplier": "",
"averageSpeedDivider": "",
"averageFuelConsumptionMultiplier": ""
}
}
+2 -2
View File
@@ -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!
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 and average fuel consumption. Leave it as it is if you don't know what's right. Take a look at the GitHub repo for more information!
+56 -17
View File
@@ -4,8 +4,8 @@ import util
from datetime import datetime, timedelta
from config import settings
from babel.dates import format_datetime
from const import charging_system_states, charging_connection_states, CLIMATE_START_URL, \
OAUTH_URL, VEHICLES_URL, VEHICLE_DETAILS_URL, RECHARGE_STATE_URL, \
from const import charging_system_states, charging_connection_states, door_states, window_states, \
OAUTH_URL, VEHICLES_URL, VEHICLE_DETAILS_URL, RECHARGE_STATE_URL, CLIMATE_START_URL, \
WINDOWS_STATE_URL, LOCK_STATE_URL, TYRE_STATE_URL, supported_entities, BATTERY_CHARGE_STATE_URL, \
STATISTICS_URL
@@ -285,29 +285,33 @@ def parse_api_data(data, sensor_id=None):
multiplier = 1
return int(data["odometer"]["value"]) * multiplier if util.keys_exists(data, "odometer") else None
elif sensor_id == "window_front_left":
return data["frontLeftWindowOpen"]["value"] if util.keys_exists(data, "frontLeftWindowOpen") else None
return window_states[data["frontLeftWindowOpen"]["value"]] if util.keys_exists(data, "frontLeftWindowOpen") \
else None
elif sensor_id == "window_front_right":
return data["frontRightWindowOpen"]["value"] if util.keys_exists(data, "frontRightWindowOpen") else None
return window_states[data["frontRightWindowOpen"]["value"]] if util.keys_exists(data, "frontRightWindowOpen") \
else None
elif sensor_id == "window_rear_left":
return data["rearLeftWindowOpen"]["value"] if util.keys_exists(data, "rearLeftWindowOpen") else None
return window_states[data["rearLeftWindowOpen"]["value"]] if util.keys_exists(data, "rearLeftWindowOpen") \
else None
elif sensor_id == "window_rear_right":
return data["rearRightWindowOpen"]["value"] if util.keys_exists(data, "rearRightWindowOpen") else None
return window_states[data["rearRightWindowOpen"]["value"]] if util.keys_exists(data, "rearRightWindowOpen") \
else None
elif sensor_id == "door_front_left":
return data["frontLeftDoorOpen"]["value"] if util.keys_exists(data, "frontLeftDoorOpen") else None
return door_states[data["frontLeftDoorOpen"]["value"]] if util.keys_exists(data, "frontLeftDoorOpen") else None
elif sensor_id == "door_front_right":
return data["frontRightDoorOpen"]["value"] if util.keys_exists(data, "frontRightDoorOpen") else None
return door_states[data["frontRightDoorOpen"]["value"]] if util.keys_exists(data, "frontRightDoorOpen") else None
elif sensor_id == "door_rear_left":
return data["rearLeftDoorOpen"]["value"] if util.keys_exists(data, "rearLeftDoorOpen") else None
return door_states[data["rearLeftDoorOpen"]["value"]] if util.keys_exists(data, "rearLeftDoorOpen") else None
elif sensor_id == "door_rear_right":
return data["rearRightDoorOpen"]["value"] if util.keys_exists(data, "rearRightDoorOpen") else None
return door_states[data["rearRightDoorOpen"]["value"]] if util.keys_exists(data, "rearRightDoorOpen") else None
elif sensor_id == "tailgate":
return data["tailGateOpen"]["value"] if util.keys_exists(data, "tailGateOpen") else None
return door_states[data["tailGateOpen"]["value"]] if util.keys_exists(data, "tailGateOpen") else None
elif sensor_id == "sunroof":
return data["capOpen"]["value"] if util.keys_exists(data, "capOpen") else None
return door_states[data["sunRoofOpen"]["value"]] if util.keys_exists(data, "sunRoofOpen") else None
elif sensor_id == "engine_hood":
return data["hoodOpen"]["value"] if util.keys_exists(data, "hoodOpen") else None
return door_states[data["hoodOpen"]["value"]] if util.keys_exists(data, "hoodOpen") else None
elif sensor_id == "tank_lid":
return data["tankLidOpen"]["value"] if util.keys_exists(data, "tankLidOpen") else None
return door_states[data["tankLidOpen"]["value"]] if util.keys_exists(data, "tankLidOpen") else None
elif sensor_id == "tyre_front_left":
return data["frontLeftTyrePressure"]["value"] if util.keys_exists(data, "frontLeftTyrePressure") else None
elif sensor_id == "tyre_front_right":
@@ -319,11 +323,46 @@ def parse_api_data(data, sensor_id=None):
elif sensor_id == "engine_state":
return data["engineRunning"]["value"] if util.keys_exists(data, "engineRunning") else None
elif sensor_id == "fuel_level":
return data["fuelAmount"]["value"] if util.keys_exists(data, "fuelAmount") else None
if util.keys_exists(data, "fuelAmount"):
fuel_amount = int(data["fuelAmount"]["value"])
if fuel_amount > 0:
return fuel_amount
else:
return None
else:
return None
elif sensor_id == "average_fuel_consumption":
return data["averageFuelConsumption"]["value"] if util.keys_exists(data, "averageFuelConsumption") else None
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
else:
return None
else:
return None
elif sensor_id == "average_speed":
return data["averageSpeed"]["value"] if util.keys_exists(data, "averageSpeed") else None
if util.keys_exists(data, "averageSpeed"):
average_speed = int(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 average_speed / divider
else:
return None
else:
return None
elif sensor_id == "location":
coordinates = {}
if util.keys_exists(data, "geometry"):