milanmeu / aionanoleaf

Async typed Python package for the Nanoleaf OpenAPI
GNU Lesser General Public License v3.0
1 stars 8 forks source link

[WIP] Add extControl support #5

Open ptxmac opened 2 years ago

ptxmac commented 2 years ago

extControl allows a client to control each panel directly.

This PR is not completely, but it is functional. Sample code for testing it:

async def main():
    async with ClientSession() as session:
        nanoleaf = aionanoleaf.Nanoleaf(session, "<host>", "<token>")
        await nanoleaf.get_info()
        s = await nanoleaf.steam()
        red = Color(255, 0, 0, 0)
        green = Color(0, 255, 0, 0)
        clear = Color(0, 0, 0, 0)
        panels = sorted(list(nanoleaf.panels), key=lambda p: (p.x_coordinate, p.y_coordinate))
        updates = [
            Update(p.id, red, 10 * idx) for idx, p in enumerate(panels)
        ]
        await s.send_updates(updates)
        await asyncio.sleep(len(panels) * 1)
        await s.send_updates([Update(p.id, clear, 0) for p in panels])
        for p in reversed(panels):
            await s.send_updates([Update(p.id, green, 10)])
            await asyncio.sleep(1)
            await s.send_updates([Update(p.id, red, 10)])
            await asyncio.sleep(1)

run(main())