Skip to content

Commit

Permalink
Safer "thw" computation in weathercloud uploader
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Aug 31, 2018
1 parent 24e0686 commit 00a047f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 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 = '1625'
_commit = 'a940b9d'
_release = '1626'
_commit = '24e0686'
15 changes: 13 additions & 2 deletions src/pywws/service/weathercloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,23 @@

import requests

from pywws.conversions import usaheatindex, wind_mph
import pywws.service

__docformat__ = "restructuredtext en"
service_name = os.path.splitext(os.path.basename(__file__))[0]
logger = logging.getLogger(__name__)


def thw(data):
if data['wind_ave'] is None:
return None
heat = usaheatindex(data['temp_out'], data['hum_out'])
if heat is None:
return None
return heat - (1.072 * wind_mph(data['wind_ave']))


class ToService(pywws.service.LiveDataService):
config = {
'deviceid' : ('', True, 'wid'),
Expand All @@ -71,8 +81,7 @@ class ToService(pywws.service.LiveDataService):
"'dew' : '%.0f'," "" "scale(x, 10.0)"#
#calc "usaheatindex(data['temp_out'], data['hum_out'])"
"'heat' : '%.0f'," "" "scale(x, 10.0)"#
#calc "usaheatindex(data['temp_out'], data['hum_out']) -
scale(wind_mph(data['wind_ave']), 1.072)"
#calc "self.thw(data)"
"'thw' : '%.0f'," "" "scale(x, 10.0)"#
#hum_out
"'hum' : '%.d',"#
Expand Down Expand Up @@ -114,6 +123,8 @@ def __init__(self, context, check_params=True):
"'heatin' : '%.0f'," "" "scale(x, 10.0)"#
"""
logger.debug('template: %s', self.template)
# add thw function to templater
self.templater.thw = thw

@contextmanager
def session(self):
Expand Down

0 comments on commit 00a047f

Please sign in to comment.