Example #1
0
 def __init__(self):
     XplPlugin.__init__(self, name='zwave')
     Listener(self.zwave_cmd_cb, self.myxpl, {
         'schema': 'zwave.basic',
         'xpltype': 'xpl-cmnd'
     })
     self._config = Query(self.myxpl, self.log)
     device = self._config.query('zwave', 'device')
     speed = self._config.query('zwave', 'speed')
     print(device, '  ', speed)
     #        device='/dev/ttyUSB0'
     self.myzwave = ZWave(device, speed, self.zwave_cb, self.log)
     self.myzwave.start()
     self.enable_hbeat()
     self.myzwave.send('Network Discovery')
     sleep(3)
Example #2
0
class Zwave(XplPlugin):
    def __init__(self):
        XplPlugin.__init__(self, name='zwave')
        Listener(self.zwave_cmd_cb, self.myxpl, {
            'schema': 'zwave.basic',
            'xpltype': 'xpl-cmnd'
        })
        self._config = Query(self.myxpl, self.log)
        device = self._config.query('zwave', 'device')
        speed = self._config.query('zwave', 'speed')
        print(device, '  ', speed)
        #        device='/dev/ttyUSB0'
        self.myzwave = ZWave(device, speed, self.zwave_cb, self.log)
        self.myzwave.start()
        self.enable_hbeat()
        self.myzwave.send('Network Discovery')
        sleep(3)

    def zwave_cmd_cb(self, message):
        if 'command' in message.data:
            cmd = message.data['command']
            node = message.data['node']
            if cmd == 'level':
                lvl = message.data['level']
                self.myzwave.send(cmd, node, lvl)
            else:
                self.myzwave.send(cmd, node)

    def zwave_cb(self, read):
        mess = XplMessage()
        if 'info' in read:
            self.log.error("Error : Node %s unreponsive" % read['node'])
        elif 'Find' in read:
            print("node enregistré : %s" % read['Find'])
        elif 'event' in read:
            mess.set_type('xpl-trig')
            mess.set_schema('zwave.basic')
            mess.add_data({
                'event': read['event'],
                'node': read['node'],
                'level': read['level']
            })
            self.myxpl.send(mess)
        elif 'command' in read and read['command'] == 'Info':
            print("Home ID is %s" % read['Home ID'])