Fix wrong return values for not working endpoints

This commit is contained in:
Linus Dietz
2023-06-29 08:06:31 +02:00
parent f0d4d68792
commit 9f1209e628
+4 -4
View File
@@ -183,17 +183,17 @@ def api_call(url, method, vin, sensor_id=None, force_update=False):
response = session.get(url.format(vin), timeout=15) response = session.get(url.format(vin), timeout=15)
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
print("Error getting data: " + str(e)) print("Error getting data: " + str(e))
return "" return None
elif method == "POST": elif method == "POST":
print("Starting " + method + " call against " + url) print("Starting " + method + " call against " + url)
try: try:
response = session.post(url.format(vin), timeout=20) response = session.post(url.format(vin), timeout=20)
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
print("Error getting data: " + str(e)) print("Error getting data: " + str(e))
return "" return None
else: else:
print("Unkown method posted: " + method + ". Returning nothing") print("Unkown method posted: " + method + ". Returning nothing")
return "" return None
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
@@ -207,7 +207,7 @@ def api_call(url, method, vin, sensor_id=None, force_update=False):
mqtt.update_car_data() mqtt.update_car_data()
else: else:
print("API Call failed. Status Code: " + str(response.status_code) + ". Error: " + response.text) print("API Call failed. Status Code: " + str(response.status_code) + ". Error: " + response.text)
return "" return None
return parse_api_data(data, sensor_id) return parse_api_data(data, sensor_id)