MylesMor / nanoleafapi

A Python3 wrapper for the Nanoleaf OpenAPI, for use with the Light Panels, Canvas and Shapes (Hexagons, Triangles and Elements).
https://nanoleafapi.readthedocs.io
MIT License
59 stars 15 forks source link

Create Events: add examples in wiki #3

Closed MatthewARoy closed 4 years ago

MatthewARoy commented 4 years ago

Hi, this is excellent! Very excited to use it.

How can you create new events with this? I see the register events. Is it possible to set single panels to have an effect via that? Or is it just listening to active events. Can you provide a more detailed example set for generating a new event in the wiki?

Thanks

MylesMor commented 4 years ago

Hi, I unfortunately don't think I did the best job with naming the methods.

register_event will listen for all the event types you provide it in the second argument, including the state event and touch event (most common ones). I don't believe you can create your own events if that's what you mean, they are limited to the ones specified by Nanoleaf. Whenever one of these set events occur, it will send the contents of the event data (in a dictionary) to the function specified and created by you and given as a first argument.

This means you can then use this data stored in the dictionary (or even the fact that the event occurred) to do anything else such as setting an effect, or even controlling other smart devices as I tried with the touch event.

I hope this is what you meant, let me know if it needs any further explanation and I'll try to add a more detailed example soon, in fact I'll add an example code file with examples of all the functions in action.

MatthewARoy commented 4 years ago

Ok, so it's not possible to set nanoleaf states via the event states, this is more just listening?

MylesMor commented 4 years ago

I'm still not totally sure what you mean but as far as I know, all you can do is listen for events and then run code when they're found, which is what register_event does.

There is a way to send an effect dictionary if that's what you mean, which basically creates a new effect using the parameters specified. This functionality isn't currently in my package but planning to add it in the next update.

MatthewARoy commented 4 years ago

I understand. Creating a new effect is what I was looking for, I'll look into their SDK and look forward to your next update!

On Tue, Feb 18, 2020 at 1:56 AM MylesMor notifications@github.com wrote:

I'm still not totally sure what you mean but as far as I know, all you can do is listen for events and then run code when they're found, which is what register_event does.

There is a way to send an effect dictionary if that's what you mean, which basically creates a new effect using the parameters specified. This functionality isn't currently in my package but planning to add it in the next update.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MylesMor/nanoleafapi/issues/3?email_source=notifications&email_token=AA2KV2752YXXKAYJSQHYOPDRDOWE7A5CNFSM4KVU23PKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMBKKZQ#issuecomment-587375974, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2KV26W6HIAHWGMAGJ3AXDRDOWE7ANCNFSM4KVU23PA .

MylesMor commented 4 years ago

Great! In the mean time until my next update, have a look at section 3.2.4 Effects Commands here: https://forum.nanoleaf.me/docs/openapi

It just gives some information if you would like to have a go at doing it yourself.

MylesMor commented 4 years ago

Commit 764c459cebc64dd020896c9affba3843afaeaa42 (version 1.1.5) adds a way to send these user-created effect dictionaries to the lights, using write_effect(effect_dict). You still need to create the effect dictionary by hand, but I'm planning some features to make this a little easier in the future.

MatthewARoy commented 4 years ago

Thank you!