mirror of
https://github.com/Dielee/volvo2mqtt.git
synced 2026-08-13 11:19:52 +02:00
Move energy api to v2
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
## v1.13.0
|
||||||
|
|
||||||
|
### 🚀 Features:
|
||||||
|
|
||||||
|
- Move energy api to v2 (https://developer.volvocars.com/apis/energy/v2/release-notes/)
|
||||||
|
|
||||||
## v1.12.2
|
## v1.12.2
|
||||||
|
|
||||||
### 🚀 Features:
|
### 🚀 Features:
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
name: "Volvo2Mqtt"
|
name: "Volvo2Mqtt"
|
||||||
description: "Volvo AAOS MQTT bridge"
|
description: "Volvo AAOS MQTT bridge"
|
||||||
version: "1.12.2"
|
version: "1.13.0"
|
||||||
slug: "volvo2mqtt"
|
slug: "volvo2mqtt"
|
||||||
init: false
|
init: false
|
||||||
url: "https://github.com/Dielee/volvo2mqtt"
|
url: "https://github.com/Dielee/volvo2mqtt"
|
||||||
|
|||||||
+7
-8
@@ -1,6 +1,6 @@
|
|||||||
from config import settings
|
from config import settings
|
||||||
|
|
||||||
VERSION = "v1.12.2"
|
VERSION = "v1.13.0"
|
||||||
|
|
||||||
OAUTH_TOKEN_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2"
|
OAUTH_TOKEN_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2"
|
||||||
OAUTH_AUTH_URL = "https://volvoid.eu.volvocars.com/as/authorization.oauth2"
|
OAUTH_AUTH_URL = "https://volvoid.eu.volvocars.com/as/authorization.oauth2"
|
||||||
@@ -12,7 +12,7 @@ CLIMATE_STOP_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/
|
|||||||
LOCK_STATE_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/doors"
|
LOCK_STATE_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/doors"
|
||||||
CAR_LOCK_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/commands/lock"
|
CAR_LOCK_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/commands/lock"
|
||||||
CAR_UNLOCK_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/commands/unlock"
|
CAR_UNLOCK_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/commands/unlock"
|
||||||
RECHARGE_STATE_URL = "https://api.volvocars.com/energy/v2/vehicles/{0}/recharge-status"
|
RECHARGE_STATE_URL = "https://api.volvocars.com/energy/v2/vehicles/{0}/state"
|
||||||
ODOMETER_STATE_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/odometer"
|
ODOMETER_STATE_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/odometer"
|
||||||
LOCATION_STATE_URL = "https://api.volvocars.com/location/v1/vehicles/{0}/location"
|
LOCATION_STATE_URL = "https://api.volvocars.com/location/v1/vehicles/{0}/location"
|
||||||
TYRE_STATE_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/tyres"
|
TYRE_STATE_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/tyres"
|
||||||
@@ -59,13 +59,12 @@ units = {
|
|||||||
|
|
||||||
availability_topic = "volvoAAOS2mqtt/availability"
|
availability_topic = "volvoAAOS2mqtt/availability"
|
||||||
|
|
||||||
charging_system_states = {"CHARGING_SYSTEM_CHARGING": "Charging", "CHARGING_SYSTEM_IDLE": "Idle",
|
charging_system_states = {"CHARGING": "Charging", "IDLE": "Idle",
|
||||||
"CHARGING_SYSTEM_FAULT": "Fault", "CHARGING_SYSTEM_UNSPECIFIED": "Unspecified",
|
"FAULT": "Fault", "UNSPECIFIED": "Unspecified",
|
||||||
"CHARGING_SYSTEM_DONE": "Done", "CHARGING_SYSTEM_SCHEDULED": "Scheduled"}
|
"DONE": "Done", "SCHEDULED": "Scheduled"}
|
||||||
|
|
||||||
charging_connection_states = {"CONNECTION_STATUS_DISCONNECTED": "Disconnected", "CONNECTION_STATUS_UNSPECIFIED": "Unspecified",
|
charging_connection_states = {"DISCONNECTED": "Disconnected", "UNSPECIFIED": "Unspecified",
|
||||||
"CONNECTION_STATUS_CONNECTED_DC": "Connected DC", "CONNECTION_STATUS_CONNECTED_AC": "Connected AC",
|
"FAULT": "Fault", "CONNECTED": "Connected"}
|
||||||
"CONNECTION_STATUS_FAULT": "Fault"}
|
|
||||||
|
|
||||||
window_states = {"CLOSED": "OFF", "OPEN": "ON", "UNSPECIFIED": "UNKNOWN", "AJAR": "ON"}
|
window_states = {"CLOSED": "OFF", "OPEN": "ON", "UNSPECIFIED": "UNKNOWN", "AJAR": "ON"}
|
||||||
door_states = {"CLOSED": "OFF", "OPEN": "ON", "UNSPECIFIED": "UNKNOWN", "AJAR": "ON"}
|
door_states = {"CLOSED": "OFF", "OPEN": "ON", "UNSPECIFIED": "UNKNOWN", "AJAR": "ON"}
|
||||||
|
|||||||
+13
@@ -176,16 +176,24 @@ def on_message(client, userdata, msg):
|
|||||||
if "climate_status" in msg.topic:
|
if "climate_status" in msg.topic:
|
||||||
if payload == "ON":
|
if payload == "ON":
|
||||||
start_climate(vin)
|
start_climate(vin)
|
||||||
|
return None
|
||||||
elif payload == "OFF":
|
elif payload == "OFF":
|
||||||
stop_climate(vin)
|
stop_climate(vin)
|
||||||
|
return None
|
||||||
|
return None
|
||||||
elif "lock_status" in msg.topic:
|
elif "lock_status" in msg.topic:
|
||||||
if payload == "LOCK":
|
if payload == "LOCK":
|
||||||
lock_car(vin)
|
lock_car(vin)
|
||||||
|
return None
|
||||||
elif payload == "UNLOCK":
|
elif payload == "UNLOCK":
|
||||||
unlock_car(vin)
|
unlock_car(vin)
|
||||||
|
return None
|
||||||
|
return None
|
||||||
elif "update_data" in msg.topic:
|
elif "update_data" in msg.topic:
|
||||||
if payload == "PRESS":
|
if payload == "PRESS":
|
||||||
update_car_data(True)
|
update_car_data(True)
|
||||||
|
return None
|
||||||
|
return None
|
||||||
elif "update_interval" in msg.topic:
|
elif "update_interval" in msg.topic:
|
||||||
try:
|
try:
|
||||||
update_interval = int(payload)
|
update_interval = int(payload)
|
||||||
@@ -194,8 +202,10 @@ def on_message(client, userdata, msg):
|
|||||||
else:
|
else:
|
||||||
logging.warning(f"Interval {update_interval} seconds is to low. Doing nothing!")
|
logging.warning(f"Interval {update_interval} seconds is to low. Doing nothing!")
|
||||||
update_car_data()
|
update_car_data()
|
||||||
|
return None
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
logging.error(f"Unable to change update_interval {error} payload={payload}")
|
logging.error(f"Unable to change update_interval {error} payload={payload}")
|
||||||
|
return None
|
||||||
elif "schedule" in msg.topic:
|
elif "schedule" in msg.topic:
|
||||||
try:
|
try:
|
||||||
d = json.loads(payload)
|
d = json.loads(payload)
|
||||||
@@ -205,8 +215,11 @@ def on_message(client, userdata, msg):
|
|||||||
|
|
||||||
if d["mode"] == "timer":
|
if d["mode"] == "timer":
|
||||||
start_climate_timer(d, vin)
|
start_climate_timer(d, vin)
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
logging.warning("No schedule mode found, doing nothing")
|
logging.warning("No schedule mode found, doing nothing")
|
||||||
|
return None
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def start_climate_timer(d, vin):
|
def start_climate_timer(d, vin):
|
||||||
|
|||||||
+22
-16
@@ -600,43 +600,50 @@ def cached_request(url, method, vin, force_update=False, key_change=False):
|
|||||||
|
|
||||||
|
|
||||||
def parse_api_data(data, sensor_id=None):
|
def parse_api_data(data, sensor_id=None):
|
||||||
if sensor_id != "api_backend_status":
|
if sensor_id in ["battery_charge_level", "electric_range", "charging_system_status",
|
||||||
data = data["data"]
|
"charging_connection_status", "estimated_charging_time", "estimated_charging_finish_time"]:
|
||||||
|
|
||||||
if sensor_id == "battery_charge_level":
|
if sensor_id == "battery_charge_level":
|
||||||
return data["batteryChargeLevel"]["value"] if util.keys_exists(data, "batteryChargeLevel") else None
|
return data["batteryChargeLevel"]["value"] if util.keys_exists(data, "batteryChargeLevel") else None
|
||||||
elif sensor_id == "battery_capacity":
|
|
||||||
return data["batteryCapacityKWH"] if util.keys_exists(data, "batteryCapacityKWH") else None
|
|
||||||
elif sensor_id == "electric_range":
|
elif sensor_id == "electric_range":
|
||||||
return util.convert_metric_values(data["electricRange"]["value"]) \
|
return util.convert_metric_values(data["electricRange"]["value"]) \
|
||||||
if util.keys_exists(data, "electricRange") else None
|
if util.keys_exists(data, "electricRange") else None
|
||||||
elif sensor_id == "charging_system_status":
|
elif sensor_id == "charging_system_status":
|
||||||
return charging_system_states[data["chargingSystemStatus"]["value"]] \
|
return charging_system_states[data["chargingStatus"]["value"]] \
|
||||||
if util.keys_exists(data, "chargingSystemStatus") else None
|
if util.keys_exists(data, "chargingStatus") else None
|
||||||
elif sensor_id == "charging_connection_status":
|
elif sensor_id == "charging_connection_status":
|
||||||
return charging_connection_states[data["chargingConnectionStatus"]["value"]] \
|
return charging_connection_states[data["chargerConnectionStatus"]["value"]] \
|
||||||
if util.keys_exists(data, "chargingConnectionStatus") else None
|
if util.keys_exists(data, "chargerConnectionStatus") else None
|
||||||
elif sensor_id == "estimated_charging_time":
|
elif sensor_id == "estimated_charging_time":
|
||||||
if util.keys_exists(data, "chargingSystemStatus"):
|
if util.keys_exists(data, "chargingStatus"):
|
||||||
charging_system_state = charging_system_states[data["chargingSystemStatus"]["value"]]
|
charging_system_state = charging_system_states[data["chargingStatus"]["value"]]
|
||||||
if charging_system_state == "Charging":
|
if charging_system_state == "Charging":
|
||||||
return data["estimatedChargingTime"]["value"] if util.keys_exists(data, "estimatedChargingTime") else ""
|
return data["estimatedChargingTimeToTargetBatteryChargeLevel"]["value"] if util.keys_exists(data,
|
||||||
|
"estimatedChargingTimeToTargetBatteryChargeLevel") else ""
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
return None
|
return None
|
||||||
elif sensor_id == "estimated_charging_finish_time":
|
elif sensor_id == "estimated_charging_finish_time":
|
||||||
if util.keys_exists(data, "chargingSystemStatus"):
|
if util.keys_exists(data, "estimatedChargingTimeToTargetBatteryChargeLevel"):
|
||||||
charging_system_state = charging_system_states[data["chargingSystemStatus"]["value"]]
|
charging_system_state = charging_system_states[data["chargingStatus"]["value"]]
|
||||||
if charging_system_state == "Charging":
|
if charging_system_state == "Charging":
|
||||||
charging_time = int(
|
charging_time = int(
|
||||||
data["estimatedChargingTime"]["value"] if util.keys_exists(data, "estimatedChargingTime")
|
data["estimatedChargingTimeToTargetBatteryChargeLevel"]["value"] if util.keys_exists(data, "estimatedChargingTimeToTargetBatteryChargeLevel")
|
||||||
else 0)
|
else 0)
|
||||||
charging_finished = datetime.now(util.TZ) + timedelta(minutes=charging_time)
|
charging_finished = datetime.now(util.TZ) + timedelta(minutes=charging_time)
|
||||||
return format_datetime(charging_finished, format="medium", locale=settings["babelLocale"])
|
return format_datetime(charging_finished, format="medium", locale=settings["babelLocale"])
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
return None
|
return None
|
||||||
elif sensor_id == "lock_status":
|
return None
|
||||||
|
else:
|
||||||
|
if sensor_id != "api_backend_status":
|
||||||
|
data = data["data"]
|
||||||
|
|
||||||
|
if sensor_id == "lock_status":
|
||||||
return data["centralLock"]["value"] if util.keys_exists(data, "centralLock") else None
|
return data["centralLock"]["value"] if util.keys_exists(data, "centralLock") else None
|
||||||
|
elif sensor_id == "battery_capacity":
|
||||||
|
return data["batteryCapacityKWH"] if util.keys_exists(data, "batteryCapacityKWH") else None
|
||||||
elif sensor_id == "odometer":
|
elif sensor_id == "odometer":
|
||||||
return util.convert_metric_values(int(data["odometer"]["value"])) \
|
return util.convert_metric_values(int(data["odometer"]["value"])) \
|
||||||
if util.keys_exists(data, "odometer") else None
|
if util.keys_exists(data, "odometer") else None
|
||||||
@@ -788,7 +795,6 @@ def parse_api_data(data, sensor_id=None):
|
|||||||
if trip_speed != 0:
|
if trip_speed != 0:
|
||||||
return util.convert_metric_values(trip_speed)
|
return util.convert_metric_values(trip_speed)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user