Skip to content
Snippets Groups Projects
Commit 8e8d6bcc authored by jkerdreu's avatar jkerdreu
Browse files

First release with the new schemas lib.

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/trunk@1968 b32b6428-25c9-4566-ad07-03861ab6144f
parent e3b7100a
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,8 @@ from setuptools import setup,find_packages
with open('README.rst') as f:
long_description = f.read()
VERSION = "0.1"
VERSION = 0.2
setup(
name='xaal.owm',
......
from .gw import init
from . import gw
gw.main()
from xaal.lib import Engine
def main():
eng = Engine()
gw.init(eng)
eng.run()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print("Bye Bye..")
import platform
import time
from xaal.lib import Device,Engine,tools,config
import platform,time
import pyowm
from pyowm.exceptions import OWMError
from xaal.lib import Device, tools
from xaal.schemas import devices
PACKAGE_NAME = "xaal.owm"
logger = tools.get_logger(PACKAGE_NAME,'DEBUG')
RATE = 300 # update every 5 min
def build_dev(dtype,addr):
dev = Device(dtype)
dev.address = addr
def setup_dev(dev):
dev.vendor_id = "IHSEV"
dev.product_id = "OpenWeatherMap"
dev.info = "%s@%s" % (PACKAGE_NAME,platform.node())
......@@ -28,27 +28,21 @@ class GW:
def setup(self):
""" create devices, register .."""
cfg = self.cfg['config']
attr = {}
# devices
temp = build_dev("thermometer.basic",cfg['temperature'])
attr['temperature'] = temp.new_attribute('temperature')
hum = build_dev("hygrometer.basic",cfg['humidity'])
attr['humidity'] = hum.new_attribute('humidity')
self.devs = []
self.devs.append(devices.thermometer(cfg['temperature']))
self.devs.append(devices.hygrometer(cfg['humidity']))
self.devs.append(devices.barometer(cfg['pressure']))
# gw
gw = devices.gateway(cfg['addr'])
gw.attributes['embedded'] = [dev.address for dev in self.devs]
press = build_dev("barometer.basic",cfg['pressure'])
attr['pressure'] = press.new_attribute('pressure')
for dev in (self.devs + [gw,]):
setup_dev(dev)
self.attr = attr
self.devs = [temp,hum,press]
# 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,])
# OWM stuff
self.eng.add_timer(self.update,RATE)
self.owm = pyowm.OWM(cfg['api_key'])
......@@ -61,23 +55,11 @@ class GW:
def _update(self):
place = self.cfg['config']['place']
weather = self.owm.weather_at_place(place).get_weather()
self.attr['temperature'].value = round(weather.get_temperature(unit='celsius')['temp'],1)
self.attr['pressure'].value = weather.get_pressure()['press']
self.attr['humidity'].value = weather.get_humidity()
def run():
eng = Engine()
log = GW(eng)
eng.run()
def main():
try:
run()
except KeyboardInterrupt:
print("Bye Bye..")
self.devs[0].attributes['temperature'] = round(weather.get_temperature(unit='celsius')['temp'],1)
self.devs[1].attributes['humidity'] = weather.get_humidity()
self.devs[2].attributes['pressure'] = weather.get_pressure()['press']
if __name__ == '__main__':
main()
def init(engine):
gw = GW(engine)
return gw
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment