mirror of
https://github.com/flobz/psa_car_controller.git
synced 2026-08-21 17:06:18 +00:00
fix get_temp()
This commit is contained in:
+2
-6
@@ -508,10 +508,7 @@ class MyPSACC:
|
||||
logger.error("The api return a wrong mileage for %s : %f", vin, mileage)
|
||||
else:
|
||||
if conn.execute("SELECT Timestamp from position where Timestamp=?", (date,)).fetchone() is None:
|
||||
temp = None
|
||||
if self.weather_api is not None:
|
||||
temp = get_temp(latitude,longitude,self.weather_api)
|
||||
|
||||
temp = get_temp(latitude,longitude,self.weather_api)
|
||||
if level_fuel == 0: # fix fuel level not provided when car is off
|
||||
try:
|
||||
level_fuel = conn.execute(
|
||||
@@ -540,8 +537,7 @@ class MyPSACC:
|
||||
except TypeError:
|
||||
in_progress = False
|
||||
if not in_progress:
|
||||
conn.execute("INSERT INTO battery(start_at,start_level,VIN) VALUES(?,?,?)",
|
||||
(charge_date, level, vin))
|
||||
conn.execute("INSERT INTO battery(start_at,start_level,VIN) VALUES(?,?,?)", (charge_date, level, vin))
|
||||
conn.commit()
|
||||
else:
|
||||
try:
|
||||
|
||||
@@ -7,15 +7,17 @@ import requests
|
||||
from MyLogger import logger
|
||||
|
||||
|
||||
def get_temp(latitude, longitude, api_key):
|
||||
def get_temp(latitude:str, longitude:str, api_key:str) -> float:
|
||||
try:
|
||||
weather_rep = requests.get("https://api.openweathermap.org/data/2.5/onecall",
|
||||
params={"lat": latitude, "lon": longitude,
|
||||
"exclude": "minutely,hourly,daily,alerts",
|
||||
"appid": api_key,
|
||||
"units": "metric"})
|
||||
temp = weather_rep.json()["current"]["temp"]
|
||||
logger.debug("Temperature :%fc", temp)
|
||||
if not (latitude is None or longitude is None or api_key is None):
|
||||
weather_rep = requests.get("https://api.openweathermap.org/data/2.5/onecall",
|
||||
params={"lat": latitude, "lon": longitude,
|
||||
"exclude": "minutely,hourly,daily,alerts",
|
||||
"appid": api_key,
|
||||
"units": "metric"})
|
||||
temp = weather_rep.json()["current"]["temp"]
|
||||
logger.debug("Temperature :%fc", temp)
|
||||
return temp
|
||||
except ConnectionError:
|
||||
logger.error("Can't connect to openweathermap :%s", traceback.format_exc())
|
||||
except KeyError:
|
||||
|
||||
Reference in New Issue
Block a user