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

API returns error or False #7

Closed OfficialVreesie closed 3 years ago

OfficialVreesie commented 3 years ago

Hi, I have a problem using the nanoleafapi.

Problem

I am trying to toggle the power of my nanoleaf using the following command: nl.toggle_power(), but that gives me the following error: Expecting value: line 1 column 1 (char 0)

What I did

  1. I created an auth_token and stored it in my code
  2. Then I called the nl.toggle_power() function, but instantly get an error.
  3. If I try nl.set_color((255, 0, 0)), it returns False and nothing happens

Code

Here is my full code (not much)

from nanoleafapi import Nanoleaf

nl = Nanoleaf("192.168.x.xx")

auth_token = "my_token"
nl.toggle_power()



What am I doing wrong?

MylesMor commented 3 years ago

Hi, thanks for your issue report! Right the first steps are:

nl = Nanoleaf("192.168.x.xx")
nl.generate_auth_token()

It looks like you've done this, so the next step is to remove the generate_auth_token() call and just initialise the Nanoleaf object with your token like this:

auth_token = "TOKEN"
nl = Nanoleaf("192.168.x.xx", auth_token, print_errors=True)

Now you can start calling the methods as listed without having to get a new key every time. Also try setting the print_errors argument to True as shown above to help me diagnose the issue. Then try repeating nl.toggle_power() and nl.set_color((255, 0, 0)) and please tell me the result of that. Thanks!

OfficialVreesie commented 3 years ago

Thanks, this fixed it.... I did saw it indeed in the code!