Exemplo n.º 1
0
    def find(self, args=None):
        """ Try to find IPX800 relay boards
        """
        # Init IPX
        ipx = IPX(self._log, None, None)

        # Find boards
        data = []
        data.append("List of all IPX800 boards found :")
        try:
            for ipx in ipx.find():
                data.append("%s : %s" % (ipx[0], ipx[1]))
        except IPXException as err:
            return [err.value]
        print(data)
        return data
Exemplo n.º 2
0
 def find(self, args = None):
     """ Try to find IPX800 relay boards
     """
     # Init IPX
     ipx  = IPX(self._log, None, None)
     
     # Find boards
     data = []
     data.append("List of all IPX800 boards found :")
     try:
         for ipx in ipx.find():
             data.append("%s : %s" % (ipx[0], ipx[1]))
     except IPXException as err:
         return [err.value]
     print(data)
     return data
Exemplo n.º 3
0
    def status(self, args=None):
        """ Get status for relay, inputs, counter, etc
        """

        ipx = IPX(self._log, None, None)
        if len(args) == 2:
            ipx.open("foo", args[0], args[1])
        elif len(args) == 4:
            ipx.open("foo", args[0], args[1], args[2], args[3])
        else:
            return ["Bad usage of this helper"]
        data = ipx.get_status_for_helper()
        print(data)
        return data
Exemplo n.º 4
0
 def status(self, args = None):
     """ Get status for relay, inputs, counter, etc
     """
         
     ipx = IPX(self._log, None, None)
     if len(args) == 2:
         ipx.open("foo", args[0], args[1])
     elif len(args) == 4:
         ipx.open("foo", args[0], args[1], args[2], args[3])
     else:
         return ["Bad usage of this helper"]
     data = ipx.get_status_for_helper()
     print(data)
     return data
Exemplo n.º 5
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 :)")