How to use the pywebostv.connection.WebOSClient.PROMPTED function in pywebostv

To help you get started, we’ve selected a few pywebostv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github supersaiyanmode / PyWebOSTV / tests / test_connection.py View on Github external
"type": "wrong-response"
                    }))
            return send_response

        def patched_send_message(*args, **kwargs):
            kwargs["unique_id"] = "1"
            obj = WebOSClient.send_message(client, *args, **kwargs)
            sent_event.set()
            return obj

        client.send_message = patched_send_message

        store = {}
        Thread(target=make_response(True, True, False)).start()
        gen = client.register(store, timeout=10)
        assert next(gen) == WebOSClient.PROMPTED
        assert next(gen) == WebOSClient.REGISTERED

        assert store == {"client_key": "xyz"}

        # Test with non-empty store.
        Thread(target=make_response(False, True, False)).start()
        assert list(client.register(store, timeout=10)) ==\
            [WebOSClient.REGISTERED]
        assert "xyz" in json.dumps(client.sent_message)

        # Test wrong response.
        Thread(target=make_response(False, False, True)).start()
        with raises(Exception):
            list(client.register(store, timeout=10))
github supersaiyanmode / PyWebOSTV / pywebostv / connection.py View on Github external
def register(self, store, timeout=60):
        if "client_key" in store:
            REGISTRATION_PAYLOAD["client-key"] = store["client_key"]

        queue = self.send('register', None, REGISTRATION_PAYLOAD,
                          get_queue=True)
        while True:
            try:
                item = queue.get(block=True, timeout=timeout)
            except Empty:
                raise Exception("Timeout.")

            if item.get("payload", {}).get("pairingType") == "PROMPT":
                yield WebOSClient.PROMPTED
            elif item["type"] == "registered":
                store["client_key"] = item["payload"]["client-key"]
                yield WebOSClient.REGISTERED
                break
            else:
                # TODO: Better exception.
                raise Exception("Failed to register.")