Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Add statistics endpoint to cached responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Dielee committed Jun 26, 2023
1 parent c095c39 commit 689d3e8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 23 deletions.
2 changes: 1 addition & 1 deletion 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.5.0"
version: "1.5.1"
slug: "volvo2mqtt"
init: false
url: "https://github.com/Dielee/volvo2mqtt"
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.5.0"
VERSION = "v1.5.1"

OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2"
VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v1/vehicles"
Expand Down
25 changes: 4 additions & 21 deletions src/volvo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
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, \
WINDOWS_STATE_URL, LOCK_STATE_URL, TYRE_STATE_URL, supported_entities, BATTERY_CHARGE_STATE_URL
WINDOWS_STATE_URL, LOCK_STATE_URL, TYRE_STATE_URL, supported_entities, BATTERY_CHARGE_STATE_URL, \
STATISTICS_URL

session = requests.Session()
session.headers = {
Expand Down Expand Up @@ -168,30 +169,12 @@ def api_call(url, method, vin, sensor_id=None, force_update=False):
if datetime.now(util.TZ) >= token_expires_at:
refresh_auth()

if url == RECHARGE_STATE_URL:
# Minimize API calls for recharge state
if url in [RECHARGE_STATE_URL, WINDOWS_STATE_URL, LOCK_STATE_URL, TYRE_STATE_URL, STATISTICS_URL]:
# Minimize API calls for endpoints with multiple values
response = cached_request(url, method, vin, force_update)
if response is None:
# Exception caught while getting data from volvo api, doing nothing
return None
elif url == WINDOWS_STATE_URL:
# Minimize API calls for window state
response = cached_request(url, method, vin, force_update)
if response is None:
# Exception caught while getting data from volvo api, doing nothing
return ""
elif url == LOCK_STATE_URL:
# Minimize API calls for door state
response = cached_request(url, method, vin, force_update)
if response is None:
# Exception caught while getting data from volvo api, doing nothing
return ""
elif url == TYRE_STATE_URL:
# Minimize API calls for tyre state
response = cached_request(url, method, vin, force_update)
if response is None:
# Exception caught while getting data from volvo api, doing nothing
return ""
elif method == "GET":
print("Starting " + method + " call against " + url)
try:
Expand Down

0 comments on commit 689d3e8

Please sign in to comment.