コード例 #1
0
ファイル: gw.py プロジェクト: baocaifeng/xAAL
def new_dev(gw, key, channel, addr, dtype):
    """ create e new xAAL device """
    dev = None
    if dtype == 'lamp':
        dev = Device("lamp.basic", addr)
        dev.product_id = "Lamp on HQ Product RF433 power relay"
        var = dev.new_attribute('light')
    else:
        dev = Device("powerrelay.basic", addr)
        dev.product_id = "HQ Product RF433 power relay"
        var = dev.new_attribute('power')

    dev.vendor_id = "JKX"
    dev.hw_id = '%s%s' % (key, channel)
    dev.version = 0.2
    dev.info = "%s@%s" % (PACKAGE_NAME, platform.node())

    # methods
    def on():
        if gw.switch_relay('ON', key, channel):
            var.value = True

    def off():
        if gw.switch_relay('OFF', key, channel):
            var.value = False

    dev.add_method('on', on)
    dev.add_method('off', off)
    return dev
コード例 #2
0
ファイル: devices.py プロジェクト: baocaifeng/xAAL
    def __init__(self,ipx,channel,addr,state_name,group):
        dev = Device("changeme.basic",addr)
        dev.vendor_id  = "IHSEV"
        dev.version    = 0.1
        dev.hw_id = channel
        dev.group_id = group
        
        # attribute
        self.state = dev.new_attribute(state_name)
        
        # method 
        dev.add_method('on',self.on)
        dev.add_method('off',self.off)

        self.chan = channel
        self.ipx = ipx 
        self.dev = dev