X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=cached%2Fweather_forecast.py;fp=cached%2Fweather_forecast.py;h=b34393832dec04120548aa08fb6822366cfc6ff6;hb=5f75cf834725ac26b289cc5f157af0cb71cd5f0e;hp=d1e754025eeaadeee84cfc12b38a1c53e8a547ee;hpb=ba223f821df1e9b8abbb6f6d23d5ba92c5a70b05;p=python_utils.git diff --git a/cached/weather_forecast.py b/cached/weather_forecast.py index d1e7540..b343938 100644 --- a/cached/weather_forecast.py +++ b/cached/weather_forecast.py @@ -19,6 +19,8 @@ import datetime_utils import dateparse.dateparse_utils as dp import persistent import text_utils +import smart_home.thermometers as temps + logger = logging.getLogger(__name__) @@ -61,23 +63,9 @@ class CachedDetailedWeatherForecast(persistent.Persistent): self.forecasts = {} # Ask the raspberry pi about the outside temperature. - www = None - try: - www = urllib.request.urlopen( - "http://10.0.0.75/~pi/outside_temp", - timeout=2, - ) - current_temp = www.read().decode("utf-8") - current_temp = float(current_temp) - current_temp *= (9/5) - current_temp += 32.0 - current_temp = round(current_temp) - except Exception: - logger.warning('Timed out reading 10.0.0.75/~pi/outside_temp?!') - current_temp = None - finally: - if www is not None: - www.close() + current_temp = temps.ThermometerRegistry().read_temperature( + 'house_outside', convert_to_fahrenheit=True + ) # Get a weather forecast for Bellevue. www = urllib.request.urlopen(