Compare commits

..
5 Commits
Author SHA1 Message Date
Linus Dietz 71f03e505b Fix recharge caching while using multiple cars 2023-06-20 08:56:45 +02:00
Linus DietzandGitHub 2b6a2a4f4c Update README.md 2023-06-20 08:35:29 +02:00
Linus DietzandGitHub 38cca04473 Add working with section 2023-06-20 08:32:35 +02:00
Linus Dietz fbb98481f4 Undo changes // Bump version 2023-06-20 07:52:08 +02:00
Linus Dietz dad5f9aaaa Remove unused requirements // Bump version 2023-06-20 07:35:30 +02:00
5 changed files with 15 additions and 8 deletions
+5
View File
@@ -3,6 +3,11 @@
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.
## Confirmed working with
- Volvo XC40 BEV (2023)
Please let me know if your car works with this addon so I can expand the list!
## Setup
Just install this addon with the following command.
+1 -1
View File
@@ -1,4 +1,4 @@
VERSION = "v1.0.2.1"
VERSION = "v1.0.5"
OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2"
VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v1/vehicles"
+2 -1
View File
@@ -6,7 +6,7 @@ import threading
from datetime import datetime
from babel.dates import format_datetime
from config import settings
from const import VEHICLE_DETAILS_URL,CLIMATE_START_URL, CLIMATE_STOP_URL, CAR_LOCK_URL, \
from const import VEHICLE_DETAILS_URL, CLIMATE_START_URL, CLIMATE_STOP_URL, CAR_LOCK_URL, \
CAR_UNLOCK_URL, supported_sensors, supported_buttons, supported_switches, supported_locks
@@ -74,6 +74,7 @@ def update_loop():
while True:
print("Sending mqtt update...")
update_car_data()
print("Mqtt update done. Next run in " + str(settings["updateInterval"]) + " seconds.")
time.sleep(settings["updateInterval"])
-1
View File
@@ -1,5 +1,4 @@
requests~=2.29.0
dynaconf~=3.1.12
paho-mqtt~=1.6.1
pytz~=2023.3
Babel~=2.12.1
+7 -5
View File
@@ -8,7 +8,7 @@ from const import charging_system_states, CLIMATE_START_URL, \
session = requests.Session()
session.headers = {
"vcc-api-key": "",
"vcc-api-key": settings["volvoData"]["vccapikey"],
"content-type": "application/json",
"accept": "*/*"
}
@@ -42,7 +42,6 @@ def authorize():
token_expires_at = datetime.now() + timedelta(seconds=(data["expires_in"] - 30))
refresh_token = data["refresh_token"]
session.headers.update({"vcc-api-key": settings["volvoData"]["vccapikey"]})
get_vehicles()
else:
message = auth.json()
@@ -116,18 +115,18 @@ def api_call(url, method, vin, sensor_id=None):
# No API Data cached, get fresh data from API
print("Starting " + method + " call against " + url)
response = session.get(url.format(vin), timeout=15)
recharge_response = response
recharge_response[vin] = response
recharge_last_update = datetime.now()
else:
if (datetime.now() - recharge_last_update).total_seconds() >= settings["updateInterval"]:
# Old Data in Cache, updateing
print("Starting " + method + " call against " + url)
response = session.get(url.format(vin), timeout=15)
recharge_response = response
recharge_response[vin] = response
recharge_last_update = datetime.now()
else:
# Data is up do date, returning cached data
response = recharge_response
response = recharge_response[vin]
elif method == "GET":
print("Starting " + method + " call against " + url)
response = session.get(url.format(vin), timeout=15)
@@ -148,7 +147,10 @@ def api_call(url, method, vin, sensor_id=None):
else:
print("API Call failed. Status Code: " + str(response.status_code) + ". Error: " + response.text)
return ""
return parse_api_data(url, data, sensor_id)
def parse_api_data(url, data, sensor_id=None):
if url == VEHICLE_DETAILS_URL:
return data["data"]
elif sensor_id == "battery_charge_level":