Skip to content

Commit

Permalink
Delay conversion of template text to StringIO
Browse files Browse the repository at this point in the history
This allows service classes to initialise the base class before
extending the template.

Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Aug 28, 2018
1 parent b22a84b commit 4ca8d5b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '18.8.0'
_release = '1600'
_commit = '3b0b49d'
_release = '1601'
_commit = 'b22a84b'
4 changes: 3 additions & 1 deletion src/pywws/service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def __init__(self, context, check_params=True):
# create templater
if self.template:
self.templater = pywws.template.Template(context, use_locale=False)
self.template_file = StringIO(self.template)
self.template_file = None
# get time stamp of last uploaded data
self.last_update = context.status.get_datetime(
'last update', self.service_name)
Expand All @@ -204,6 +204,8 @@ def queue_data(self, timestamp, data, live):
return False
if not self.valid_data(data):
return False
if not self.template_file:
self.template_file = StringIO(self.template)
data_str = self.templater.make_text(self.template_file, data)
self.template_file.seek(0)
prepared_data = eval('{' + data_str + '}')
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/pwsweather.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ class ToService(pywws.service.CatchupDataService):
"""

def __init__(self, context, check_params=True):
super(ToService, self).__init__(context, check_params)
# extend template
if context.params.get('config', 'ws type') == '3080':
self.template += """
#illuminance "'solarradiation': '%.2f'," "" "illuminance_wm2(x)"#
#uv "'UV' : '%d',"#
"""
super(ToService, self).__init__(context, check_params)

@contextmanager
def session(self):
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/underground.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class ToService(pywws.service.CatchupDataService):
"""

def __init__(self, context, check_params=True):
super(ToService, self).__init__(context, check_params)
# extend template
if context.params.get('config', 'ws type') == '3080':
self.template += """
Expand All @@ -102,7 +103,6 @@ def __init__(self, context, check_params=True):
#hum_in "'indoorhumidity': '%.d',"#
#temp_in "'indoortempf' : '%.1f'," "" "temp_f(x)"#
"""
super(ToService, self).__init__(context, check_params)

@contextmanager
def session(self):
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/wetterarchivde.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ class ToService(pywws.service.CatchupDataService):
"""

def __init__(self, context, check_params=True):
super(ToService, self).__init__(context, check_params)
# extend template
if context.params.get('config', 'ws type') == '3080':
self.template += """#uv "'uv': '%d',"#"""
super(ToService, self).__init__(context, check_params)

@contextmanager
def session(self):
Expand Down

0 comments on commit 4ca8d5b

Please sign in to comment.