def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='rfxcom') # check if the plugin is configured. If not, this will stop the plugin and log an error if not self.check_configured(): return # get the devices list # for this plugin, if no devices are created we won't be able to use devices. # but.... if we stop the plugin right now, we won't be able to detect existing device and send events about them # so we don't stop the plugin if no devices are created self.devices = self.get_device_list(quit_if_no_device = False) # get the rfxcom device address in the filesystem self.rfxcom_device = self.get_config("rfxcom_device") self.rfxcom_manager = Rfxcom(self.log, self.send_xpl, self.get_stop(), self.rfxcom_device, self.device_detected, self.send_xpl, self.register_thread, self.options.test_option) # create listeners for commands send over xPL # type 11 - Lighting 2 Listener(self.process_ac_basic, self.myxpl, {'schema': 'ac.basic', 'xpltype': 'xpl-cmnd'}) # Open the RFXCOM device try: self.rfxcom_manager.open() except RfxcomException as e: self.log.error(e.value) print(e.value) self.force_leave() return # Start reading RFXCOM rfxcom_process = threading.Thread(None, self.rfxcom_manager.listen, "rfxcom-process-reader", (self.get_stop(),), {}) self.register_thread(rfxcom_process) rfxcom_process.start() self.ready()
class RfxcomManager(XplPlugin): """ Manage the RFXCOM usb device """ def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='rfxcom') # check if the plugin is configured. If not, this will stop the plugin and log an error if not self.check_configured(): return # get the devices list # for this plugin, if no devices are created we won't be able to use devices. # but.... if we stop the plugin right now, we won't be able to detect existing device and send events about them # so we don't stop the plugin if no devices are created self.devices = self.get_device_list(quit_if_no_device = False) # get the rfxcom device address in the filesystem self.rfxcom_device = self.get_config("rfxcom_device") self.rfxcom_manager = Rfxcom(self.log, self.send_xpl, self.get_stop(), self.rfxcom_device, self.device_detected, self.send_xpl, self.register_thread, self.options.test_option) # create listeners for commands send over xPL # type 11 - Lighting 2 Listener(self.process_ac_basic, self.myxpl, {'schema': 'ac.basic', 'xpltype': 'xpl-cmnd'}) # Open the RFXCOM device try: self.rfxcom_manager.open() except RfxcomException as e: self.log.error(e.value) print(e.value) self.force_leave() return # Start reading RFXCOM rfxcom_process = threading.Thread(None, self.rfxcom_manager.listen, "rfxcom-process-reader", (self.get_stop(),), {}) self.register_thread(rfxcom_process) rfxcom_process.start() self.ready() def send_xpl(self, message = None, schema = None, data = {}): """ Send xPL message on network """ if message != None: self.log.debug(u"send_xpl : send full message : {0}".format(message)) self.myxpl.send(message) else: self.log.debug(u"send_xpl : Send xPL message xpl-trig : schema:{0}, data:{1}".format(schema, data)) msg = XplMessage() msg.set_type("xpl-trig") msg.set_schema(schema) for key in data: msg.add_data({key : data[key]}) self.myxpl.send(msg) def process_ac_basic(self, message): """ Process command xpl message and call the librairy for processing command @param message : xpl message type 11 - Lighting 2 Example xPL messages: $ ./send.py xpl-cmnd ac.basic "address=0x0038abfe,unit=10,command=off" $ ./send.py xpl-cmnd ac.basic "address=0x0038abfe,unit=10,command=on" $ ./send.py xpl-cmnd ac.basic "address=0x0038abfe,unit=10,command=preset,level=1" """ address = message.data["address"].lower() unit = message.data["unit"] if unit.lower() == "group": unit = 0 group = True else: unit = int(unit) group = False command = message.data["command"].lower() if command == "preset": level = int(message.data["level"]) else: level = 0 if message.data.has_key("eu"): eu = message.data["eu"] else: eu = False # Prepare xpl-trig to send if success trig_msg = XplMessage() trig_msg.set_type("xpl-trig") trig_msg.set_schema("ac.basic") for key in message.data: trig_msg.add_data({key : message.data[key]}) # Use the rfxcom if self.rfxcom_manager.command_11(address, unit, command, level, eu, group, trig_msg): self.myxpl.send(trig_msg)
class RfxcomManager(XplPlugin): """ Manage the RFXCOM usb device """ def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='rfxcom') # check if the plugin is configured. If not, this will stop the plugin and log an error if not self.check_configured(): return # get the devices list # for this plugin, if no devices are created we won't be able to use devices. # but.... if we stop the plugin right now, we won't be able to detect existing device and send events about them # so we don't stop the plugin if no devices are created self.devices = self.get_device_list(quit_if_no_device = False) # get the rfxcom device address in the filesystem self.rfxcom_device = self.get_config("rfxcom_device") self.rfxcom_manager = Rfxcom(self.log, self.send_xpl, self.get_stop(), self.rfxcom_device, self.device_detected, self.send_xpl, self.register_thread, self.options.test_option) # create listeners for commands send over xPL # TODO # Open the RFXCOM device try: self.rfxcom_manager.open() except RfxcomException as e: self.log.error(e.value) print(e.value) self.force_leave() return # Start reading RFXCOM rfxcom_process = threading.Thread(None, self.rfxcom_manager.listen, "rfxcom-process-reader", (self.get_stop(),), {}) self.register_thread(rfxcom_process) rfxcom_process.start() self.ready() def send_xpl(self, message = None, schema = None, data = {}): """ Send xPL message on network """ if message != None: self.log.debug("send_xpl : send full message : {0}".format(message)) self.myxpl.send(message) else: self.log.debug("send_xpl : Send xPL message xpl-trig : schema:{0}, data:{1}".format(schema, data)) msg = XplMessage() msg.set_type("xpl-trig") msg.set_schema(schema) for key in data: msg.add_data({key : data[key]}) self.myxpl.send(msg)