cmd ='off' elif typ==DEVT['doorbell']: # simulate bell cmd = state hausc = '4cfa' # fixed hauscode for doorbell button prop = None else: cmd = state if cmd: cmd= fstls.FS20_command(hausc, devadr, cmd=cmd, dur=prop) self.serdev.send_message(cmd) return cmd if __name__ == "__main__": # for testing and discovering devices import asyncio logger = get_logger(__file__) conf={ # to be loaded from json file #"dbFile": "/mnt/extssd/storage/fs20store.sqlite" "dbFile": '~/fs20store.sqlite', "hausc":"1212", "100":{ "typ":0, "devadr":"1", "source":"zolder" }, "101":{ "typ":1, "devadr":"1", "source":"zolder" }, "102":{
logger.warning('no such quantity:%s' % quantity) async def setState(self, quantity, state, prop='bri'): if quantity in hueSampler.devdat: return await hueSampler.devdat[quantity].setState(prop, state) else: logger.warning('no such quantity:%s' % quantity) def semaphore(self): ''' to use to block concurrent http tasks ''' return HueBaseDef.Semaphore if __name__ == "__main__": import asyncio logger = get_logger(__file__, logging.INFO, logging.DEBUG) conf = { # to be loaded from json file "hueuser": "", "huebridge": "192.168.1.24", #"dbFile": "/mnt/extssd/storage/fs20store.sqlite" "dbFile": '~/fs20store.sqlite' } QCONF = { # example default configuration "570": { "source": "gang", "name": "gangSwitch", "devadr": "2", "typ": 12, "signal": "116=17,4cfa" }, "580": {
''' general purpose tool for drawing lines and shapes to pythonista uiImageView class''' import canvas import ui import sys from PIL import Image if '.' not in __name__: # =="__main__" or imported from same package sys.path.insert(0, '..') import plottls else: from pyploty import plottls import lib.tls as tls logger = tls.get_logger(__name__) IMGDRW = 1 # 1: use uiImageView TXTDRW = 0 # 1: draw txt directly on view class uiImage_context(plottls.xy_context): """ defines a rectangular drawing frame in a ui.view """ def __init__(self, uiImageView, *args, **kwargs): #world_frame=None, user_frame=None, font_name='Helvetica', font_size=16.0): self.uiImageView = uiImageView self.ctx = ui.ImageContext(uiImageView.width, uiImageView.height) logger.info("context:%s" % self.uiImageView.bounds) if IMGDRW: #ivfrm = uiImageView.superview.bounds #uiImageView.frame #wrld_frm = (ivfrm[0],ivfrm[1]+ivfrm[3], ivfrm[2],-ivfrm[3]) # chg origin to left under wrld_frm = (0, uiImageView.height, uiImageView.width, -uiImageView.height)
# import logging, time #import ui if '.' in __name__: # imported from higher level package from . import tls #logger = tls.get_logger() else: import sys sys.path.insert(0, '..') import lib.tls as tls # gives error when called from main package also using tls logger = tls.get_logger(__file__, logging.DEBUG) from lib import cbBle as cb, GATTclient #from pyploty.uiView_context import uiView_context chDIGI = 10 # func id for digitals chANA1ST = 11 # func id for first analog channel mdOUT = 0b00 # following GATT AIOS mdINP = 0b10 mdNOP = 0b11 anaDSCFACT = 10000 class AIOSclient(GATTclient.GATTclient): """ interfacing to device with BLE automation-IO profile """ bitvals = [] digmods = [] def __init__(self, *args, nAnaChans=3, **kwargs): """ """ self.nAnaChans = nAnaChans
grQuantIds="%s" % list(grQuantIds), evtData=json.dumps(evtData), **buildChart(jdats, ydats, qss, jdtill, ndays)) logger.debug("redraw page:(t:%s)\n%s\n" % (time.perf_counter() - tm, page)) return page #fall back to static as last @app.route('/<filepath:path>') def server_static(filepath): return bottle.static_file(filepath, root='./static/') if __name__ == '__main__': import socket logger = get_logger(__file__, logging.INFO, logging.DEBUG) config = devConfig(CONFFILE) dbfile = config.getItem('dbFile', dbfile) try: dbStore = sqlLogger(dbfile) dbStore.sources(minDaysBack=5) #logger.info("statistics:%s" % dbStore.statistics(5)) # will get list of quantities and sources logger.info('quantities:%s' % dbStore.items) for qk in dbStore.items: rec = dbStore.fetchlast(qk) logger.info("qkey:{}={}".format(qk, rec)) if config.hasItem('tailScale'): ip = config.getItem( 'tailScale') # ip accessible by world, issued by tailScale else: # ip of listening host
from lib.fsHapper import fsBridge from accessories.hue.hueHap import add_HUE_to_bridge from accessories.p1smart.p1DSMR_Hap import add_p1DSMR_to_bridge from accessories.fs20.fs20_hap import add_fs20_to_bridge from accessories.BLEAIOS.aiosHap import add_AIOS_to_bridge from accessories.netgear.netgear_HAP import add_WNDR_to_bridge from accessories.sounder.sounds import add_SND_to_bridge from lib.tls import get_logger __maintainer__ = "Henk Jan van Aalderen" __email__ = "*****@*****.**" __status__ = "Development" # setup logging for console and error log and generic log logger = get_logger(__file__, levelConsole=logging.INFO, levelLogfile=logging.INFO) logger.info('with HAP-python %s' % pyHAP_version) loop = asyncio.get_event_loop() # unique loop for application driver = AccessoryDriver(port=51826, loop=loop) # prevent renewing loop bridge = fsBridge(driver, 'fsBridge') add_SND_to_bridge(bridge, config=None) if os.path.isfile("config/aios.json"): add_AIOS_to_bridge(bridge, config="./config/aios.json") if os.path.isfile("config/deCONZ.json"): add_HUE_to_bridge(bridge, config="./config/deCONZ.json") if os.path.isfile("config/hue.json"): add_HUE_to_bridge(bridge, config="./config/hue.json") if os.path.isfile("config/fs20.json"):
def set_state(self, quantity, state, prop=None, dur=None): ''' stateSetter to set digio bit ''' ok = super().set_state(quantity, state, prop=prop) if prop: # and prop.isnumeric(): if dur: self.aios.setDigPulse(bitnr=int(prop), duration=dur) else: self.aios.setDigBit(bitnr=int(prop), val=state) return ok if __name__ == "__main__": # testing import asyncio DIGINPIN = 16 # PIR detector logger = get_logger(__file__) #logging.getLogger() # build a default config dict QCONF = { "%d" % (adr + aiosSampler.minqid): { "source": 'aios', "name": aiosAPI.NAMES[adr], "devadr": "%d" % adr, "typ": typ, "mask": DIGINPIN if adr == aiosAPI.chDIGI else None } for adr, typ in zip((aiosAPI.chTEMP, aiosAPI.chHUMI, aiosAPI.chECO2, aiosAPI.chTVOC, aiosAPI.chDIGI, aiosAPI.chANA1ST), (DEVT['temperature'], DEVT['humidity'], DEVT['ECO2'], DEVT['TVOC'], DEVT['DIGI'],
''' drawing charts to one of the context classes ''' import math import canvas if '.' not in __name__: # =="__main__" or imported from same package import sys sys.path.append('..') from pyploty import plottls from lib import tls logger = tls.get_logger(__file__) class xy_graph(object): def __init__(self, context, hold=True, grid=True): ''' context= canvas_context or uiView_context object having world set to a drawing area each yaxis side may have differen context ''' if type(context) is dict: self.context = context else: self.context = { 0: context } # graph to have different context for left and right yaxis self.hold = hold self.grid = grid self.axis_color = (0.40, 0.40, 0.40) self.datasets = [] for id, ctx in self.context.items(): self.set_bounds(*ctx.user.frame(), ctxId=id) def set_bounds(self, xmin, ymin, xsize, ysize, ctxId=0):
sampler = hue_happer(conf['huebridge'], conf['hueuser'], dbFile=conf['dbFile'], quantities=conf.itstore, minNr=1, maxNr=2, minDevPerc=0) #sampler.minqid=None # do not auto create bridge.add_sampler(sampler, conf.itstore) if __name__ == "__main__": """ run this for testing """ from lib.tls import get_logger logger = get_logger(__file__) try: driver = AccessoryDriver(port=51826) signal.signal(signal.SIGTERM, driver.signal_handler) bridge = fsBridge(driver, 'hueBridge') add_HUE_to_bridge(bridge, config="hue.json") driver.add_accessory(accessory=bridge) signal.signal(signal.SIGTERM, driver.signal_handler) driver.start() except Exception: logger.exception('ending hueHap') finally: