Skip to content
Snippets Groups Projects
Commit 167f26a3 authored by jkerdreu's avatar jkerdreu
Browse files

Add error handling & Gw

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/fork@1587 b32b6428-25c9-4566-ad07-03861ab6144f
parent f0665ee4
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
from xaal.lib import Device,Engine,tools,config
import platform,time
import pyowm
from pyowm.exceptions import OWMError
PACKAGE_NAME = "xaal.owm"
logger = tools.get_logger(PACKAGE_NAME,'DEBUG')
......@@ -28,10 +29,9 @@ class GW:
""" create devices, register .."""
cfg = self.cfg['config']
# create devices
attr = {}
# devices
temp = build_dev("thermometer.basic",cfg['temperature'])
attr['temperature'] = temp.new_attribute('temperature')
......@@ -43,12 +43,22 @@ class GW:
self.attr = attr
self.devs = [temp,hum,press]
self.eng.add_devices(self.devs)
# gw
gw = build_dev("gateway.basic",cfg['addr'])
emb = gw.new_attribute('embedded',[dev.address for dev in self.devs])
self.eng.add_devices(self.devs + [gw,])
self.eng.add_timer(self.update,RATE)
self.owm = pyowm.OWM(cfg['api_key'])
def update(self):
try:
self._update()
except OWMError,e:
logger.warn(e)
def _update(self):
place = self.cfg['config']['place']
weather = self.owm.weather_at_place(place).get_weather()
self.attr['temperature'].value = weather.get_temperature(unit='celsius')['temp']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment