Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
    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.")
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
 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")
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
    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 :)")
Exemplo n.º 7
0
 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")
Exemplo n.º 8
0
 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")
Exemplo n.º 9
0
    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()
Exemplo n.º 10
0
    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()
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
    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()
Exemplo n.º 13
0
    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()
Exemplo n.º 14
0
    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()
Exemplo n.º 15
0
    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()
Exemplo n.º 16
0
    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()
Exemplo n.º 17
0
 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)
Exemplo n.º 18
0
    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()
Exemplo n.º 19
0
    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.")
Exemplo n.º 20
0
    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.")
Exemplo n.º 21
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)
Exemplo n.º 22
0
    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 :)")
Exemplo n.º 23
0
    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")
Exemplo n.º 24
0
    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()
Exemplo n.º 25
0
    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()
Exemplo n.º 26
0
 def __init__(self):
     """
     Create the telldus class
     This class is used to connect devices (through telldus) to
     the xPL Network
     """
     XplHlpPlugin.__init__(self,
                           name='telldus',
                           reload_cb=self.telldus_reload_config_cb)
     self.log.debug("telldus.__init__ : Start ...")
     self._device = "/dev/tellstick"
     #Check if the device exists
     if not os.path.exists(self._device):
         self.log.warning(self._device +
                          " is not present but Tellstick Duo don't use it.")
     else:
         self.log.debug("Device present as " + self._device)
     self._config = Query(self.myxpl, self.log)
     self.log.debug("telldus.__init__ : Try to load API")
     try:
         self._mytelldus = TelldusAPI(self, self.send_xpl, self.log,
                                      self._config,
                                      self.get_data_files_directory(),
                                      self.myxpl)
     except Exception:
         self.log.error("Something went wrong during telldus API init.")
         self.log.error("%s" % (traceback.format_exc()))
         self.force_leave()
         exit(1)
     self.add_stop_cb(self._mytelldus.unregister)
     self.log.debug("telldus.__init__ : Create listeners")
     Listener(self.telldus_cmnd_cb, self.myxpl, {
         'schema': 'telldus.basic',
         'xpltype': 'xpl-cmnd'
     })
     Listener(
         self.telldus_reload_config_cb, self.myxpl, {
             'schema': 'domogik.system',
             'xpltype': 'xpl-cmnd',
             'command': 'reload',
             'plugin': 'telldus'
         })
     self.enable_hbeat()
     try:
         boo = self._config.query('telldus', 'lightext')
         if boo == None:
             boo = "False"
         self.lightext = eval(boo)
     except:
         self.log.warning(
             "Can't get delay configuration from XPL. Disable lighting extensions."
         )
         self.lightext = False
     if self.lightext == True:
         self.log.debug(
             "telldus.__init__ : Try to load the lighting extension.")
         self.lighting = LightingExtension(self, self._name, \
             self._mytelldus.lighting_activate_device, \
             self._mytelldus.lighting_deactivate_device, \
             self._mytelldus.lighting_valid_device)
     self.helpers =   \
        { "list" :
           {
             "cb" : self._mytelldus.helper.helper_list,
             "desc" : "List devices in telldus daemon.",
             "usage" : "list [devicetype]",
             "param-list" : "devicetype",
             "min-args" : 0,
             "devicetype" : "the type of device to find",
           },
          "info" :
           {
             "cb" : self._mytelldus.helper.helper_info,
             "desc" : "Display device information.",
             "usage" : "info <device>",
             "param-list" : "device",
             "min-args" : 1,
             "device" : "device address",
           },
          "memory" :
           {
             "cb" : self._mytelldus.helper.helper_memory,
             "desc" : "Show memory usage of variables. Experimental.",
             "usage" : "memory",
             "param-list" : "",
             "min-args" : 0,
           },
         }
     if self.lightext == True:
         self.log.debug(
             "telldus.__init__ : Try to enable the lighting extension.")
         self.lighting.enable_lighting()
     self.log.debug("telldus.__init__ : Try to load the helpers.")
     self.enable_helper()
     self.log.info("Telldus plugin correctly started")
Exemplo n.º 27
0
    def __init__(self):
        """ Create lister and launch bg listening
        """
        XplPlugin.__init__(self, name='ipx800')

        # Configuration : list of IPX800
        self.ipx_list = {}
        num = 1
        loop = True
        self._config = Query(self.myxpl, self.log)
        while loop == True:
            model = self._config.query('ipx800', 'model-%s' % str(num))
            login = self._config.query('ipx800', 'login-%s' % str(num))
            password = self._config.query('ipx800', 'password-%s' % str(num))
            name = self._config.query('ipx800', 'name-%s' % str(num))
            address = self._config.query('ipx800', 'ip-%s' % str(num))
            inter = self._config.query('ipx800', 'int-%s' % str(num))
            if name != None:
                self.log.info(
                    "Configuration : login=%s, password=***, name=%s, ip=%s, interval=%s"
                    % (login, name, address, inter))
                self.ipx_list[name] = {
                    "login": login,
                    "password": password,
                    "model": model,
                    "ip": address,
                    "interval": float(inter)
                }
                num += 1
            else:
                loop = False

        # no ipx configured
        if num == 1:
            msg = "No ipx800 board configured. Exiting plugin"
            self.log.info(msg)
            print(msg)
            self.force_leave()
            return

        ### Create IPX objects
        num_ok = 0
        for ipx in self.ipx_list:
            self.ipx_list[ipx]['obj'] = IPX(self.log, self.send_xpl,
                                            self.get_stop())
            try:
                self.log.info("Opening IPX800 named '%s' (ip : %s)" %
                              (ipx, self.ipx_list[ipx]['ip']))
                self.ipx_list[ipx]['obj'].open(ipx, self.ipx_list[ipx]['ip'],
                                               self.ipx_list[ipx]['model'],
                                               self.ipx_list[ipx]['login'],
                                               self.ipx_list[ipx]['password'])
            except:
                self.log.error("Error opening board '%s' : %s " %
                               (ipx, traceback.format_exc()))
                print("Error opening board '%s' : check logs" % ipx)
            else:
                num_ok += 1

        # no valid ipx800 board detected
        if num_ok == 0:
            msg = "No valid IPX800 board configured. Exiting plugin..."
            self.log.info(msg)
            print(msg)
            self.force_leave()
            return

        ### Start listening each IPX800
        for ipx in self.ipx_list:
            try:
                self.log.info("Start listening to IPX800 named '%s'" % ipx)
                ipx_listen = threading.Thread(
                    None, self.ipx_list[ipx]['obj'].listen, "listen_ipx",
                    (self.ipx_list[ipx]['interval'], ), {})
                ipx_listen.start()
            except IPXException as err:
                self.log.error(err.value)
                print(err.value)
                # we don't quit plugin if an error occured
                # we can loose a board for a little time
                #self.force_leave()
                #return

        ### Create listeners for commands
        self.log.info("Creating listener for IPX 800")
        #Listener(self.ipx_command, self.myxpl, {'schema': 'control.basic',
        #        'xpltype': 'xpl-cmnd', 'type': ['output', 'count']})
        Listener(self.ipx_command, self.myxpl, {
            'schema': 'control.basic',
            'xpltype': 'xpl-cmnd',
            'type': 'output'
        })

        self.enable_hbeat()
        self.log.info("Plugin ready :)")
Exemplo n.º 28
0
    def __init__(self):
        """ Create listener for Nabaztag TTS notification
        """
        XplPlugin.__init__(self, name='nbz_tts')
        # Create logger
        self.log.debug("Listener for Nabaztag TTS notification created")

        # Configuration : list of nabaztag whith serial, token and voice
        self.alias_list = {}
        num = 1
        loop = True
        self._config = Query(self.myxpl, self.log)
        while loop == True:
            nabaztag = self._config.query('nbz_tts', 'name-%s' % str(num))
            serial = self._config.query('nbz_tts', 'serial-%s' % str(num))
            token = self._config.query('nbz_tts', 'token-%s' % str(num))
            voice = self._config.query('nbz_tts', 'voice-%s' % str(num))
            if nabaztag != None:
                mess = "Configuration : nabaztag=" + str(
                    nabaztag) + " , serial=" + str(serial) + ", token=" + str(
                        token) + ", voice=" + str(voice)
                self.log.info(mess)
                print(mess)
                self.alias_list[nabaztag] = {
                    "nabaztag": nabaztag,
                    "serial": serial,
                    "token": token,
                    "voice": voice
                }
                num += 1
            else:
                loop = False

        # no nabaztag configured
        if num == 1:
            msg = "No nabaztag configured. Exiting plugin"
            self.log.info(msg)
            print(msg)
            self.force_leave()
            return

        # Check serial
        for alias in self.alias_list:
            if str(self.alias_list[alias]['serial']) != "None":
                self.log.debug("Serial for nabaztag " +
                               str(self.alias_list[alias]['nabaztag']) +
                               " is " + str(self.alias_list[alias]['serial']))
            else:
                self.log.error(
                    "Can't find the serial for the nabaztag " +
                    str(self.alias_list[alias]['nabaztag']) +
                    " , please check the configuration page of this plugin")
                self.force_leave()
                return

        # Check token
        for alias in self.alias_list:
            if str(self.alias_list[alias]['token']) != "None":
                self.log.debug("Token for nabaztag " +
                               str(self.alias_list[alias]['nabaztag']) +
                               " is " + str(self.alias_list[alias]['token']))
            else:
                self.log.error(
                    "Can't find the Token for the nabaztag " +
                    str(self.alias_list[alias]['nabaztag']) +
                    " , please check the configuration page of this plugin")
                self.force_leave()
                return

        # Check voice
        for alias in self.alias_list:
            if str(self.alias_list[alias]['voice']) != "None":
                self.log.debug("Voice for nabaztag " +
                               str(self.alias_list[alias]['nabaztag']) +
                               " is " + str(self.alias_list[alias]['voice']))
            else:
                self.log.error(
                    "Can't find the Voice for the nabaztag " +
                    str(self.alias_list[alias]['nabaztag']) +
                    " , please check the configuration page of this plugin")
                self.force_leave()
                return

        # Create NBZNotification object
        self.nbz_notification_manager = NBZNotification(self.log)

        # Create listeners
        Listener(self.nbz_notification_cb, self.myxpl, {
            'schema': 'sendmsg.push',
            'xpltype': 'xpl-cmnd'
        })
        self.enable_hbeat()
Exemplo n.º 29
0
    def __init__(self, server_ip, server_port):
        """ Initiate DbHelper, Logs and config
            Then, start HTTP server and give it initialized data
            @param server_ip :  ip of HTTP server
            @param server_port :  port of HTTP server
        """

        XplPlugin.__init__(self, name='rest')
        # logging initialization
        self.log.info("Rest Server initialisation...")
        self.log.debug("locale : %s %s" % locale.getdefaultlocale())

        # logging Queue activities
        log_queue = logger.Logger('rest-queues')
        self.log_queue = log_queue.get_logger('rest-queues')
        self.log_queue.info("Rest's queues activities...")

        # logging data manipulation initialization
        log_dm = logger.Logger('rest-dm')
        self.log_dm = log_dm.get_logger('rest-dm')
        self.log_dm.info("Rest Server Data Manipulation...")

        # API version
        self._rest_api_version = REST_API_VERSION

        # Hosts list
        self._hosts_list = {
            self.get_sanitized_hostname(): {
                "id": self.get_sanitized_hostname(),
                "status": "on",
                "primary": True,
                "last_seen": time.time(),
                "ip": "",
                "interval": "1"
            }
        }

        try:

            ### Config

            # directory data
            cfg = Loader('domogik')
            config = cfg.load()
            conf = dict(config[1])
            self.log_dir_path = conf['log_dir_path']

            # plugin installation path
            if conf.has_key('package_path'):
                self._package_path = conf['package_path']
                self._src_prefix = None
                self.log.info("Set package path to '%s' " % self._package_path)
                print("Set package path to '%s' " % self._package_path)
                self._design_dir = "%s/domogik_packages/design/" % self._package_path
                self.package_mode = True
            else:
                self.log.info("No package path defined in config file")
                self._package_path = None
                self._src_prefix = conf['src_prefix']
                self._design_dir = "%s/share/domogik/design/" % conf[
                    'src_prefix']
                self.package_mode = False

            # HTTP server ip and port
            try:
                cfg_rest = Loader('rest')
                config_rest = cfg_rest.load()
                conf_rest = dict(config_rest[1])
                self.server_ip = conf_rest['rest_server_ip']
                self.server_port = conf_rest['rest_server_port']
            except KeyError:
                # default parameters
                self.server_ip = server_ip
                self.server_port = server_port
            self.log.info("Configuration : ip:port = %s:%s" %
                          (self.server_ip, self.server_port))

            # SSL configuration
            try:
                cfg_rest = Loader('rest')
                config_rest = cfg_rest.load()
                conf_rest = dict(config_rest[1])
                self.use_ssl = conf_rest['rest_use_ssl']
                if self.use_ssl == "True":
                    self.use_ssl = True
                else:
                    self.use_ssl = False
                self.ssl_certificate = conf_rest['rest_ssl_certificate']
            except KeyError:
                # default parameters
                self.use_ssl = USE_SSL
                self.ssl_certificate = SSL_CERTIFICATE
            if self.use_ssl == True:
                self.log.info(
                    "Configuration : SSL support activated (certificate : %s)"
                    % self.ssl_certificate)
            else:
                self.log.info("Configuration : SSL support not activated")

            # File repository
            try:
                cfg_rest = Loader('rest')
                config_rest = cfg_rest.load()
                conf_rest = dict(config_rest[1])
                self.repo_dir = conf_rest['rest_repository']
            except KeyError:
                # default parameters
                self.repo_dir = DEFAULT_REPO_DIR

            # Gloal Queues config
            self.log.debug("Get queues configuration")
            self._config = Query(self.myxpl, self.log)

            self._queue_timeout = self._config.query('rest', 'q-timeout')
            if self._queue_timeout == None:
                self._queue_timeout = QUEUE_TIMEOUT
            self._queue_timeout = float(self._queue_timeout)

            self._queue_package_size = self._config.query('rest', 'q-pkg-size')
            if self._queue_package_size == None:
                self._queue_package_size = QUEUE_PACKAGE_SIZE
            self._queue_package_size = float(self._queue_package_size)

            self._queue_size = self._config.query('rest', 'q-size')
            if self._queue_size == None:
                self._queue_size = QUEUE_SIZE
            self._queue_size = float(self._queue_size)

            self._queue_life_expectancy = self._config.query(
                'rest', 'q-life-exp')
            if self._queue_life_expectancy == None:
                self._queue_life_expectancy = QUEUE_LIFE_EXPECTANCY
            self._queue_life_expectancy = float(self._queue_life_expectancy)

            self._queue_sleep = self._config.query('rest', 'q-sleep')
            if self._queue_sleep == None:
                self._queue_sleep = QUEUE_SLEEP
            self._queue_sleep = float(self._queue_sleep)

            # /command Queues config
            self._queue_command_size = self._config.query('rest', 'q-cmd-size')
            if self._queue_command_size == None:
                self._queue_command_size = QUEUE_COMMAND_SIZE
            self._queue_command_size = float(self._queue_command_size)

            # /event Queues config
            self._event_timeout = self._config.query('rest', 'evt-timeout')
            if self._event_timeout == None:
                self._event_timeout = EVENT_TIMEOUT
            self._event_timeout = float(self._event_timeout)

            self._queue_event_size = self._config.query('rest', 'q-evt-size')
            if self._queue_event_size == None:
                self._queue_event_size = QUEUE_EVENT_SIZE
            self._queue_event_size = float(self._queue_event_size)

            self._queue_event_timeout = self._config.query(
                'rest', 'q-evt-timeout')
            if self._queue_event_timeout == None:
                self._queue_event_timeout = QUEUE_EVENT_TIMEOUT
            self._queue_event_timeout = float(self._queue_event_timeout)

            self._queue_event_life_expectancy = self._config.query(
                'rest', 'q-evt-life-exp')
            if self._queue_event_life_expectancy == None:
                self._queue_event_life_expectancy = QUEUE_EVENT_LIFE_EXPECTANCY
            self._queue_event_life_expectancy = float(
                self._queue_event_life_expectancy)

            # Queues for xPL
            # Queues for packages management
            self._queue_package = Queue(self._queue_package_size)

            # Queues for domogik system actions
            self._queue_system_list = Queue(self._queue_size)
            self._queue_system_detail = Queue(self._queue_size)
            self._queue_system_start = Queue(self._queue_size)
            self._queue_system_stop = Queue(self._queue_size)

            # Queues for /command
            self._queue_command = Queue(self._queue_command_size)

            # Queues for /events/domogik
            self._queue_event_dmg = Queue(self._queue_event_size)

            # Queues for /events/request
            # this queue will be fill by stat manager
            self._event_requests = RequestEvents(
                self.get_stop, self.log, self._event_timeout,
                self._queue_event_size, self._queue_event_timeout,
                self._queue_event_life_expectancy)
            self.add_stop_cb(self._event_requests.set_stop_clean)

            # Queues for /events/domogik
            # this queue will be fill by stat manager
            self._event_dmg = DmgEvents(self.get_stop, self.log,
                                        self._event_timeout,
                                        self._queue_event_size,
                                        self._queue_event_timeout,
                                        self._queue_event_life_expectancy)
            # notice : adding data in queue is made in _add_to_queue_system_list
            self.add_stop_cb(self._event_dmg.set_stop_clean)

            # define listeners for queues
            self.log.debug("Create listeners")
            if self.package_mode == True:
                Listener(self._list_installed_packages, self.myxpl, \
                         {'schema': 'domogik.package',
                          'xpltype': 'xpl-trig',
                          'command' : 'installed-packages-list'})
            Listener(self._add_to_queue_package, self.myxpl, \
                     {'schema': 'domogik.package',
                      'xpltype': 'xpl-trig'})
            Listener(self._add_to_queue_system_list, self.myxpl, \
                     {'schema': 'domogik.system',
                      'xpltype': 'xpl-trig',
                      'command' : 'list'})
            Listener(self._add_to_queue_system_list, self.myxpl, \
                     {'schema': 'domogik.system',
                      'xpltype': 'xpl-trig',
                      'command' : 'enable'})
            Listener(self._add_to_queue_system_list, self.myxpl, \
                     {'schema': 'domogik.system',
                      'xpltype': 'xpl-trig',
                      'command' : 'disable'})
            Listener(self._add_to_queue_system_detail, self.myxpl, \
                     {'schema': 'domogik.system',
                      'xpltype': 'xpl-trig',
                      'command' : 'detail'})
            Listener(self._add_to_queue_system_start, self.myxpl, \
                     {'schema': 'domogik.system',
                      'xpltype': 'xpl-trig',
                      'command' : 'start'})
            Listener(self._add_to_queue_system_stop, self.myxpl, \
                     {'schema': 'domogik.system',
                      'xpltype': 'xpl-trig',
                      'command' : 'stop'})
            Listener(self._add_to_queue_command, self.myxpl, \
                     {'xpltype': 'xpl-trig'})

            # Listener for hosts list
            Listener(self._list_hosts, self.myxpl, \
                     {'schema': 'hbeat.app',
                      'xpltype': 'xpl-stat'})

            # Background process to check if hosts has disappeared
            thr_hbeat = XplTimer(10, \
                                 self._refresh_status_for_list_hosts, \
                                 self.myxpl)
            thr_hbeat.start()

            self._discover_hosts()

            # Enable hbeat
            self.enable_hbeat()

            # Ask for installed packages on all hosts
            # Semaphore init for installed package list update
            self.sema_installed = Semaphore(value=1)
            self._installed_packages = {}
            if self.package_mode == True:
                self._get_installed_packages_from_manager()

            # Launch server, stats
            self.log.info("REST Initialisation OK")
            self.add_stop_cb(self.stop_http)
            self.server = None
            self.start_stats()

            self.start_http()
        except:
            self.log.error("%s" % self.get_exception())
Exemplo n.º 30
0
    def __init__(self):
        """ Init plugin
        """
        XplPlugin.__init__(self, name='demodata')

        ### Get config
        self._config = Query(self.myxpl, self.log)
        port = self._config.query('demodata', 'port')
        if port == None:
            port = DEFAULT_PORT 
        else:
            port = int(port)
        self.log.info("Listen port is %s" % port)

        self.log.info("Start creating the listeners")

        ### Create listeners for the fake actuator devices
        # RGB controller
        Listener(self.cmd_arduino_rgb, self.myxpl, {
            'schema': 'arduino.rgb',
            'xpltype': 'xpl-cmnd',
        })

        # Switch
        # Dimmer
        Listener(self.cmd_lighting_basic, self.myxpl, {
            'schema': 'lighting.basic',
            'xpltype': 'xpl-cmnd',
        })

        self.log.info("All listeners are created")

        ### Call the data creators
        self.log.info("Start all the data creator threads")
        demo = DemoData(self.log, self.send_sensor_basic, \
                                  self.send_teleinfo_basic)

        # weather data each minute
        self._weather_thr = XplTimer(60, \
                                     demo.weather_data, \
                                     self.myxpl)
        self._weather_thr.start()

        # teleinfo data each 10min
        self._teleinfo_thr = XplTimer(600, \
                                     demo.teleinfo_data, \
                                     self.myxpl)
        self._teleinfo_thr.start()

        # tank data each 1min
        self._tank_thr = XplTimer(60, \
                                  demo.tank_data, \
                                  self.myxpl)
        self._tank_thr.start()

        # water data each 1min
        self._water_thr = XplTimer(60, \
                                  demo.water_data, \
                                  self.myxpl)
        self._water_thr.start()

        self.log.info("All the data creator threads created")

        self.enable_hbeat()

        # Launch the web UI
        #demo_ui = DemoUI()
        msg = "Launch the Web UI on port %s" % port
        print(msg)
        self.log.info(msg)
        self.add_stop_cb(self.stop_http)
        self.server = None
        self.server_ip = ''
        self.server_port = port
        self.start_http()