Esempio n. 1
0
async def validate_input(hass: core.HomeAssistant, data):
    """Validate the user input allows us to connect to the hub.

    Data has the keys from DATA_SCHEMA with values provided by the user.
    """

    hub = aiopulse2.Hub(data["host"])
    try:
        await hub.test()
    except Exception as err:
        raise CannotConnect(str(err))

    # Return info that you want to store in the config entry.
    return {"title": hub.name}
Esempio n. 2
0
async def main():
    hosts = sys.argv[1:]
    if not hosts:
        print("Usage: hubtest.py host1 [host2 ...]")
        return
    for host in hosts:
        try:
            hub = aiopulse2.Hub(host)
            result = await hub.test(True)
            if result:
                print(f"Host: {host}: {hub}")
                for roller in hub.rollers.values():
                    print(f"    {roller}")
            else:
                print(f"Host: {host}: Unknown Error")
        except Exception as e:
            print(f"Host: {host}: Error ({e})")
Esempio n. 3
0
    async def async_step_user(self, user_input=None):
        """Handle the initial step once we have info from the user."""
        errors = {}
        if user_input is not None:
            try:
                hub = aiopulse2.Hub(user_input["host"])
                await hub.test()
                info = {"title": hub.name}

                return self.async_create_entry(title=info["title"],
                                               data=user_input)
            except Exception:  # pylint: disable=broad-except
                errors["base"] = "cannot_connect"

        return self.async_show_form(step_id="user",
                                    data_schema=DATA_SCHEMA,
                                    errors=errors)
Esempio n. 4
0
async def main():
    """cli utility"""

    if (len(sys.argv) != 4):
        print(f"usage: pulse_hub_cli.py hub_ip roller_name closed_percent")
        exit(1)

    hubip = sys.argv[1]
    desired_roller_name = sys.argv[2]
    desired_closed_percent = int(sys.argv[3])

    # hubip='192.168.1.127'
    # desired_roller_name = 'Office 3 of 3'
    # desired_closed_percent = 26 # 26 (27 for 1 of 3) closed percent is the desired location

    print(
        f" move hub {hubip} roller {desired_roller_name} to closed {desired_closed_percent}%"
    )

    event_loop = asyncio.get_running_loop()

    print("  setup the hub")
    hub = aiopulse2.Hub(hubip)
    add_job(event_loop, hub.run)
    await hub.rollers_known.wait()

    print("  find the roller")
    counter = 0
    roller = list(hub.rollers.values())[0]
    while (roller.name != desired_roller_name
           ):  # hub.rollers gets populated while this loop runs sometimes
        for roller in hub.rollers.values():
            if (roller.name == desired_roller_name):
                break
        if (roller.name != desired_roller_name):
            counter += 1
            if (counter > 200):  # timeout after 20 seconds
                print(f"  failed to find roller {desired_roller_name}")
                await close_up(event_loop, hub)
                exit(1)
            await asyncio.sleep(0.5)

    print("  ensure the roller is all set")
    counter = 0
    while (roller.closed_percent == None):
        counter += 1
        if (counter > 200):  # timeout after 20 seconds
            print(f"   roller {roller.name} has not reported")
            await close_up(event_loop, hub)
            exit(1)
        await asyncio.sleep(0.5)

    print('  send moveto command')
    add_job(event_loop, roller.move_to, desired_closed_percent)

    print(f"  wait for the roller to arrive at {desired_closed_percent}")
    counter = 0
    while (roller.closed_percent != desired_closed_percent):
        counter += 1
        if (
                counter > 200
        ):  # timeout after 20 seconds - to-do - rounding error can cause this e.g. a roller looking for 27 to finish at 26
            print(
                f"  timeout - roller has not yet arrived at {desired_closed_percent} - {roller.closed_percent}"
            )
            await close_up(event_loop, hub)
            exit(1)
        await asyncio.sleep(0.1)

    await close_up(event_loop, hub)