def main(addr): if addr == None: addr = tools.get_random_uuid() dev = Device("switch.basic",addr) dev.product_id = 'One Simple test of Switch' dev.url = 'http://www.acme.org' # attributes state = dev.new_attribute('state') dev.dump() # methods def on(): state.value = True print("%s ON" % dev) def off(): state.value = False print("%s OFF" %dev) dev.add_method('on',on) dev.add_method('off',off) eng = Engine() eng.add_device(dev) #eng.run() eng.start()
def setup(): """ setup xAAL Engine & Device. And start it in a Greenlet""" helpers.setup_console_logger() global monitor engine = Engine() cfg = tools.load_cfg(PACKAGE_NAME) if not cfg: logger.info('Missing config file, building a new one') cfg = tools.new_cfg(PACKAGE_NAME) cfg.write() dev = Device("hmi.basic") dev.address = cfg['config']['addr'] dev.vendor_id = "IHSEV" dev.product_id = "WEB Interface" dev.version = 0.1 dev.info = "%s@%s" % (PACKAGE_NAME, platform.node()) engine.add_device(dev) db_server = None if 'db_server' in cfg['config']: db_server = cfg['config']['db_server'] else: logger.info('You can set "db_server" in the config file') monitor = Monitor(dev, filter_func=monitor_filter, db_server=db_server) monitor.subscribe(event_handler) engine.start() green_let = Greenlet(xaal_loop, engine) green_let.start()
def main(): if len(sys.argv) == 2: addr = sys.argv[1] if tools.is_valid_addr(addr): t0 = time.time() eng = Engine() eng.start() dev = QueryDB(eng) dev.query(addr) print("Time : %0.3f sec" % (time.time() - t0)) else: print("Invalid addr") else: usage()
def setup_xaal(): """ setup xAAL Engine & Device. And start it in a Greenlet""" global monitor engine = Engine() cfg = tools.load_cfg_or_die(PACKAGE_NAME) dev = Device("hmi.basic") dev.address = cfg['config']['addr'] dev.vendor_id = "IHSEV" dev.product_id = "REST API" dev.version = 0.1 dev.info = "%s@%s" % (PACKAGE_NAME, platform.node()) engine.add_device(dev) monitor = Monitor(dev, filter_func=monitor_filter) engine.start() green_let = Greenlet(xaal_loop, engine) green_let.start()
import time, random, sys from xaal.lib import Engine, Device, tools target = sys.argv[-1] dev = Device("switch.basic", tools.get_random_uuid()) eng = Engine() eng.start() while 1: eng.send_request(dev, [ target, ], 'dim', {'target': random.randint(0, 100)}) eng.loop() time.sleep(5) eng.send_request(dev, [ target, ], 'on') print('ON') eng.loop() time.sleep(3) eng.send_request(dev, [ target, ], 'off') print('OFF') eng.loop() time.sleep(3)