fix #647 weather doesnt run forever if offline on start (#700)

* always run init()

added online/offline_interval to settings of base weather class and accompanying logic

* remove `require(internet)` from `init` methods of both weather modules

* ...
This commit is contained in:
chestm007 2018-12-26 02:56:33 +11:00 committed by Erik Johnson
parent 4d237620d9
commit a4ecdd6566
3 changed files with 11 additions and 3 deletions

View File

@ -171,6 +171,8 @@ class Weather(IntervalModule):
'shown by the module) when refreshing weather data. '
'**NOTE:** Depending on how quickly the update is '
'performed, the icon may not be displayed.'),
('online_interval', 'seconds between updates when online (defaults to interval)'),
('offline_interval', 'seconds between updates when offline (default: 300)'),
'format',
)
required = ('backend',)
@ -191,6 +193,8 @@ class Weather(IntervalModule):
color = None
backend = None
interval = 1800
offline_interval = 300
online_interval = None
refresh_icon = ''
format = '{current_temp}{temp_unit}[ {update_error}]'
@ -205,6 +209,9 @@ class Weather(IntervalModule):
user_open(self.backend.forecast_url)
def init(self):
if self.online_interval is None:
self.online_interval = int(self.interval)
if self.backend is None:
raise RuntimeError('A backend is required')
@ -239,6 +246,10 @@ class Weather(IntervalModule):
self.thread.start()
def update_thread(self):
if internet():
self.interval = self.online_interval
else:
self.interval = self.offline_interval
try:
self.check_weather()
while True:
@ -253,7 +264,6 @@ class Weather(IntervalModule):
)
self.logger.error(msg, exc_info=True)
@require(internet)
def check_weather(self):
'''
Check the weather using the configured backend

View File

@ -166,7 +166,6 @@ class Weathercom(WeatherBackend):
# This will be set in the init based on the passed location code
forecast_url = None
@require(internet)
def init(self):
if self.location_code is not None:
# Ensure that the location code is a string, in the event that a

View File

@ -107,7 +107,6 @@ class Wunderground(WeatherBackend):
station_id = None
forecast_url = None
@require(internet)
def init(self):
'''
Use the location_code to perform a geolookup and find the closest