Aircoookie/Espalexa

setState() and getState() independant of Value

alka79 opened this issue · 4 comments

hello,
Library works great for me. NodeMCU 1.0 device regognized by Alexa as a dimmable light. Much better recognition than fauxmo. Great job :)

However, it is confusing and annoying that the library uses the brightness value to control ON/OFF.

For example, I'd like to externally turn ON the device without knowing the current brigthness. It would use the current device brightness. Like Alexa does when you ask to turn on.
Devices actually have a brighness Value, even when OFF.

I would suggest separate boolean functions getState() and setState() self explanatory . It would clarify usage and really help when the device is also controlled outside of Alexa.

Thanks for considering,
Al

Hi!
Thank you, this is an excellent suggestion!
You could already turn on to the current brightness using device.setValue(device.getLastValue()), but I believe that syntax isn't very user friendly. Added the state functions!

just tried 2.4.8 : SetState and getState seem to be working fine. Thanks. That was quick 👍

However, getValue() always returns 0 when the device is Off. Any chance to return the real brighness attribute ?

Awesome!
getValue() returning 0 is intended. If you were for example controlling an LED connected to a PWM pin, 0 means off. If you always want the brightness even if the device is off, just use getLastValue(). Maybe that function name is not really intuitive, but it is the correct brightness you are looking for. If the device is on, getLastValue() == getValue() should be the case 🙂

I just tried getLastValue(). This is it :)
Thanks.