Aircoookie/Espalexa

Missing On Off information

Opened this issue · 2 comments

Hello,

thank you for this helpfull library. What I was missing is an explicit on/off function. So I've done some extention:

in EspalexaDevice.cpp
bool EspalexaDevice::getOnOff()
{
return _on_off;
}
void EspalexaDevice::setOnOff(bool onoff)
{
_on_off = onoff;
}

in EspalexaDevice.h
...
class EspalexaDevice {
private:
...
bool _on_off = false;
...

in Espalexa.h
if (body.indexOf("false")>0) //OFF command
{
devices[devId]->setOnOff(0);
...
if (body.indexOf("true") >0) //ON command
{
devices[devId]->setOnOff(1);
...

works for me.

Greetings Jörg

Missing something, no?
C:\Users\Warren\Documents\Arduino\libraries\Espalexa\src/Espalexa.h: In member function 'bool Espalexa::handleAlexaApiCall(String, String)':
C:\Users\Warren\Documents\Arduino\libraries\Espalexa\src/Espalexa.h:479:19: error: 'class EspalexaDevice' has no member named 'setOnOff'
devices[devId]->setOnOff(0);
^
C:\Users\Warren\Documents\Arduino\libraries\Espalexa\src/Espalexa.h:489:19: error: 'class EspalexaDevice' has no member named 'setOnOff'
devices[devId]->setOnOff(1);
^
exit status 1

There is no need for setOnOff, the library has the function already.
In my house i have many lights with i can switching (toggle with a tactile switch) instead of alexa command:

device[i]->setValue(device[i]->getValue() > 0 ? 0 : 255);		// toggle value
device[i]->doCallback();	// relay on

or

// toggle value, switch on with last brightness, if needed
device[i]->setValue(device[i]->getValue() > 0 ? 0 : device[i]->getLastValue());
// set relay or LED strip dim value
device[i]->doCallback();								 

or

device[i]->setValue(1);     // relay on
device[i]->doCallback();    // set relay