Exemple #1
0
async def get_client(ip_address, protocol,
                     show_responses) -> Optional[HarmonyAPI]:
    client = HarmonyAPI(ip_address=ip_address, protocol=protocol)

    def output_response(message):
        print(f"{client.name}: {message}")

    if show_responses:
        listen_callback = Handler(handler_obj=output_response,
                                  handler_name='output_response',
                                  once=False)
        client.register_handler(handler=listen_callback)

    print(f"Trying to connect to HUB with IP {ip_address}.")
    try:
        if await client.connect():
            print(
                "Connected to HUB {} ({}) with firmware version {} and HUB ID {} using protocol {}"
                .format(client.name, ip_address, client.fw_version,
                        client.hub_id, client.protocol))
            return client
    except ConnectionRefusedError:
        print(f"Failed to connect to HUB {ip_address}.")

    print("An issue occurred trying to connect")

    return None
Exemple #2
0
async def get_client(ip_address, show_responses) -> Optional[HarmonyAPI]:
    client = HarmonyAPI(ip_address)

    def output_response(message):
        print(message)

    listen_callback = Handler(handler_obj=output_response,
                              handler_name='output_response',
                              once=False)
    if show_responses:
        client.register_handler(handler=listen_callback)

    if await client.connect():
        print("Connected to HUB {} with firmware version {}".format(
            client.name, client.fw_version))
        return client

    print("An issue occured trying to connect")

    return None