Skip to content
Snippets Groups Projects
Commit 74b9dea9 authored by jkerdreu's avatar jkerdreu
Browse files

Initial release xaal.owm



git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/fork@1491 b32b6428-25c9-4566-ad07-03861ab6144f
parent 68a31153
No related branches found
No related tags found
No related merge requests found
from setuptools import setup
with open('README.rst') as f:
long_description = f.read()
VERSION = "0.1"
setup(
name='xaal.owm',
version=VERSION,
license='GPL License',
author='Jerome Kerdreux',
author_email='Jerome.Kerdreux@imt-atlantique.fr',
#url='',
description=('xAAL devices for OpenWeather Map' ),
long_description=long_description,
classifiers=[
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
],
keywords=['xaal', 'own','weather'],
platforms='any',
packages=["xaal.own",],
namespace_packages=["xaal"],
include_package_data=True,
install_requires=[
'xaal.lib',
'pyowm',
]
)
[config]
api_key = xxxx
place = Brest,FR
temperature = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
humidity = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
pressure = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
# this is a namespace package
try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
from . import dev
dev.main()
from xaal.lib import Device,Engine,tools,config
import platform,time
import pyowm
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
dev.vendor_id = "IHSEV"
dev.product_id = "OpenWeatherMap"
dev.info = "%s on %s" % (PACKAGE_NAME,platform.node())
return dev
class OWMManager:
def __init__(self,engine):
self.eng = engine
self.load_config()
self.setup()
self.last_update = 0
def load_config(self):
""" load config file """
cfg = tools.load_cfg(PACKAGE_NAME)
if not cfg:
logger.warn("Unable to load config file")
import sys;sys.exit(-1)
self.cfg = cfg['config']
def setup(self):
""" create devices, register .."""
# create devices
devs = {}
devs['temp'] = build_dev("thermometer.basic",self.cfg['temperature'])
devs['temp'].new_attribute('temperature')
devs['hum'] = build_dev("humidity.basic",self.cfg['humidity'])
devs['hum'].new_attribute('humidity')
devs['press'] = build_dev("barometer.basic",self.cfg['pressure'])
devs['press'].new_attribute('pressure')
self.devs = devs
self.eng.register_devices(devs.values())
self.eng.register_callback(self.update)
self.owm = pyowm.OWM(self.cfg['api_key'])
def update(self):
now = time.time()
if (self.last_update + RATE) < now:
weather = self.owm.weather_at_place(self.cfg['place']).get_weather()
self.devs['press'].attributes[0].value = weather.get_pressure()['press']
self.devs['temp'].attributes[0].value = weather.get_temperature(unit='celsius')['temp']
self.devs['hum'].attributes[0].value = weather.get_humidity()
self.last_update = now
def run():
eng = Engine()
log = OWMManager(eng)
eng.run()
def main():
try:
run()
except KeyboardInterrupt:
print("Bye Bye..")
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment