コード例 #1
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 :)")
コード例 #2
0
class KarotzMain(XplPlugin):
    '''Manage ZiBase
    '''    
    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 xpl_command(self, message):
        """ Call karotz lib function in function of given xpl message
            @param message : xpl message
        """
        cmd = None
        dev = None
        value = None
        
        if 'command' in message.data:
            cmd = message.data['command']
        if 'device' in message.data:
            device = message.data['device']
        if 'value' in message.data:
            value=message.data['value']
        if 'time' in message.data:
            tps=message.data['time']
        if 'right' in message.data:
            right=message.data['right']
            value=right
        if 'left' in message.data:
            left=message.data['left']

        self.log.debug(message.data)
        if value == None :
            self.log.warning("value not specified")
            return
        else:
            #self.log.debug("xpl %s received : device = %s value=%s " % (cmd, device, value))
            self.log.debug("xpl %s received " % (cmd) )    

            try:
                if cmd=='tts':
                    self.log.debug("xpl command=%s language=%s" % (cmd, self.lang))
                    self.karotz.tts(value,self.lang.upper())
                if cmd=='led':
                    self.log.debug("xpl command=%s color=%s time=%s" % (cmd, value,tps))
                    self.karotz.led(value,tps)
                if cmd=='ears':
                    self.log.debug("xpl command=%s right=%s left=%s" % (cmd, right, left))
                    self.karotz.ears(right,left)
            except:
                self.log.error("Error to send command=%s" % (traceback.format_exc()))