def __init__(self, host='127.0.0.1', port=5000, timeout=1,
                 recv_ident=None, recv_codes_only=True, veto_repeats=True):
        """Initialize the pilight client.

        The readout thread is not started automatically.
        """
        threading.Thread.__init__(self)
        self.daemon = True
        self._stop_thread = threading.Event()
        self._lock = threading.Lock()
        self.recv_codes_only = recv_codes_only
        self.veto_repeats = veto_repeats

        # Identify client (https://manual.pilight.org/en/api)
        client_identification_sender = {
            "action": "identify",
            "options": {
                # To get CPU load and RAM of pilight daemon, is neverless
                # ignored by daemon ...
                "core": 0,
                "receiver": 0,  # To receive the RF data received by pilight
                "config": 0
            }
        }

        if recv_ident:
            client_identification_receiver = recv_ident
        else:
            client_identification_receiver = {
                "action": "identify",
                "options": {
                    "core": 0,  # To get CPU load and RAM of pilight daemon
                    # To receive the RF data received by pilight
                    "receiver": 1,
                    "config": 0,
                    "forward": 0
                }
            }

        # Open 2 socket connections, one for sending one for receiving data
        # That is the simplest approach to allow asynchronus communication with
        # the pilight daemon
        self.receive_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.send_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        # Timeout to allow receiver thread termination and to restrict blocking
        # connection time
        self.receive_socket.settimeout(timeout)
        self.send_socket.settimeout(timeout)

        self.receive_socket.connect((host, port))
        self.send_socket.connect((host, port))

        # Identify this clients sockets at the pilight-deamon
        self.receive_socket.send(
            json.dumps(client_identification_receiver).encode())
        answer_1 = json.loads(self.receive_socket.recv(1024).decode())
        self.send_socket.send(
            json.dumps(client_identification_sender).encode())
        answer_2 = json.loads(self.send_socket.recv(1024).decode())

        # Check connections are acknowledged
        if ('success' not in answer_1['status'] or
                'success' not in answer_2['status']):
            raise IOError(
                'Connection to the pilight daemon failed. Reply %s, %s',
                answer_1, answer_2)

        self.callback = None
def __init__ ( self , host = '127.0.0.1' , port = 5000 , timeout = 1 , recv_ident = None , recv_codes_only = True , veto_repeats = True ) : threading . Thread . __init__ ( self ) self . daemon = True self . _stop_thread = threading . Event ( ) self . _lock = threading . Lock ( ) self . recv_codes_only = recv_codes_only self . veto_repeats = veto_repeats client_identification_sender = { "action" : "identify" , "options" : { "core" : 0 , "receiver" : 0 , "config" : 0 } } if recv_ident : client_identification_receiver = recv_ident else : client_identification_receiver = { "action" : "identify" , "options" : { "core" : 0 , "receiver" : 1 , "config" : 0 , "forward" : 0 } } self . receive_socket = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) self . send_socket = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) self . receive_socket . settimeout ( timeout ) self . send_socket . settimeout ( timeout ) self . receive_socket . connect ( ( host , port ) ) self . send_socket . connect ( ( host , port ) ) self . receive_socket . send ( json . dumps ( client_identification_receiver ) . encode ( ) ) answer_1 = json . loads ( self . receive_socket . recv ( 1024 ) . decode ( ) ) self . send_socket . send ( json . dumps ( client_identification_sender ) . encode ( ) ) answer_2 = json . loads ( self . send_socket . recv ( 1024 ) . decode ( ) ) if ( 'success' not in answer_1 [ 'status' ] or 'success' not in answer_2 [ 'status' ] ) : raise IOError ( 'Connection to the pilight daemon failed. Reply %s, %s' , answer_1 , answer_2 ) self . callback = None
Initialize the pilight client.

        The readout thread is not started automatically.