Skip to content
Snippets Groups Projects
Commit 90f27028 authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Fix refresh rate due to Meross request (email)

parent d67be14f
Branches
No related tags found
No related merge requests found
import aiohttp
from xaal.lib import tools
from meross_iot.http_api import MerossHttpClient
......@@ -15,34 +14,35 @@ logger = logging.getLogger(PACKAGE_NAME)
# disable internal logging
logging.getLogger("meross_iot").setLevel(logging.WARNING)
class GW(object):
def __init__(self,engine):
def __init__(self, engine):
self.engine = engine
self.devices = []
self.config()
engine.on_start(self.setup)
engine.on_stop(self._exit)
# refresh devices state
engine.add_timer(self.refresh,60)
# dis
engine.add_timer(self.discover,60)
# refresh devices state
engine.add_timer(self.refresh, 120)
# discover
engine.add_timer(self.discover, 300)
def config(self):
cfg = tools.load_cfg(PACKAGE_NAME)
if not cfg:
cfg= tools.new_cfg(PACKAGE_NAME)
cfg['config'] = {'addr': tools.get_random_uuid(),'login':'','password':''}
cfg = tools.new_cfg(PACKAGE_NAME)
cfg['config'] = {'addr': tools.get_random_uuid(), 'login': '', 'password': ''}
cfg['devices'] = {}
logger.warn("Created an empty config file")
logger.warning("Created an empty config file")
cfg.write()
self.cfg = cfg
async def setup(self):
config = self.cfg.get('config', {})
login = config.get('login', None)
passwd = config.get('password', None)
region = config.get('region', 'eu')
if not login or not passwd:
logger.warning('No email or password in configuration file')
return
......@@ -67,9 +67,9 @@ class GW(object):
logger.error(e)
meross_devices = self.manager.find_devices()
#import pdb;pdb.set_trace()
# import pdb;pdb.set_trace()
# config
devices_config = self.cfg.get('devices',{})
devices_config = self.cfg.get('devices', {})
# devices
uuids = [d.meross.uuid for d in self.devices]
for m_dev in meross_devices:
......@@ -79,19 +79,19 @@ class GW(object):
# find a class to handle this device
klass = bindings.find_class(m_dev)
if not klass:
logger.warn(f"No binding for {m_dev.type}")
logger.warning(f"No binding for {m_dev.type}")
continue
# search config
conf = devices_config.get(m_dev.uuid,None)
conf = devices_config.get(m_dev.uuid, None)
if not conf:
logger.info(f"Found a new device {m_dev.type} {m_dev.uuid}")
base_addr = tools.get_random_base_uuid()
devices_config.update({m_dev.uuid:{'base_addr':base_addr}})
devices_config.update({m_dev.uuid: {'base_addr': base_addr}})
devices_config.inline_comments[m_dev.uuid] = m_dev.type
else:
base_addr = tools.get_uuid(conf.get('base_addr',None))
base_addr = tools.get_uuid(conf.get('base_addr', None))
# create device
dev = klass(m_dev,base_addr)
dev = klass(m_dev, base_addr)
# poll the current state
await dev.meross.async_update()
await dev.update()
......@@ -109,6 +109,7 @@ class GW(object):
logger.info('Saving configuration file')
self.cfg.write()
def setup(eng):
GW(eng)
return True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment