jangxx / node-magichome

An incomplete implementation of the functionality of the "Magic Home" app. Partially a port of https://github.com/Danielhiversen/flux_led to Node.js
ISC License
124 stars 26 forks source link

[REQUEST] Set warm white mode #5

Closed jghaanstra closed 6 years ago

jghaanstra commented 6 years ago

RGBW and RGBWW LED strips can also change the (warm) white of the LED strip. The Python library which was used to create this library supports a "set warm white mode" function but it seems this has not been ported to this nodejs library. I'd like to request this feature. I'd submit a PR myself but my programming skills are to limited.

jangxx commented 6 years ago

This is a really good idea, and I would be happy to have this functionality in this library. Unfortunately, I don't have the necessary setup to adequately test it at the moment. I could try to add necessary methods based on the python code alone, but I would not be able to verify that they actually did what they're supposed to.

I also don't have time to work on this library at the moment, so this request will need to stay unfulfilled for at least a few weeks (except you or someone else implements it instead).

jghaanstra commented 6 years ago

Ok, that was actually a lot easier than I thought. Here is the PR: https://github.com/jangxx/node-magichome/pull/6

jangxx commented 6 years ago

Okay, I cleaned up your code a bit, merged your PR and published the changes to npm. Thanks a lot :+1:

jghaanstra commented 6 years ago

With cleaning up the code you actually broke the functionality. The warm white level is an integer between 0 and 100 in the Magic Home smartphone app but it needs to be normalized to a 0 - 255 range for the command. Using the following math gives the right value: ww = (clamp(ww, lower_bound, 100) * 255) / 100;

Do you want me to submit a new PR?

jangxx commented 6 years ago

I think we can just leave it as is it for now. The controllers take a value from 0 to 255, so the method works as intended. If you want to have value from 0 to 100, or 0 to 1, or any other arbitrary range, you can just calculate the value in your application.