Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

value of power json is always zero #6

Open
do9xe opened this issue Jan 6, 2020 · 3 comments
Open

value of power json is always zero #6

do9xe opened this issue Jan 6, 2020 · 3 comments

Comments

@do9xe
Copy link

do9xe commented Jan 6, 2020

When sending the following line of python to the REST-API of tradfri-go in server-mode the value 1 is ignored. It will always default to 0.
requests.put("http://10.42.3.34:8080/api/device/65539/power", data = {"power":1})

powerRequest := model.PowerRequest{}
err := json.Unmarshal(body, &powerRequest)
res, err := tradfriClient.PutDevicePower(deviceId, powerRequest.Power)

The value of powerRequest.Power is already 0 in line 94. I tested with several ways of input, like a json conversion before sending the data or converting it to a string. I also discovered that this also applies to the dimmer and the dimming and setState function.

@eriklupander
Copy link
Owner

Thank you for posting your issue.

I can successfully turn on/off the Power state of one of my lightbulbs using curl.

> curl -X PUT http://localhost:8080/api/device/65538/power --data '{"power":0}'
{"Msg":"Changed"}

> curl -X PUT http://localhost:8080/api/device/65538/power --data '{"power":1}'
{"Msg":"Changed"}

> curl http://localhost:8080/api/device/65538
{"deviceMetadata":{"id":65538,"name":"Färgglad","vendor":"IKEA of Sweden","type":"TRADFRI bulb E27 CWS opal 600lm"},"dimmer":203,"xcolor":29713,"ycolor":26431,"rgbcolor":"f2eccf","power":true}

In the example above, I'm running tradfri-go in server mode. Can you try running the same curl commands?

@eriklupander
Copy link
Owner

I've added some missing error checks + logging when parsing the REST API requests into JSON which possibly could help you pinpoint your issue.

@CaramelFur
Copy link
Contributor

the line:
requests.put("http://10.42.3.34:8080/api/device/65539/power", data = {"power":1})
does not send the expected json you want, it tries to send a python dictionary instead of a json string so the server cannot unmarshal anything and will respond with a 400 status code.

You should try running
requests.put("http://10.42.3.34:8080/api/device/65537/power", data = '{"power": 1}')
instead as this actually sends the string the server is expecting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants