Call new temperature endpoint

This commit is contained in:
Mike Cifelli 2023-01-05 19:18:11 -05:00
parent 627420e9cb
commit 3c5404a3da
1 changed files with 2 additions and 13 deletions

View File

@ -15,7 +15,7 @@ class WeatherUpdater:
lat = config['weather'].get('lat') lat = config['weather'].get('lat')
lon = config['weather'].get('lon') lon = config['weather'].get('lon')
self.uri = f'https://{host}/api/weather?lat={lat}&lon={lon}&units=metric' self.uri = f'https://{host}/api/temperature?lat={lat}&lon={lon}&units=metric'
self.auth = (user, password) self.auth = (user, password)
self.weatherTempFile = 'data/weather.tmp' self.weatherTempFile = 'data/weather.tmp'
self.weatherFile = 'data/weather.txt' self.weatherFile = 'data/weather.txt'
@ -33,18 +33,7 @@ class WeatherUpdater:
self.persistTemperature('halted') self.persistTemperature('halted')
def getTemperature(self): def getTemperature(self):
weather = self.getWeather() return requests.get(self.uri, auth=self.auth, timeout=3).json()['temperature']
currentWeather = list(
filter(
lambda t: t['timestep'] == 'current',
weather['tomorrow']['data']['timelines']
)
)
return currentWeather[0]['intervals'][0]['values']['temperature']
def getWeather(self):
return requests.get(self.uri, auth=self.auth, timeout=3).json()
def persistTemperature(self, temperature): def persistTemperature(self, temperature):
with open(self.weatherTempFile, 'w') as file: with open(self.weatherTempFile, 'w') as file: