Esempio n. 1
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")
Esempio n. 2
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")
Esempio n. 3
0
class Telldus(XplHlpPlugin):
    '''
    Manage chacon devices through the TellStick device
    '''
    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")

    def telldus_cmnd_cb(self, message):
        """
        General callback for all command messages
        @param message : an XplMessage object
        """
        self.log.debug("telldus.telldus_cmnd_cb : Receive message.")
        commands = {
            'on': lambda hu, l, f: self._mytelldus.send_on(hu),
            'off': lambda hu, l, f: self._mytelldus.send_off(hu),
            'dim': lambda hu, l, f: self._mytelldus.send_dim(hu, l),
            'bright': lambda hu, l, f: self._mytelldus.send_bright(hu, l, f),
            'shine': lambda hu, l, f: self._mytelldus.send_shine(hu, l, f),
            'change': lambda hu, l, f: self._mytelldus.send_change(hu, l, f),
            'up': lambda hu, l, f: self._mytelldus.send_up(hu),
            'down': lambda hu, l, f: self._mytelldus.send_down(hu),
            'stop': lambda hu, l, f: self._mytelldus.send_stop(hu),
            'shut': lambda hu, l, f: self._mytelldus.send_shut(hu, l),
        }
        try:
            cmd = None
            if 'command' in message.data:
                cmd = message.data['command']
            device = None
            if 'device' in message.data:
                device = message.data['device']
            level = "0"
            if 'level' in message.data:
                level = message.data['level']
            faderate = "0"
            if 'faderate' in message.data:
                faderate = message.data['faderate']
            self.log.debug("%s received : device= %s, level=%s, faderate=%s" %
                           (cmd, device, level, faderate))
            commands[cmd](device, level, faderate)
        except Exception:
            self.log.error("action _ %s _ unknown." % (cmd))
            error = "Exception : %s" % (traceback.format_exc())
            self.log.info("TelldusException : " + error)

    def telldus_reload_config_cb(self):
        """
        Callback for telldus reload config
        @param message : xpl message
        """
        self.log.debug("Telldus reload config received")
        self._mytelldus.reload_config()

    def send_xpl(self, message):
        """
        Callback for sending xpl
        @param add : address of the module
        @param order : the order sent to the unit
        """
        self.log.debug("Telldus send_xpl")
        self.myxpl.send(message)
Esempio n. 4
0
class Telldus(XplHlpPlugin):
    '''
    Manage chacon devices through the TellStick device
    '''
    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")

    def telldus_cmnd_cb(self, message):
        """
        General callback for all command messages
        @param message : an XplMessage object
        """
        self.log.debug("telldus.telldus_cmnd_cb : Receive message.")
        commands = {
            'on': lambda hu, l, f: self._mytelldus.send_on(hu),
            'off': lambda hu, l, f: self._mytelldus.send_off(hu),
            'dim': lambda hu, l, f: self._mytelldus.send_dim(hu, l),
            'bright': lambda hu, l, f: self._mytelldus.send_bright(hu, l, f),
            'shine': lambda hu, l, f: self._mytelldus.send_shine(hu, l, f),
            'change': lambda hu, l, f: self._mytelldus.send_change(hu, l, f),
            'up': lambda hu, l, f: self._mytelldus.send_up(hu),
            'down': lambda hu, l, f: self._mytelldus.send_down(hu),
            'stop': lambda hu, l, f: self._mytelldus.send_stop(hu),
            'shut': lambda hu, l, f: self._mytelldus.send_shut(hu, l),
        }
        try :
            cmd = None
            if 'command' in message.data:
                cmd = message.data['command']
            device = None
            if 'device' in message.data:
                device = message.data['device']
            level = "0"
            if 'level' in message.data:
                level = message.data['level']
            faderate = "0"
            if 'faderate' in message.data:
                faderate = message.data['faderate']
            self.log.debug("%s received : device= %s, level=%s, faderate=%s" % (cmd, device, level, faderate))
            commands[cmd](device, level, faderate)
        except Exception:
            self.log.error("action _ %s _ unknown." % (cmd))
            error = "Exception : %s" % (traceback.format_exc())
            self.log.info("TelldusException : "+error)

    def telldus_reload_config_cb(self):
        """
        Callback for telldus reload config
        @param message : xpl message
        """
        self.log.debug("Telldus reload config received")
        self._mytelldus.reload_config()

    def send_xpl(self, message):
        """
        Callback for sending xpl
        @param add : address of the module
        @param order : the order sent to the unit
        """
        self.log.debug("Telldus send_xpl")
        self.myxpl.send(message)