* 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:
parent
4d237620d9
commit
a4ecdd6566
@ -171,6 +171,8 @@ class Weather(IntervalModule):
|
|||||||
'shown by the module) when refreshing weather data. '
|
'shown by the module) when refreshing weather data. '
|
||||||
'**NOTE:** Depending on how quickly the update is '
|
'**NOTE:** Depending on how quickly the update is '
|
||||||
'performed, the icon may not be displayed.'),
|
'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',
|
'format',
|
||||||
)
|
)
|
||||||
required = ('backend',)
|
required = ('backend',)
|
||||||
@ -191,6 +193,8 @@ class Weather(IntervalModule):
|
|||||||
color = None
|
color = None
|
||||||
backend = None
|
backend = None
|
||||||
interval = 1800
|
interval = 1800
|
||||||
|
offline_interval = 300
|
||||||
|
online_interval = None
|
||||||
refresh_icon = '⟳'
|
refresh_icon = '⟳'
|
||||||
format = '{current_temp}{temp_unit}[ {update_error}]'
|
format = '{current_temp}{temp_unit}[ {update_error}]'
|
||||||
|
|
||||||
@ -205,6 +209,9 @@ class Weather(IntervalModule):
|
|||||||
user_open(self.backend.forecast_url)
|
user_open(self.backend.forecast_url)
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
|
if self.online_interval is None:
|
||||||
|
self.online_interval = int(self.interval)
|
||||||
|
|
||||||
if self.backend is None:
|
if self.backend is None:
|
||||||
raise RuntimeError('A backend is required')
|
raise RuntimeError('A backend is required')
|
||||||
|
|
||||||
@ -239,6 +246,10 @@ class Weather(IntervalModule):
|
|||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
def update_thread(self):
|
def update_thread(self):
|
||||||
|
if internet():
|
||||||
|
self.interval = self.online_interval
|
||||||
|
else:
|
||||||
|
self.interval = self.offline_interval
|
||||||
try:
|
try:
|
||||||
self.check_weather()
|
self.check_weather()
|
||||||
while True:
|
while True:
|
||||||
@ -253,7 +264,6 @@ class Weather(IntervalModule):
|
|||||||
)
|
)
|
||||||
self.logger.error(msg, exc_info=True)
|
self.logger.error(msg, exc_info=True)
|
||||||
|
|
||||||
@require(internet)
|
|
||||||
def check_weather(self):
|
def check_weather(self):
|
||||||
'''
|
'''
|
||||||
Check the weather using the configured backend
|
Check the weather using the configured backend
|
||||||
|
@ -166,7 +166,6 @@ class Weathercom(WeatherBackend):
|
|||||||
# This will be set in the init based on the passed location code
|
# This will be set in the init based on the passed location code
|
||||||
forecast_url = None
|
forecast_url = None
|
||||||
|
|
||||||
@require(internet)
|
|
||||||
def init(self):
|
def init(self):
|
||||||
if self.location_code is not None:
|
if self.location_code is not None:
|
||||||
# Ensure that the location code is a string, in the event that a
|
# Ensure that the location code is a string, in the event that a
|
||||||
|
@ -107,7 +107,6 @@ class Wunderground(WeatherBackend):
|
|||||||
station_id = None
|
station_id = None
|
||||||
forecast_url = None
|
forecast_url = None
|
||||||
|
|
||||||
@require(internet)
|
|
||||||
def init(self):
|
def init(self):
|
||||||
'''
|
'''
|
||||||
Use the location_code to perform a geolookup and find the closest
|
Use the location_code to perform a geolookup and find the closest
|
||||||
|
Loading…
Reference in New Issue
Block a user