Compare commits

...
3 Commits
Author SHA1 Message Date
Linus DietzandGitHub 781e1da8e8 Fix #104 (#107)
* Catch Volvo API not returning a valid json string #104

* Update changelog
2023-09-21 14:31:21 +02:00
6b419cfe3a Fix regex for some emails #98 // Add option to disable log completely #96 (#99)
* Update volovData.username regex (#98)

* Add option to disable log completely #96

---------

Co-authored-by: Gert-jan Theunissen <gurtjun@users.noreply.github.com>
2023-09-08 11:40:21 +02:00
Linus Dietz e5ece2116b Add option to use multiple docker containers (with different logins) #93 2023-08-28 15:09:01 +02:00
8 changed files with 49 additions and 10 deletions
+19
View File
@@ -1,3 +1,22 @@
## v1.8.8
### 🐛 Bug Fixes:
- Fix json decode error, if volvo API returns a simple string #104
## v1.8.7
### 🚀 Features:
- Add option to disable log completely #96
### 🐛 Bug Fixes:
- Fix regex error for some mailaddresses #97
## v1.8.6
### 🚀 Features:
- Add option to use multiple docker containers (with different logins) #93
## v1.8.5
### 🚀 Features:
+4 -2
View File
@@ -1,6 +1,6 @@
name: "Volvo2Mqtt"
description: "Volvo AAOS MQTT bridge"
version: "1.8.5"
version: "1.8.7"
slug: "volvo2mqtt"
init: false
url: "https://github.com/Dielee/volvo2mqtt"
@@ -15,6 +15,7 @@ options:
babelLocale: null
TZ: null
debug: false
disable_logging: false
mqtt:
broker: "auto_broker"
port: "auto_port"
@@ -34,13 +35,14 @@ schema:
babelLocale: str
TZ: match(^.+/.+$)
debug: bool
disable_logging: bool
mqtt:
broker: str
port: str
username: str?
password: str?
volvoData:
username: match(^([\w+\.]+@([\w-]+\.)+[\w-]{2,4})|(\+\d{5,20})$)
username: match(^([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)|(\+\d{5,20})$)
password: str
vin: str?
vccapikey:
+1 -1
View File
@@ -1,6 +1,6 @@
from config import settings
VERSION = "v1.8.5"
VERSION = "v1.8.8"
OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2"
VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v1/vehicles"
+10 -6
View File
@@ -4,6 +4,7 @@ import paho.mqtt.client as mqtt
import json
import volvo
import util
import os
from threading import Thread, Timer
from datetime import datetime
from babel.dates import format_datetime
@@ -23,7 +24,9 @@ active_schedules = {}
def connect():
client = mqtt.Client("volvoAAOS2mqtt")
client = mqtt.Client("volvoAAOS2mqtt") if os.environ.get("IS_HA_ADDON") \
else mqtt.Client("volvoAAOS2mqtt_" + settings.volvoData["username"])
client.will_set(availability_topic, "offline", 0, False)
if settings["mqtt"]["username"] and settings["mqtt"]["password"]:
client.username_pw_set(settings["mqtt"]["username"], settings["mqtt"]["password"])
@@ -252,11 +255,12 @@ def update_car_data(force_update=False, overwrite={}):
else:
topic = f"homeassistant/{entity['domain']}/{vin}_{entity['id']}/state"
mqtt_client.publish(
topic,
json.dumps(state) if isinstance(state, dict) or isinstance(state, list) else state
)
update_ha_device(entity, vin, state)
if state:
mqtt_client.publish(
topic,
json.dumps(state) if isinstance(state, dict) or isinstance(state, list) else state
)
update_ha_device(entity, vin, state)
def update_ha_device(entity, vin, state):
+2
View File
@@ -2,6 +2,8 @@
"updateInterval": 300,
"babelLocale": "de",
"TZ": "Europe/Berlin",
"debug": false,
"disable_logging": false,
"mqtt": {
"broker": "",
"port": 1883,
+3
View File
@@ -11,6 +11,9 @@ configuration:
debug:
name: API debug mode
description: Enable Volvo API debug, normaly this can stay off. If enabled, the complete log file can be found under \\<Your HA Host IP>\addons\volvo2mqtt\log\volvo2mqtt.log.
disable_logging:
name: Disable logging
description: Disable logging completely to reduce IO and SD card access.
mqtt:
name: MQTT Broker settings
description: Leave the settings as they are if you are using the MQTT Mosquitto Addon. If not, take a look at the readme from volvo2mqtt.
+4
View File
@@ -68,6 +68,10 @@ def setup_logging():
if settings["debug"]:
logger.setLevel(logging.DEBUG)
if "disable_logging" in settings:
if settings["disable_logging"]:
logger.setLevel(logging.ERROR)
def check_existing_folder():
Path("/addons/volvo2mqtt/log/").mkdir(parents=True, exist_ok=True)
+6 -1
View File
@@ -8,6 +8,7 @@ from threading import currentThread
from datetime import datetime, timedelta
from config import settings
from babel.dates import format_datetime
from json import JSONDecodeError
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, \
@@ -347,7 +348,11 @@ def api_call(url, method, vin, sensor_id=None, force_update=False, key_change=Fa
return None
logging.debug("Response status code: " + str(response.status_code))
data = response.json()
try:
data = response.json()
except JSONDecodeError as e:
logging.error("Fetched json decode error, Volvo API seems to return garbage. Skipping update. Error: " + str(e))
return None
if response.status_code == 200:
logging.debug(response.text)