mirror of
https://github.com/Dielee/volvo2mqtt.git
synced 2026-08-13 11:19:52 +02:00
Support force update for backend state
This commit is contained in:
@@ -244,6 +244,9 @@ def update_car_data(force_update=False, overwrite={}):
|
|||||||
elif entity["id"] == "active_schedules":
|
elif entity["id"] == "active_schedules":
|
||||||
state = active_schedules[vin]
|
state = active_schedules[vin]
|
||||||
elif entity["id"] == "api_backend_status":
|
elif entity["id"] == "api_backend_status":
|
||||||
|
if force_update:
|
||||||
|
state = volvo.get_backend_status()
|
||||||
|
else:
|
||||||
state = volvo.backend_status
|
state = volvo.backend_status
|
||||||
else:
|
else:
|
||||||
if entity["id"] == ov_entity_id and vin == ov_vin:
|
if entity["id"] == ov_entity_id and vin == ov_vin:
|
||||||
|
|||||||
+9
-5
@@ -55,7 +55,7 @@ def authorize():
|
|||||||
get_vcc_api_keys()
|
get_vcc_api_keys()
|
||||||
get_vehicles()
|
get_vehicles()
|
||||||
check_supported_endpoints()
|
check_supported_endpoints()
|
||||||
Thread(target=get_backend_status).start()
|
Thread(target=backend_status_loop).start()
|
||||||
else:
|
else:
|
||||||
message = auth.json()
|
message = auth.json()
|
||||||
raise Exception(message["error_description"])
|
raise Exception(message["error_description"])
|
||||||
@@ -316,18 +316,22 @@ def check_engine_status(vin):
|
|||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
|
def backend_status_loop():
|
||||||
|
while True:
|
||||||
|
get_backend_status()
|
||||||
|
# Update every hour
|
||||||
|
time.sleep(3600)
|
||||||
|
|
||||||
|
|
||||||
def get_backend_status():
|
def get_backend_status():
|
||||||
global backend_status
|
global backend_status
|
||||||
while True:
|
|
||||||
response = session.get(API_BACKEND_STATUS, timeout=15)
|
response = session.get(API_BACKEND_STATUS, timeout=15)
|
||||||
try:
|
try:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
backend_status = data["message"] if util.keys_exists(data, "message") else "No warnings"
|
backend_status = data["message"] if util.keys_exists(data, "message") else "No warnings"
|
||||||
except JSONDecodeError as e:
|
except JSONDecodeError as e:
|
||||||
backend_status = "No warnings"
|
backend_status = "No warnings"
|
||||||
|
return backend_status
|
||||||
# Update every hour
|
|
||||||
time.sleep(3600)
|
|
||||||
|
|
||||||
|
|
||||||
def api_call(url, method, vin, sensor_id=None, force_update=False, key_change=False):
|
def api_call(url, method, vin, sensor_id=None, force_update=False, key_change=False):
|
||||||
|
|||||||
Reference in New Issue
Block a user