def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='mirror') # Get config # - device self._config = Query(self.myxpl, self.log) device = self._config.query('mirror', 'device') # Init Mir:ror mirror = Mirror(self.log, self.send_xpl) # Open Mir:ror try: mirror.open(device) except MirrorException as e: self.log.error(e.value) print(e.value) self.force_leave() return # Start reading Mir:ror mirror_process = threading.Thread(None, mirror.listen, "mirror-process-reader", (self.get_stop(), ), {}) self.register_thread(mirror_process) mirror_process.start() self.enable_hbeat()
def __init__(self): """ Create lister for google agenda requets """ XplPlugin.__init__(self, name='gagenda') # Create logger self.log.debug("Listener for Google agenda created") # Get config self._config = Query(self.myxpl, self.log) self._email = self._config.query('gagenda', 'email') self._password = self._config.query('gagenda', 'password') self._calendar_name = self._config.query('gagenda', 'calendarname') # Create object self._gagenda_manager = GAgenda(self.log, \ self._email, \ self._password, \ self._calendar_name, \ self._broadcast_events) # Create listener for today Listener( self.gagenda_cb, self.myxpl, { 'schema': 'calendar.request', 'xpltype': 'xpl-cmnd', 'command': 'REQUEST' }) self.enable_hbeat()
def __init__(self): """ Create lister and launch bg listening """ try: XplPlugin.__init__(self, name = 'karotz') except: self.log.error("Error to create Karotz Xplplugin=%s" % (traceback.format_exc())) return self._config = Query(self.myxpl, self.log) self.instid = self._config.query('karotz', 'installid') self.lang = self._config.query('karotz', 'language') try: self.log.info("Starting library") self.karotz=Karotz(self.log,self.instid) self.log.info("Started") except: self.log.error("Error to create Karotz object=%s" % (traceback.format_exc())) return self.log.info("Creating listener for Karotz") Listener(self.xpl_command, self.myxpl, {'schema': 'karotz.basic', 'xpltype': 'xpl-cmnd'}) #self.add_stop_cb(self.stop) self.enable_hbeat() self.log.info("Plugin ready :)")
def __init__(self): """ Create the X10Main class This class is used to connect x10 (through heyu) to the xPL Network """ XplPlugin.__init__(self, name='x10_heyu') self._heyu_cfg_path_res = "" self._config = Query(self.myxpl, self.log) self._heyu_cfg_path_res = self._config.query('x10_heyu', 'heyu-cfg-path') try: self.__myx10 = X10API(self._heyu_cfg_path_res, self.log) except Exception: self.log.error("Something went wrong during heyu init, check logs") self.log.error("Exception : %s" % traceback.format_exc()) exit(1) #Create listeners Listener(self.x10_cmnd_cb, self.myxpl, { 'schema': 'x10.basic', 'xpltype': 'xpl-cmnd' }) #One listener for system schema, allowing to reload config #Listener(self.heyu_reload_config, self.myxpl, {'schema': 'domogik.system', 'xpltype': 'xpl-cmnd', # 'command': 'reload', 'plugin': 'x10'}) #One listener for system schema, allowing to dump config #Listener(self.heyu_dump_config, self.myxpl, {'schema': 'domogik.system', 'xpltype': 'xpl-cmnd', # 'command': 'push_config', 'plugin': 'x10'}) self.log.debug("before start X10monitor") self._monitor = X10Monitor(self._heyu_cfg_path_res) self._monitor.get_monitor().add_cb(self.x10_monitor_cb) self._monitor.get_monitor().start() self.enable_hbeat() self.log.debug("Heyu correctly started")
def __init__(self): ''' Start teleinfo device handler ''' XplPlugin.__init__(self, name='teleinfo') self._config = Query(self.myxpl, self.log) device = self._config.query('teleinfo', 'device') interval = self._config.query('teleinfo', 'interval') # Init Teleinfo teleinfo = Teleinfo(self.log, self.send_xpl) # Open Teleinfo modem try: teleinfo.open(device) except TeleinfoException as err: self.log.error(err.value) print(err.value) self.force_leave() return self.add_stop_cb(teleinfo.close) # Start reading Teleinfo teleinfo_process = threading.Thread(None, teleinfo.listen, 'teleinfo-listen', (float(interval),), {}) teleinfo_process.start() self.enable_hbeat()
def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='cidmodem') # Configuration self._config = Query(self.myxpl, self.log) device = self._config.query('cidmodem', 'device') cid_command = self._config.query('cidmodem', 'cid-command') # Init Modem cid = CallerIdModem(self.log, self.send_xpl) # Open Modem try: cid.open(device, cid_command) except CallerIdModemException as e: self.log.error(e.value) print(e.value) self.force_leave() return # Start reading Modem cid_process = threading.Thread(None, cid.listen, "listen_cid", (), {}) cid_process.start() self.enable_hbeat()
def __init__(self): # Connect to the socket XplPlugin.__init__(self, name = 'mochad') self.mochad_socket = None self._config = Query(self.myxpl, self.log) self.__host = self._config.query('mochad','mochad-host') self.__port = self._config.query('mochad','mochad-port') if self._config.query('mochad','cm15') == "True": self.__cm15 = True else: self.__cm15 = False if self._config.query('mochad','cm19') == "True": self.__cm19 = True else: self.__cm19 = False if self.__cm15: self.__itf = "pl" elif self.__cm19: self.__itf = "rf" self.connect() child_pid = os.fork() if child_pid == 0: self.listener() else: return None
def __init__(self, proxy_ip, proxy_port): """ Initiate properties Then, start HTTP server and give it initialized data @param proxy_ip : ip of the proxy server @param proxy_port : port of proxy server """ XplPlugin.__init__(self, name='proxy', reload_cb=self.reload_config) # logging initialization self.log.info("Proxy initialisation ...") self.log.debug("locale : %s %s" % locale.getdefaultlocale()) self._config = Query(self.myxpl, self.log) self.server = None self.server_process = None self.proxy_ip = None self.proxy_port = None self.use_ssl = False self.ssl_certificate = None self.server_ip = None self.server_port = None self.auth_method = None self.username = None self.password = None self.add_stop_cb(self.stop_http) self.enable_hbeat() self.reload_config()
def __init__(self): ''' Create the plcbusMain class This class is used to connect PLCBUS to the xPL Network ''' # Load config XplPlugin.__init__(self, name='plcbus') # Create listeners Listener(self._plcbus_cmnd_cb, self.myxpl, { 'schema': 'plcbus.basic', 'xpltype': 'xpl-cmnd', }) self._config = Query(self.myxpl, self.log) device = self._config.query('plcbus', 'device') self._usercode = self._config.query('plcbus', 'usercode') self._probe_inter = int(self._config.query('plcbus', 'probe-interval')) self._probe_list = self._config.query('plcbus', 'probe-list') # Create log instance self.api = PLCBUSAPI(self.log, device, self._command_cb, self._message_cb) self.add_stop_cb(self.api.stop) if self._probe_inter == 0: self.log.warning( "The probe interval has been set to 0. This is not correct. The plugin will use a probe interval of 5 seconds" ) self._probe_inter = 5 self._probe_status = {} self._probe_thr = XplTimer(self._probe_inter, self._send_probe, self.myxpl) self._probe_thr.start() # self.register_timer(self._probe_thr) self.enable_hbeat()
def __init__(self): """ Create lister for XBMC notifications """ XplPlugin.__init__(self, name='xbmc_not') # Create logger self.log.debug("Listener for XBMC notifications created") # Get configuration self._config = Query(self.myxpl, self.log) address = self._config.query('xbmc_not', 'address') delay = self._config.query('xbmc_not', 'delay') maxdelay = self._config.query('xbmc_not', 'maxdelay') self.log.debug("Config : address = " + address) self.log.debug("Config : delay = " + delay) self.log.debug("Config : maxdelay = " + maxdelay) # Create XBMCNotification object self.xbmc_notification_manager = XBMCNotification(self.log, address, delay, \ maxdelay) # Create listeners Listener(self.xbmc_notification_cb, self.myxpl, { 'schema': 'osd.basic', 'xpltype': 'xpl-cmnd' }) self.enable_hbeat() self.enable_hbeat()
def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='velbus') self._config = Query(self.myxpl, self.log) # get the config values device_type = self._config.query('velbus', 'connection-type') if device_type == None: self.log.error('Devicetype is not configured, exitting') print('Devicetype is not configured, exitting') self.force_leave() return device = self._config.query('velbus', 'device') #device = '192.168.1.101:3788' if device == None: self.log.error('Device is not configured, exitting') print('Device is not configured, exitting') self.force_leave() return # validate the config vars if (device_type != 'serial') and (device_type != 'socket'): self.log.error('Devicetype must be socket or serial, exitting') print('Devicetype must be socket or serial, exitting') self.force_leave() return if device_type == 'socket' and not re.match('[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}:[0-9]+', device): self.log.error('A socket device is in the form of <ip>:<port>, exitting') print('A socket device is in the form of <ip>:<port>, exitting') self.force_leave() return # Init RFXCOM self.manager = VelbusDev(self.log, self.send_xpl, self.send_trig, self.get_stop()) self.add_stop_cb(self.manager.close) # Create a listener for all messages used by RFXCOM Listener(self.process_lighting_basic, self.myxpl, {'xpltype': 'xpl-cmnd', 'schema': 'lighting.basic'}) Listener(self.process_shutter_basic, self.myxpl, {'xpltype': 'xpl-cmnd', 'schema': 'shutter.basic'}) # Create listeners try: self.manager.open(device, device_type) except VelbusException as ex: self.log.error(ex.value) self.force_leave() return self.manager.scan() # Start reading RFXCOM listenthread = threading.Thread(None, self.manager.listen, "velbus-process-reader", (self.get_stop(),), {}) self.register_thread(listenthread) listenthread.start() self.enable_hbeat()
def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='yweather') # Get config self._config = Query(self.myxpl, self.log) unit = self._config.query('yweather', 'unit') if unit == None: self.log.error("Unit not configured : exiting") print("Unit not configured : exiting") self.force_leave() return unit = unit.lower() self.enable_current = self._config.query('yweather', 'en-current') self.enable_previsionnal = self._config.query('yweather', 'en-prev') self.cities = {} num = 1 loop = True while loop == True: city_code = self._config.query('yweather', 'city-%s' % str(num)) device = self._config.query('yweather', 'device-%s' % str(num)) if city_code != None: self.cities[city_code] = {"device": device} num = num + 1 else: loop = False # Open weather for cities for city in self.cities: self.cities[city]["obj"] = YWeather(self.log, self.send_xpl) try: self.log.info("Init weather for '%s'" % city) self.cities[city]["obj"].open(city, unit, self.cities[city]["device"]) except YWeatherException as err: self.log.error(err.value) print(err.value) self.force_leave() return # Start listening for weather for city in self.cities: try: self.log.info("Start listening weather for '%s'" % city) self._listen_thr = XplTimer(TIME_BETWEEN_EACH_WEATHER_READ, \ self.cities[city]["obj"].get, \ self.myxpl) self._listen_thr.start() self.enable_hbeat() except YWeatherException as err: self.log.error(err.value) print(err.value) self.force_leave() return self.enable_hbeat()
def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='rfxcom') # Get config # - device self._config = Query(self.myxpl, self.log) device = self._config.query('rfxcom', 'device') if device == None: self.log.error('Device is not configured, exiting') print('Device is not configured, exiting') self.force_leave() return # Init RFXCOM self.rfxcom = RfxcomUsb(self.log, self.send_xpl, self.send_trig, self.get_stop()) # Create a listener for all messages used by RFXCOM # TODO !!!!! # Create listeners Listener(self.process_x10_basic, self.myxpl, { 'schema': 'x10.basic', 'xpltype': 'xpl-cmnd' }) Listener(self.process_x10_security, self.myxpl, { 'schema': 'x10.securiy', 'xpltype': 'xpl-cmnd' }) Listener(self.process_ac_basic, self.myxpl, { 'schema': 'ac.basic', 'xpltype': 'xpl-cmnd' }) Listener(self.process_remote_basic, self.myxpl, { 'schema': 'remote.basic', 'xpltype': 'xpl-cmnd' }) Listener(self.process_control_basic, self.myxpl, { 'schema': 'control.basic', 'xpltype': 'xpl-cmnd' }) # Open RFXCOM try: self.rfxcom.open(device) 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.listen, "rfxcom-process-reader", (self.get_stop(), ), {}) self.register_thread(rfxcom_process) rfxcom_process.start() self.enable_hbeat()
def __init__(self): """ Create listener for Foscam Relay """ XplPlugin.__init__(self, name='foscam') self._config = Query(self.myxpl, self.log) # Configuration : list of cameras self.cameras = {} num = 1 loop = True while loop == True: #Get each camera settings name = self._config.query('foscam', 'name-%s' % str(num)) ip = self._config.query('foscam', 'ip-%s' % str(num)) port = self._config.query('foscam', 'port-%s' % str(num)) user = self._config.query('foscam', 'user-%s' % str(num)) password = self._config.query('foscam', 'password-%s' % str(num)) delay = self._config.query('foscam', 'delay-%s' % str(num)) if port == None: port = 80 if user == None: user = "" if password == None: password = "" if delay == None: delay = 0 if name != None: self.log.info( "Configuration : name=%s, ip=%s, port=%s, user=%s, password=No_Log, delay=%s" % (name, ip, port, user, delay)) self.cameras[name] = { "ip": ip, "port": port, "user": user, "password": password, "delay": delay } else: loop = False num += 1 ### Create FOSCAM object self._foscammanager = RELAY(self.log) # Create listeners Listener(self.foscam_command, self.myxpl, { 'schema': 'control.basic', 'xpltype': 'xpl-cmnd', 'type': 'output' }) self.log.info("Listener for Foscam relay created") #print ("Listener for Foscam relay created") self.enable_hbeat()
class XBMCNotificationListener(XplPlugin): """ Create listener for xPL messages about xbmc notifications """ def __init__(self): """ Create lister for XBMC notifications """ XplPlugin.__init__(self, name='xbmc_not') # Create logger self.log.debug("Listener for XBMC notifications created") # Get configuration self._config = Query(self.myxpl, self.log) address = self._config.query('xbmc_not', 'address') delay = self._config.query('xbmc_not', 'delay') maxdelay = self._config.query('xbmc_not', 'maxdelay') self.log.debug("Config : address = " + address) self.log.debug("Config : delay = " + delay) self.log.debug("Config : maxdelay = " + maxdelay) # Create XBMCNotification object self.xbmc_notification_manager = XBMCNotification(self.log, address, delay, \ maxdelay) # Create listeners Listener(self.xbmc_notification_cb, self.myxpl, { 'schema': 'osd.basic', 'xpltype': 'xpl-cmnd' }) self.enable_hbeat() self.enable_hbeat() def xbmc_notification_cb(self, message): """ Call XBMC notification lib @param message : message to send """ self.log.debug("Call xbmc_notification_cb") if 'command' in message.data: command = message.data['command'] if 'text' in message.data: text = message.data['text'] if 'row' in message.data: row = message.data['row'] if 'delay' in message.data: delay = message.data['delay'] self.log.debug("Call _notify") self.xbmc_notification_manager.notify(command, text, row, delay)
class Mochad(XplPlugin): def __init__(self): # Connect to the socket XplPlugin.__init__(self, name = 'mochad') self.mochad_socket = None self._config = Query(self.myxpl, self.log) self.__host = self._config.query('mochad','mochad-host') self.__port = self._config.query('mochad','mochad-port') if self._config.query('mochad','cm15') == "True": self.__cm15 = True else: self.__cm15 = False if self._config.query('mochad','cm19') == "True": self.__cm19 = True else: self.__cm19 = False if self.__cm15: self.__itf = "pl" elif self.__cm19: self.__itf = "rf" self.connect() child_pid = os.fork() if child_pid == 0: self.listener() else: return None def connect(self): for res in socket.getaddrinfo(self.__host, self.__port, socket.AF_UNSPEC, socket.SOCK_STREAM): af, socktype, proto, canonname, sa = res try: self.mochad_socket = socket.socket(af, socktype, proto) except socket.error, msg: self.mochad_socket = None continue try: self.mochad_socket.connect(sa) except socket.error, msg: self.mochad_socket.close() self.mochad_socket = None continue break
def __init__(self): """ Create the lighting class """ XplPlugin.__init__(self, name='lighting') self.log.debug("lighting.__init__ : Start ...") self._config = Query(self.myxpl, self.log) self.log.debug("lighting.__init__ : Try to get configuration from XPL") try: #self.use_cron = bool(self._config.query('lighting', 'usecron')) self.broadcast = bool(self._config.query('lighting', 'broadcast')) #self.presence = bool(self._config.query('lighting', 'presence')) except: error = "Can't get configuration from XPL : %s" % \ (traceback.format_exc()) self.log.exception("lighting.__init__ : " + error) #self.use_cron = True self.broadcast = True #self.presence = True raise LightingException(error) self.log.debug( "lighting.__init__ : Try to start the lighting librairy") try: self._mylighting = LightingAPI(self.broadcast, \ self.myxpl, self.log, self.get_data_files_directory()) except: error = "Something went wrong during lightingAPI init : %s" % \ (traceback.format_exc()) self.log.error("lighting.__init__ : " + error) self.force_leave() raise LightingException(error) self.log.debug("lighting.__init__ : Try to create listeners") Listener(self.lighting_config_cmnd, self.myxpl, { 'schema': 'lighting.config', 'xpltype': 'xpl-cmnd' }) Listener(self.lighting_basic_cmnd, self.myxpl, { 'schema': 'lighting.basic', 'xpltype': 'xpl-cmnd' }) # Listener(self.lighting_basic_trig, self.myxpl, # {'schema': 'lighting.basic', 'xpltype': 'xpl-trig'}) self.enable_hbeat() self._mylighting.reload_config() self.log.info("Plugin lighting correctly started.")
def __init__(self): ''' Create the plcbusMain class This class is used to connect PLCBUS to the xPL Network ''' # Load config XplPlugin.__init__(self, name = 'plcbus') # Create listeners Listener(self._plcbus_cmnd_cb, self.myxpl, { 'schema': 'plcbus.basic', 'xpltype': 'xpl-cmnd', }) self._config = Query(self.myxpl, self.log) device = self._config.query('plcbus', 'device') self._usercode = self._config.query('plcbus', 'usercode') self._probe_inter = int( self._config.query('plcbus', 'probe-interval')) self._probe_list = self._config.query('plcbus', 'probe-list') # Create log instance self.api = PLCBUSAPI(self.log, device, self._command_cb, self._message_cb) self.add_stop_cb(self.api.stop) if self._probe_inter == 0: self.log.warning("The probe interval has been set to 0. This is not correct. The plugin will use a probe interval of 5 seconds") self._probe_inter = 5 self._probe_status = {} self._probe_thr = XplTimer(self._probe_inter, self._send_probe, self.myxpl) self._probe_thr.start() # self.register_timer(self._probe_thr) self.enable_hbeat()
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 __init__(self, proxy_ip, proxy_port): """ Initiate properties Then, start HTTP server and give it initialized data @param proxy_ip : ip of the proxy server @param proxy_port : port of proxy server """ XplPlugin.__init__(self, name = 'proxy', reload_cb = self.reload_config) # logging initialization self.log.info("Proxy initialisation ...") self.log.debug("locale : %s %s" % locale.getdefaultlocale()) self._config = Query(self.myxpl, self.log) self.server = None self.server_process = None self.proxy_ip = None self.proxy_port = None self.use_ssl = False self.ssl_certificate = None self.server_ip = None self.server_port = None self.auth_method = None self.username = None self.password = None self.add_stop_cb(self.stop_http) self.enable_hbeat() self.reload_config()
def __init__(self): """ Create the bluez plugin. """ XplPlugin.__init__(self, name='bluez') self.log.info("__init__ : Start ...") self.config = Query(self.myxpl, self.log) self.log.debug("__init__ : Try to start the bluez API") try: self._bluez = BluezAPI(self.log, self.config, self.myxpl, \ self.get_stop()) except: error = "Something went wrong during bluezAPI init : %s" % \ (traceback.format_exc()) self.log.error("__init__ : " + error) self.log.debug("__init__ : Try to create listeners") Listener(self.basic_cmnd_cb, self.myxpl, { 'schema': 'bluez.basic', 'xpltype': 'xpl-cmnd' }) self.add_stop_cb(self._bluez.stop_all) #self.enable_helper() self.enable_hbeat() self._bluez.start_adaptator() self.log.info("Plugin bluez correctly started.")
def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='mirror') # Get config # - device self._config = Query(self.myxpl, self.log) device = self._config.query('mirror', 'device') # Init Mir:ror mirror = Mirror(self.log, self.send_xpl) # Open Mir:ror try: mirror.open(device) except MirrorException as e: self.log.error(e.value) print(e.value) self.force_leave() return # Start reading Mir:ror mirror_process = threading.Thread(None, mirror.listen, "mirror-process-reader", (self.get_stop(),), {}) self.register_thread(mirror_process) mirror_process.start() self.enable_hbeat()
def __init__(self): """ Create the X10Main class This class is used to connect x10 (through heyu) to the xPL Network """ XplPlugin.__init__(self, name = 'x10_heyu') self._heyu_cfg_path_res = "" self._config = Query(self.myxpl, self.log) self._heyu_cfg_path_res = self._config.query('x10_heyu', 'heyu-cfg-path') try: self.__myx10 = X10API(self._heyu_cfg_path_res, self.log) except Exception: self.log.error("Something went wrong during heyu init, check logs") self.log.error("Exception : %s" % traceback.format_exc()) exit(1) #Create listeners Listener(self.x10_cmnd_cb, self.myxpl, {'schema': 'x10.basic', 'xpltype': 'xpl-cmnd'}) #One listener for system schema, allowing to reload config #Listener(self.heyu_reload_config, self.myxpl, {'schema': 'domogik.system', 'xpltype': 'xpl-cmnd', # 'command': 'reload', 'plugin': 'x10'}) #One listener for system schema, allowing to dump config #Listener(self.heyu_dump_config, self.myxpl, {'schema': 'domogik.system', 'xpltype': 'xpl-cmnd', # 'command': 'push_config', 'plugin': 'x10'}) self.log.debug("before start X10monitor") self._monitor = X10Monitor(self._heyu_cfg_path_res) self._monitor.get_monitor().add_cb(self.x10_monitor_cb) self._monitor.get_monitor().start() self.enable_hbeat() self.log.debug("Heyu correctly started")
def __init__(self): """ Create lister for google agenda requets """ XplPlugin.__init__(self, name = 'gagenda') # Create logger self.log.debug("Listener for Google agenda created") # Get config self._config = Query(self.myxpl, self.log) self._email = self._config.query('gagenda', 'email') self._password = self._config.query('gagenda', 'password') self._calendar_name = self._config.query('gagenda', 'calendarname') # Create object self._gagenda_manager = GAgenda(self.log, \ self._email, \ self._password, \ self._calendar_name, \ self._broadcast_events) # Create listener for today Listener(self.gagenda_cb, self.myxpl, {'schema': 'calendar.request', 'xpltype': 'xpl-cmnd', 'command': 'REQUEST'}) self.enable_hbeat()
def __init__(self): """ Init manager """ XplPlugin.__init__(self, name = 'sms') # Configuration self._config = Query(self.myxpl, self.log) login = self._config.query('sms', 'login') password = self._config.query('sms', 'password') phone = self._config.query('sms', 'phone') operator = self._config.query('sms', 'operator') operator = operator.lower() if (operator == "orange"): from domogik_packages.xpl.lib.sms_orange import Sms if (operator == "sfr"): from domogik_packages.xpl.lib.sms_sfr import Sms if (operator == "bouygues"): from domogik_packages.xpl.lib.sms_bouygues import Sms self.log.debug("Init info for sms created") ### Create Sms objects self.my_sms = Sms(self.log,login,password,phone) self.log.debug("Create object for sms created") # Create listener Listener(self.sms_cb, self.myxpl, {'schema': 'sendmsg.basic','xpltype': 'xpl-cmnd'}) self.log.debug("Listener for sms created") self.enable_hbeat()
def __init__(self): """ Create the X10Main class This class is used to connect x10 (through cm15a) to the xPL Network """ XplPlugin.__init__(self, name='x10cm15a') self.log.error("Cm15a correctly started") self._device = "/dev/cm15a0" # self._config = Query(self.myxpl, self.log) # self._device = self._config.query('cm15a', 'cm15a-path') if not os.path.exists(self._device): self.log.error(self._device + " is not present") else: self.log.debug("device present as " + self._device) self._config = Query(self.myxpl, self.log) try: self.__myx10 = X10API(self._device, self.log) except Exception: self.log.error( "Something went wrong during cm15a init, check logs") self.log.error("Exception : %s" % traceback.format_exc()) exit(1) #Create listeners Listener(self.x10_cmnd_cb, self.myxpl, { 'schema': 'x10.basic', 'xpltype': 'xpl-cmnd' }) self.log.debug("Sending hbeat") self.enable_hbeat() self.log.debug("Cm15a correctly started")
def __init__(self): """ Create the tsChacon class This class is used to connect chacon devices (through TellSitck) to the xPL Network """ XplPlugin.__init__(self, name='tschacon') self.log.debug("tschacon correctly started") self._device = "/dev/tellstick" #Check if the device exists if not os.path.exists(self._device): self.log.error(self._device + " is not present") else: self.log.debug("device present as " + self._device) self._config = Query(self.myxpl, self.log) try: self.__mytellstick = TellStick() except Exception: self.log.error( "Something went wrong during TellStick init, check logs") self.log.error("Exception : %s" % traceback.format_exc()) exit(1) #Create listeners Listener(self.tsChacon_cmnd_cb, self.myxpl, { 'schema': 'ts.arctech', 'xpltype': 'xpl-cmnd' }) self.enable_hbeat() self.log.debug("tschacon plugin correctly started")
def __init__(self): """ Init manager """ XplPlugin.__init__(self, name='gceusbrb') # Configuration : list of relayboard self.relayboards = {} num = 1 loop = True self._config = Query(self.myxpl, self.log) while loop == True: name = self._config.query('gceusbrb', 'rb-%s-name' % str(num)) device = self._config.query('gceusbrb', 'rb-%s-device' % str(num)) if name != None: self.log.info("Configuration : name=%s, device=%s" % (name, device)) self.relayboards[name] = {"device": device} else: loop = False num += 1 ### Create Relayboardusb objects ex.SamsungTV for relayboard in self.relayboards: self.relayboards[relayboard]['obj'] = Relayboardusb( self.log, self.send_xpl) try: self.log.info( "Opening RelayBoard named '%s' (device : %s)" % (relayboard, self.relayboards[relayboard]['device'])) self.relayboards[relayboard]['obj'].open( self.relayboards[relayboard]['device'], relayboard) except RelayboardusbException as err: self.log.error(err.value) print err.value self.force_leave() return # Create listener Listener(self.relayboard_cb, self.myxpl, { 'schema': 'control.basic', 'xpltype': 'xpl-cmnd', 'type': 'output' }) self.log.debug("Listener for gceusbrb created") self.enable_hbeat() self.log.info("RB Plugin ready :)")
class CIDManager(XplPlugin): """ Manage the modem to get CID """ def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='cidmodem') # Configuration self._config = Query(self.myxpl, self.log) device = self._config.query('cidmodem', 'device') cid_command = self._config.query('cidmodem', 'cid-command') # Init Modem cid = CallerIdModem(self.log, self.send_xpl) # Open Modem try: cid.open(device, cid_command) except CallerIdModemException as e: self.log.error(e.value) print(e.value) self.force_leave() return # Start reading Modem cid_process = threading.Thread(None, cid.listen, "listen_cid", (), {}) cid_process.start() self.enable_hbeat() def send_xpl(self, num): """ Send xPL message on network @param num : call number """ print("Input call : %s " % num) msg = XplMessage() msg.set_type("xpl-trig") msg.set_schema("cid.basic") msg.add_data({"calltype" : "INBOUND"}) msg.add_data({"phone" : num}) self.myxpl.send(msg)
def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='yweather') # Get config self._config = Query(self.myxpl, self.log) unit = self._config.query('yweather', 'unit' ) if unit == None: self.log.error("Unit not configured : exiting") print("Unit not configured : exiting") self.force_leave() return unit = unit.lower() self.enable_current = self._config.query('yweather', 'en-current' ) self.enable_previsionnal = self._config.query('yweather', 'en-prev' ) self.cities = {} num = 1 loop = True while loop == True: city_code = self._config.query('yweather', 'city-%s' % str(num)) device = self._config.query('yweather', 'device-%s' % str(num)) if city_code != None: self.cities[city_code] = { "device" : device } num = num + 1 else: loop = False # Open weather for cities for city in self.cities: self.cities[city]["obj"] = YWeather(self.log, self.send_xpl) try: self.log.info("Init weather for '%s'" % city) self.cities[city]["obj"].open(city, unit, self.cities[city]["device"]) except YWeatherException as err: self.log.error(err.value) print(err.value) self.force_leave() return # Start listening for weather for city in self.cities: try: self.log.info("Start listening weather for '%s'" % city) self._listen_thr = XplTimer(TIME_BETWEEN_EACH_WEATHER_READ, \ self.cities[city]["obj"].get, \ self.myxpl) self._listen_thr.start() self.enable_hbeat() except YWeatherException as err: self.log.error(err.value) print(err.value) self.force_leave() return self.enable_hbeat()
def __init__(self): """ Init manager """ XplPlugin.__init__(self, name='tv_samsg') # Configuration : list of televisions self.televisions = {} num = 1 loop = True self._config = Query(self.myxpl, self.log) while loop == True: name = self._config.query('tv_samsg', 'tv-%s-name' % str(num)) device = self._config.query('tv_samsg', 'tv-%s-device' % str(num)) if name != None: self.log.info("Configuration : name=%s, device=%s" % (name, device)) self.televisions[name] = {"device": device} else: loop = False num += 1 ### Create SamsungTV objects for television in self.televisions: self.televisions[television]['obj'] = SamsungTV(self.log) try: self.log.info( "Opening Samsung Television named '%s' (device : %s)" % (television, self.televisions[television]['device'])) self.televisions[television]['obj'].open( self.televisions[television]['device']) except SamsungTVException as err: self.log.error(err.value) print(err.value) self.force_leave() return # Create listener Listener(self.television_cb, self.myxpl, { 'schema': 'control.basic', 'xpltype': 'xpl-cmnd', 'type': 'television' }) self.log.debug("Listener for tv_samsg created") self.enable_hbeat()
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'])
def __init__(self): """ Create lister and launch bg listening """ XplPlugin.__init__(self, name = 'zibase') self._config = Query(self.myxpl, self.log) self.address = self._config.query('zibase', 'ip') self.inter = self._config.query('zibase', 'interface') self.port = int(self._config.query('zibase', 'port')) self.valvar=self._config.query('zibase', 'envar') self.interv=int(self._config.query('zibase', 'interv')) self.log.info("Creating listener for ZiBase") Listener(self.zibase_command, self.myxpl, {'schema': 'zibase.basic', 'xpltype': 'xpl-cmnd'}) try: self.ip_host=get_ip_address(self.inter) self.log.debug("Adress IP Host=%s" % (self.ip_host)) except: self.log.error("IP Host not found=%s" % (traceback.format_exc())) return try: self.api = APIZiBase(self.log,self.address) except: self.log.error("API ZiBase error=%s" % (traceback.format_exc())) return try: self.th=ServerZiBase(self.log,self.ip_host,self.port,self.myxpl) self.th.start() except: self.log.error("Server ZiBase error=%s" % (traceback.format_exc())) self.stop() try: self.api.Connect(self.ip_host,self.port) except: self.log.error("Connection ZiBase error=%s" % (traceback.format_exc())) self.stop() if self.valvar=="True" : try: self.log.info("Start reading internal variables") var_read=XplTimer(self.interv,self.zibase_read_var,self.myxpl) var_read.start() except: self.log.error("reading internal variables error") return self.add_stop_cb(self.stop) self.enable_hbeat() self.log.info("Plugin ready :)")
def __init__(self): """ Init manager """ XplPlugin.__init__(self, name = 'tts') # Configuration self._config = Query(self.myxpl, self.log) software = self._config.query('tts', 'software') self.log.debug("Init info for tts created") ### Create tts objects self.my_tts = Tts(self.log, software) self.log.debug("Create object for tts created") # Create listener Listener(self.tts_cb, self.myxpl, {'schema': 'tts.basic','xpltype': 'xpl-cmnd'}) self.log.debug("Listener for tts created") self.enable_hbeat()
class CIDManager(XplPlugin): """ Manage the modem to get CID """ def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='cidmodem') # Configuration self._config = Query(self.myxpl, self.log) device = self._config.query('cidmodem', 'device') cid_command = self._config.query('cidmodem', 'cid-command') # Init Modem cid = CallerIdModem(self.log, self.send_xpl) # Open Modem try: cid.open(device, cid_command) except CallerIdModemException as e: self.log.error(e.value) print(e.value) self.force_leave() return # Start reading Modem cid_process = threading.Thread(None, cid.listen, "listen_cid", (), {}) cid_process.start() self.enable_hbeat() def send_xpl(self, num): """ Send xPL message on network @param num : call number """ print("Input call : %s " % num) msg = XplMessage() msg.set_type("xpl-trig") msg.set_schema("cid.basic") msg.add_data({"calltype": "INBOUND"}) msg.add_data({"phone": num}) self.myxpl.send(msg)
def __init__(self): """ Create listener and background zwave manager """ XplHlpPlugin.__init__(self, name = 'ozwave') # Récupère la config # - device self._config = Query(self.myxpl, self.log) device = self._config.query('ozwave', 'device') ozwlogConf = self._config.query('ozwave', 'ozwlog') self._config = Query(self.myxpl, self.log) print ('Mode log openzwave :', ozwlogConf) # Recupère l'emplacement des fichiers de configuration OZW pathUser = self.get_data_files_directory() +'/' pathConfig = self._config.query('ozwave', 'configpath') + '/' # Initialise le manager Open zwave try: self.myzwave = OZWavemanager(self._config, self.send_xPL, self.sendxPL_trig, self.get_stop(), self.log, configPath = pathConfig, userPath = pathUser, ozwlog = ozwlogConf) except OZwaveException as e: self.log.error(e.value) print e.value self.force_leave() return self.log.debug("__init__ : Enable heplers") self.helpers = \ { "infostate" : { "cb" : self.myzwave.GetPluginInfo, "desc" : "Show Info status. Experimental.", "usage" : "memory", } } self.enable_helper() # Crée le listener pour les messages de commande xPL traités par les devices zwave Listener(self.ozwave_cmd_cb, self.myxpl,{'schema': 'ozwave.basic', 'xpltype': 'xpl-cmnd'}) # Validation avant l'ouverture du controleur, la découverte du réseaux zwave prends trop de temps -> RINOR Timeout self.add_stop_cb(self.myzwave.stop) self.enable_hbeat() # Ouverture du controleur principal self.myzwave.openDevice(device)
def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='rfxcom') # Get config # - device self._config = Query(self.myxpl, self.log) device = self._config.query('rfxcom', 'device') if device == None: self.log.error('Device is not configured, exiting') print('Device is not configured, exiting') self.force_leave() return # Init RFXCOM self.rfxcom = RfxcomUsb(self.log, self.send_xpl, self.send_trig, self.get_stop()) # Create a listener for all messages used by RFXCOM # TODO !!!!! # Create listeners Listener(self.process_x10_basic, self.myxpl, {'schema': 'x10.basic', 'xpltype': 'xpl-cmnd'}) Listener(self.process_x10_security, self.myxpl, {'schema': 'x10.securiy', 'xpltype': 'xpl-cmnd'}) Listener(self.process_ac_basic, self.myxpl, {'schema': 'ac.basic', 'xpltype': 'xpl-cmnd'}) Listener(self.process_remote_basic, self.myxpl, {'schema': 'remote.basic', 'xpltype': 'xpl-cmnd'}) Listener(self.process_control_basic, self.myxpl, {'schema': 'control.basic', 'xpltype': 'xpl-cmnd'}) # Open RFXCOM try: self.rfxcom.open(device) 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.listen, "rfxcom-process-reader", (self.get_stop(),), {}) self.register_thread(rfxcom_process) rfxcom_process.start() self.enable_hbeat()
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'])
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 __init__(self): """ Create listener for Android push notification """ XplPlugin.__init__(self, name = 'apushnot') # Create logger self.log.debug("Listener for Android push notification created") # Configuration : list of recipient and source key self.alias_list = {} num = 1 loop = True self._config = Query(self.myxpl, self.log) while loop == True: recipient = self._config.query('apushnot', 'name-%s' % str(num)) source = self._config.query('apushnot', 'source-%s' % str(num)) dfltitle = self._config.query('apushnot', 'default-title-%s' % str(num)) if recipient != None: mess="Configuration : recipient=" + str(recipient) + " , source=" + str(source) + ", default title=" + str(dfltitle) self.log.info(mess) print(mess) self.alias_list[recipient] = {"recipient" : recipient, "source" : source, "dfltitle" : dfltitle} num += 1 else: loop = False # no recipient configured if num == 1: msg = "No recipient configured. Exiting plugin" self.log.info(msg) print(msg) self.force_leave() return # Check title for alias in self.alias_list: if str(self.alias_list[alias]['dfltitle']) != "None": self.log.debug("default title for recipient " + str(self.alias_list[alias]['recipient']) + " is " + str(self.alias_list[alias]['dfltitle'])) else: self.log.error("Can't find the default title for the recipient " + str(self.alias_list[alias]['recipient']) + " , please check the configuration page of this plugin") self.force_leave() return # Create APushNotification object self.apn_notification_manager = APushNotification(self.log) # Create listeners Listener(self.apn_notification_cb, self.myxpl, {'schema': 'sendmsg.push', 'xpltype': 'xpl-cmnd'}) self.enable_hbeat()
def __init__(self): """ Create the cron class """ XplHlpPlugin.__init__(self, name='cron') self.log.debug("__init__ : Start ...") self.config = Query(self.myxpl, self.log) continue_boot = False self.log.debug("__init__ : Try to start the cron API") try: self._cron = CronAPI(self.log, self.config, self.myxpl, \ self.get_data_files_directory(), self.get_stop()) except: self.force_leave() error = "Something went wrong during cronAPI init : %s" % \ (traceback.format_exc()) self.log.error("__init__ : " + error) return self.log.debug("__init__ : Enable heplers") self.helpers = \ { "memory" : { "cb" : self._cron.helpers.helper_memory, "desc" : "Show memory usage of variables. Experimental.", "usage" : "memory", } } self.enable_helper() self.log.debug("__init__ : Try to create listeners") Listener(self.request_cmnd_cb, self.myxpl, { 'schema': 'timer.request', 'xpltype': 'xpl-cmnd' }) Listener(self.basic_cmnd_cb, self.myxpl, { 'schema': 'timer.basic', 'xpltype': 'xpl-cmnd' }) self.add_stop_cb(self._cron.stop_all) self.log.debug("__init__ : Enable the heartbeat") self.enable_hbeat() self.log.info("Plugin cron correctly started.")
class MirrorManager(XplPlugin): """ Manage the Mir:ror device and connect it to xPL """ def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='mirror') # Get config # - device self._config = Query(self.myxpl, self.log) device = self._config.query('mirror', 'device') # Init Mir:ror mirror = Mirror(self.log, self.send_xpl) # Open Mir:ror try: mirror.open(device) except MirrorException as e: self.log.error(e.value) print(e.value) self.force_leave() return # Start reading Mir:ror mirror_process = threading.Thread(None, mirror.listen, "mirror-process-reader", (self.get_stop(),), {}) self.register_thread(mirror_process) mirror_process.start() self.enable_hbeat() def send_xpl(self, device, type, current): """ Send xPL message on network """ print("device:%s, type:%s, current:%s" % (device, type, current)) msg = XplMessage() msg.set_type("xpl-trig") msg.set_schema("sensor.basic") msg.add_data({"device" : device}) msg.add_data({"type" : type}) msg.add_data({"current" : current}) self.myxpl.send(msg)
def __init__(self): """ Create the mvhr class """ XplHlpPlugin.__init__(self, name = 'mvhr') self.log.info("mvhr.__init__ : Start ...") self.config = Query(self.myxpl, self.log) self.log.debug("mvhr.__init__ : Try to start the mvhr library") try: self._mymvhr = HvacMvhr(self.config, self.log, self.myxpl) except: error = "Something went wrong during mvhrAPI init : %s" % \ (traceback.format_exc()) self.log.exception("mvhr.__init__ : "+error) self.log.debug("mvhr.__init__ : Try to create listeners") Listener(self.mvhr_request_cmnd, self.myxpl, {'schema': 'mvhr.request', 'xpltype': 'xpl-cmnd'}) Listener(self.sensor_basic_trig, self.myxpl, {'schema': 'sensor.basic', 'xpltype': 'xpl-trig'}) # Listener(self.mvhr_basic_trig, self.myxpl, # {'schema': 'mvhr.basic', 'xpltype': 'xpl-trig'}) # Listener(self.mvhr_reload_config, self.myxpl, # {'schema': 'domogik.system', 'xpltype': 'xpl-cmnd', # 'command': 'reload', 'plugin': 'mvhr'}) self.helpers = \ { "status" : { "cb" : self._mymvhr.helper_status, "desc" : "Show status of the mvhr", "usage" : "status", "param-list" : "", }, "reload_config" : { "cb" : self._mymvhr.helper_reload_config, "desc" : "Reload config of the plugin", "usage" : "reload_config", "param-list" : "", }, } self.enable_helper() self.enable_hbeat() self._mymvhr.reload_config() self.log.info("mvhr plugin correctly started")
def __init__(self): """ Create listener for wake on lan """ XplPlugin.__init__(self, name = 'wol_ping') # Configuration : interval between each ping self._config = Query(self.myxpl, self.log) interval = self._config.query('wol_ping', 'ping-interval') if interval == None: interval = 60 # Configuration : list of computers self.computers = {} num = 1 loop = True while loop == True: name = self._config.query('wol_ping', 'name-%s' % str(num)) ip = self._config.query('wol_ping', 'ip-%s' % str(num)) mac = self._config.query('wol_ping', 'mac-%s' % str(num)) mac_port = self._config.query('wol_ping', 'wol-port-%s' % str(num)) if mac_port == None: mac_port = 7 if name != None: self.log.info("Configuration : name=%s, ip=%s, mac=%s, mac port=%s" % (name, ip, mac, mac_port)) self.computers[name] = {"ip" : ip, "mac" : mac, "mac_port" : mac_port} else: loop = False num += 1 ### Create WOL object self._wolmanager = WOL(self.log) # Create listeners Listener(self.wol_cb, self.myxpl, {'schema': 'control.basic', 'xpltype': 'xpl-cmnd', 'type': 'wakeonlan', 'current': 'high'}) self.log.debug("Listener for wake on lan created") ### Create Ping object self._pingmanager = Ping(self.myxpl, self.log, self.ping_cb, float(interval), self.computers) self.enable_hbeat() self._pingmanager.ping()
class TtsManager(XplPlugin): """ Manage Tts """ def __init__(self): """ Init manager """ XplPlugin.__init__(self, name = 'tts') # Configuration self._config = Query(self.myxpl, self.log) software = self._config.query('tts', 'software') self.log.debug("Init info for tts created") ### Create tts objects self.my_tts = Tts(self.log, software) self.log.debug("Create object for tts created") # Create listener Listener(self.tts_cb, self.myxpl, {'schema': 'tts.basic','xpltype': 'xpl-cmnd'}) self.log.debug("Listener for tts created") self.enable_hbeat() def tts_cb(self, message): """ Call tts lib @param message : xPL message detected by listener """ # body contains the message self.log.debug("Function call back : entry") if 'speech' in message.data: speech = message.data['speech'] else: self._log.warning("Xpl message : missing 'speech' attribute") return try: self.log.debug("function call back : before send") self.my_tts.send(speech) self.log.debug("function call back : after send") except: self.log.error("Error while sending tts : %s" % traceback.format_exc()) return
def __init__(self): """ Create the lighting class """ XplPlugin.__init__(self, name = 'lighting') self.log.debug("lighting.__init__ : Start ...") self._config = Query(self.myxpl, self.log) self.log.debug("lighting.__init__ : Try to get configuration from XPL") try: #self.use_cron = bool(self._config.query('lighting', 'usecron')) self.broadcast = bool(self._config.query('lighting', 'broadcast')) #self.presence = bool(self._config.query('lighting', 'presence')) except: error = "Can't get configuration from XPL : %s" % \ (traceback.format_exc()) self.log.exception("lighting.__init__ : " + error) #self.use_cron = True self.broadcast = True #self.presence = True raise LightingException(error) self.log.debug("lighting.__init__ : Try to start the lighting librairy") try: self._mylighting = LightingAPI(self.broadcast, \ self.myxpl, self.log, self.get_data_files_directory()) except: error = "Something went wrong during lightingAPI init : %s" % \ (traceback.format_exc()) self.log.error("lighting.__init__ : "+error) self.force_leave() raise LightingException(error) self.log.debug("lighting.__init__ : Try to create listeners") Listener(self.lighting_config_cmnd, self.myxpl, {'schema': 'lighting.config', 'xpltype': 'xpl-cmnd'}) Listener(self.lighting_basic_cmnd, self.myxpl, {'schema': 'lighting.basic', 'xpltype': 'xpl-cmnd'}) # Listener(self.lighting_basic_trig, self.myxpl, # {'schema': 'lighting.basic', 'xpltype': 'xpl-trig'}) self.enable_hbeat() self._mylighting.reload_config() self.log.info("Plugin lighting correctly started.")
def __init__(self): """ Init manager """ XplPlugin.__init__(self, name = 'tv_samsg') # Configuration : list of televisions self.televisions = {} num = 1 loop = True self._config = Query(self.myxpl, self.log) while loop == True: name = self._config.query('tv_samsg', 'tv-%s-name' % str(num)) device = self._config.query('tv_samsg', 'tv-%s-device' % str(num)) if name != None: self.log.info("Configuration : name=%s, device=%s" % (name, device)) self.televisions[name] = {"device" : device} else: loop = False num += 1 ### Create SamsungTV objects for television in self.televisions: self.televisions[television]['obj'] = SamsungTV(self.log) try: self.log.info("Opening Samsung Television named '%s' (device : %s)" % (television, self.televisions[television]['device'])) self.televisions[television]['obj'].open(self.televisions[television]['device']) except SamsungTVException as err: self.log.error(err.value) print(err.value) self.force_leave() return # Create listener Listener(self.television_cb, self.myxpl, {'schema': 'control.basic', 'xpltype': 'xpl-cmnd', 'type': 'television'}) self.log.debug("Listener for tv_samsg created") self.enable_hbeat()
def __init__(self): """ Init manager """ XplPlugin.__init__(self, name = 'gceusbrb') # Configuration : list of relayboard self.relayboards = {} num = 1 loop = True self._config = Query(self.myxpl, self.log) while loop == True: name = self._config.query('gceusbrb', 'rb-%s-name' % str(num)) device = self._config.query('gceusbrb', 'rb-%s-device' % str(num)) if name != None: self.log.info("Configuration : name=%s, device=%s" % (name, device)) self.relayboards[name] = {"device" : device} else: loop = False num += 1 ### Create Relayboardusb objects ex.SamsungTV for relayboard in self.relayboards: self.relayboards[relayboard]['obj'] = Relayboardusb(self.log,self.send_xpl) try: self.log.info("Opening RelayBoard named '%s' (device : %s)" % (relayboard, self.relayboards[relayboard]['device'])) self.relayboards[relayboard]['obj'].open(self.relayboards[relayboard]['device'],relayboard) except RelayboardusbException as err: self.log.error(err.value) print err.value self.force_leave() return # Create listener Listener(self.relayboard_cb, self.myxpl, {'schema': 'control.basic','xpltype': 'xpl-cmnd', 'type': 'output'}) self.log.debug("Listener for gceusbrb created") self.enable_hbeat() self.log.info("RB Plugin ready :)")
class RfxcomUsbManager(XplPlugin): """ Manage the Rfxcom Usb device and connect it to xPL """ def __init__(self): """ Init plugin """ XplPlugin.__init__(self, name='rfxcom') # Get config # - device self._config = Query(self.myxpl, self.log) device = self._config.query('rfxcom', 'device') if device == None: self.log.error('Device is not configured, exiting') print('Device is not configured, exiting') self.force_leave() return # Init RFXCOM self.rfxcom = RfxcomUsb(self.log, self.send_xpl, self.send_trig, self.get_stop()) # Create a listener for all messages used by RFXCOM # TODO !!!!! # Create listeners Listener(self.process_x10_basic, self.myxpl, {'schema': 'x10.basic', 'xpltype': 'xpl-cmnd'}) Listener(self.process_x10_security, self.myxpl, {'schema': 'x10.securiy', 'xpltype': 'xpl-cmnd'}) Listener(self.process_ac_basic, self.myxpl, {'schema': 'ac.basic', 'xpltype': 'xpl-cmnd'}) Listener(self.process_remote_basic, self.myxpl, {'schema': 'remote.basic', 'xpltype': 'xpl-cmnd'}) Listener(self.process_control_basic, self.myxpl, {'schema': 'control.basic', 'xpltype': 'xpl-cmnd'}) # Open RFXCOM try: self.rfxcom.open(device) 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.listen, "rfxcom-process-reader", (self.get_stop(),), {}) self.register_thread(rfxcom_process) rfxcom_process.start() self.enable_hbeat() # lighting1 def process_x10_basic(self, message): """ Process command xpl message and call the librairy for processing command @param message : xpl message """ address = message.data["device"].lower() command = message.data["command"].lower() if message.data.has_key("level"): level = message.data["level"].lower() else: level = 0 if message.data.has_key("protocol"): protocol = message.data["protocol"].lower() else: protocol = "x10" # Prepare xpl-trig to send if success trig_msg = message trig_msg.set_type("xpl-trig") # call appropriate function if protocol in ("x10", "arc", "elro", "waveman", "chacon", "impuls"): self.rfxcom.command_10(address, command, protocol, trig_msg) elif protocol in ("koppla"): self.rfxcom.command_12(address, command, level, protocol, trig_msg) elif protocol in ("harrison"): self.rfxcom.command_18(address, command, protocol, trig_msg) def process_x10_security(self, message): """ Process command xpl message and call the librairy for processing command @param message : xpl message """ address = message.data["device"].lower() command = message.data["command"].lower() if message.data.has_key("delay"): delay = message.data["delay"].lower() else: delay = None # Prepare xpl-trig to send if success trig_msg = message trig_msg.set_type("xpl-trig") self.rfxcom.command_20(address, command, delay, trig_msg) def process_ac_basic(self, message): """ Process command xpl message and call the librairy for processing command @param message : xpl message """ # TODO : finish 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 = message trig_msg.set_type("xpl-trig") self.rfxcom.command_11(address, unit, command, level, eu, group, trig_msg) def process_remote_basic(self, message): """ Process command xpl message and call the librairy for processing command @param message : xpl message """ # TODO pass def process_control_basic(self, message): """ Process command xpl message and call the librairy for processing command @param message : xpl message """ msg_type = message.data["type"] msg_current = message.data["current"] msg_device = message.data["current"] self.log.debug("CONTROL.BASIC received : device = %s, type = %s, current = %s" % (msg_device, msg_type, msg_current)) self.rfxcom.xplcmd_control_basic(device = msg_device, type = msg_type, current = msg_current) def send_xpl(self, schema, data = {}): """ Send xPL message on network """ print("schema:%s, data:%s" % (schema, data)) self.log.debug("schema:%s, data:%s" % (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 send_trig(self, message): """ Send xpl-trig given message @param message : xpl-trig message """ self.myxpl.send(message)
class PlcBusMain(XplPlugin): ''' Manage PLCBus technology, send and receive order/state ''' def __init__(self): ''' Create the plcbusMain class This class is used to connect PLCBUS to the xPL Network ''' # Load config XplPlugin.__init__(self, name = 'plcbus') # Create listeners Listener(self._plcbus_cmnd_cb, self.myxpl, { 'schema': 'plcbus.basic', 'xpltype': 'xpl-cmnd', }) self._config = Query(self.myxpl, self.log) device = self._config.query('plcbus', 'device') self._usercode = self._config.query('plcbus', 'usercode') self._probe_inter = int( self._config.query('plcbus', 'probe-interval')) self._probe_list = self._config.query('plcbus', 'probe-list') # Create log instance self.api = PLCBUSAPI(self.log, device, self._command_cb, self._message_cb) self.add_stop_cb(self.api.stop) if self._probe_inter == 0: self.log.warning("The probe interval has been set to 0. This is not correct. The plugin will use a probe interval of 5 seconds") self._probe_inter = 5 self._probe_status = {} self._probe_thr = XplTimer(self._probe_inter, self._send_probe, self.myxpl) self._probe_thr.start() # self.register_timer(self._probe_thr) self.enable_hbeat() def _send_probe(self): """ Send probe message """ for h in self._probe_list: self.log.debug("send get_all_id") self.api.send("GET_ALL_ID_PULSE", h, self._usercode, 0, 0) time.sleep(1) self.log.debug("send get_all_on_id") self.api.send("GET_ALL_ON_ID_PULSE", h, self._usercode, 0, 0) time.sleep(1) def _plcbus_cmnd_cb(self, message): ''' General callback for all command messages ''' cmd = None dev = None user = '******' level = 0 rate = 0 if 'command' in message.data: cmd = message.data['command'] if 'device' in message.data: dev = message.data['device'].upper() if 'usercode' in message.data: user = message.data['usercode'] else: user = self._usercode if 'data1' in message.data: level = message.data['data1'] if 'data2' in message.data: rate = message.data['data2'] self.log.debug("%s received : device = %s, user code = %s, level = "\ "%s, rate = %s" % (cmd.upper(), dev, user, level, rate)) # if cmd == 'GET_ALL_ON_ID_PULSE': # self.api.get_all_on_id(user, dev) # else: self.api.send(cmd.upper(), dev, user, level, rate) # Workaround to send an ON command when dimmer = 0 if cmd == 'PRESET_DIM' and level == 0: print("cmd : %s " % cmd) print("level : %s " % level) self.api.send("OFF", dev, user) if cmd == 'PRESET_DIM' and level != 0: print('WORKAROUD : on fait suivre le DIM d un ON pour garder les widgets switch allumes') print("DEBUG cmd : %s " % cmd) print("DEBUG level : %s " % level) self.api.send("ON", dev, user) def _command_cb(self, f): ''' Called by the plcbus library when a command has been sent. If the commands need an ack, this callback will be called only after the ACK has been received @param : plcbus frame as an array ''' if f["d_command"] == "GET_ALL_ID_PULSE": data = int("%s%s" % (f["d_data1"], f["d_data2"])) house = f["d_home_unit"][0] for i in range(0,16): unit = data >> i & 1 code = "%s%s" % (house, i+1) if unit and not code in self._probe_status: self._probe_status[code] = "" self.log.info("New device discovered : %s" % code) elif (not unit) and code in self._probe_status: del self._probe_status[code] elif f["d_command"] == "GET_ALL_ON_ID_PULSE": data = "%s%s" % (bin(f["d_data1"])[2:].zfill(8), bin(f["d_data2"])[2:].zfill(8)) print("f : %s" % f) print("data : %s" % data) house = f["d_home_unit"][0] item = 16 for c in data: unit=int(c) code = "%s%s" % (house, item) print("Etat : %s " % code, unit) if code in self._probe_status and (self._probe_status[code] != str(unit)): print('DEBUG in rentre dans le IF detection GET_ALL_ON') self._probe_status[code] = str(unit) if unit == 1: command = "ON" else: command ="OFF" mess = XplMessage() mess.set_type('xpl-trig') mess.set_schema('plcbus.basic') mess.add_data({"usercode" : f["d_user_code"], "device": code, "command": command}) self.myxpl.send(mess) item = item - 1 else: mess = XplMessage() mess.set_type('xpl-trig') mess.set_schema('plcbus.basic') mess.add_data({"usercode" : f["d_user_code"], "device": f["d_home_unit"], "command": f["d_command"], "data1": f["d_data1"], "data2": f["d_data2"]}) self.myxpl.send(mess) # Workaround to for switch widget go ON when dimmer is send # if f["d_command"] == 'PRESET_DIM' and f["d_data1"] != 0 : # print('WORKAROUD : on fait suivre le DIM d un ON pour garder les widgets switch allumes') #print("data1 : %s " % f["d_data1"]) # mess = XplMessage() # mess.set_type('xpl-stat') # mess.set_schema('plcbus.basic') # mess.add_data({"usercode" : f["d_user_code"], "device": f["d_home_unit"], "command": 'ON'}) # self.myxpl.send(mess) def _message_cb(self, message): print("Message : %s " % message)
class SamsungTVManager(XplPlugin): """ Manage Samsung televisions """ def __init__(self): """ Init manager """ XplPlugin.__init__(self, name = 'tv_samsg') # Configuration : list of televisions self.televisions = {} num = 1 loop = True self._config = Query(self.myxpl, self.log) while loop == True: name = self._config.query('tv_samsg', 'tv-%s-name' % str(num)) device = self._config.query('tv_samsg', 'tv-%s-device' % str(num)) if name != None: self.log.info("Configuration : name=%s, device=%s" % (name, device)) self.televisions[name] = {"device" : device} else: loop = False num += 1 ### Create SamsungTV objects for television in self.televisions: self.televisions[television]['obj'] = SamsungTV(self.log) try: self.log.info("Opening Samsung Television named '%s' (device : %s)" % (television, self.televisions[television]['device'])) self.televisions[television]['obj'].open(self.televisions[television]['device']) except SamsungTVException as err: self.log.error(err.value) print(err.value) self.force_leave() return # Create listener Listener(self.television_cb, self.myxpl, {'schema': 'control.basic', 'xpltype': 'xpl-cmnd', 'type': 'television'}) self.log.debug("Listener for tv_samsg created") self.enable_hbeat() def television_cb(self, message): """ Call tv_samsg lib @param message : xPL message detected by listener """ # device contains name of television which will be used to get device if 'device' in message.data: name = message.data['device'] if 'current' in message.data: command = message.data['current'] else: self._log.warning("Xpl message : missing 'current' attribute") return if 'data1' in message.data: data1 = int(message.data['data1']) else: data1 = None try: device = self.televisions[name]["device"] except KeyError: self.log.warning("Television named '%s' is not defined" % name) return self.log.info("Television command received for '%s' on '%s'" % (name, device)) status = self.televisions[name]['obj'].send(command, data1) # Send xpl-trig to say plugin receive command print("S=%s" % status) if status == True: mess = XplMessage() mess.set_type('xpl-trig') mess.set_schema('sensor.basic') mess.add_data({'device' : device}) mess.add_data({'type' : 'television'}) mess.add_data({'current' : command}) if data1 != None: mess.add_data({'data1' : data1}) print(mess) self.myxpl.send(mess)