diff --git a/telldus-core/service/Device.cpp b/telldus-core/service/Device.cpp index 2f02ec38..d98bb621 100644 --- a/telldus-core/service/Device.cpp +++ b/telldus-core/service/Device.cpp @@ -32,16 +32,16 @@ Device::~Device(void) { */ int Device::getLastSentCommand(int methodsSupported){ - - int lastSentCommand = Device::maskUnsupportedMethods(d->state, methodsSupported); - - if (lastSentCommand == TELLSTICK_BELL) { - //Bell is not a state - lastSentCommand = TELLSTICK_TURNOFF; - } - if (lastSentCommand == 0) { - lastSentCommand = TELLSTICK_TURNOFF; - } + + int lastSentCommand = Device::maskUnsupportedMethods(d->state, methodsSupported); + + if (lastSentCommand == TELLSTICK_BELL) { + //Bell is not a state + lastSentCommand = TELLSTICK_TURNOFF; + } + if (lastSentCommand == 0) { + lastSentCommand = TELLSTICK_TURNOFF; + } return lastSentCommand; } @@ -127,6 +127,9 @@ int Device::doAction(int action, unsigned char data, Controller *controller) { Protocol *p = this->retrieveProtocol(); if(p){ std::string code = p->getStringForMethod(action, data, controller); + if (code == "") { + return TELLSTICK_ERROR_METHOD_NOT_SUPPORTED; + } return controller->send(code); } return TELLSTICK_ERROR_UNKNOWN; @@ -136,7 +139,7 @@ Protocol* Device::retrieveProtocol() const { if (d->protocol) { return d->protocol; } - + d->protocol = Protocol::getProtocolInstance(d->protocolName); if(d->protocol){ d->protocol->setModel(d->model); @@ -147,27 +150,27 @@ Protocol* Device::retrieveProtocol() const { return 0; } -int Device::maskUnsupportedMethods(int methods, int supportedMethods) { - // Bell -> On - if ((methods & TELLSTICK_BELL) && !(supportedMethods & TELLSTICK_BELL)) { - methods |= TELLSTICK_TURNON; - } - //Cut of the rest of the unsupported methods we don't have a fallback for - return methods & supportedMethods; -} - -int Device::methodId( const std::string &methodName ) { - if (methodName.compare("turnon") == 0) { - return TELLSTICK_TURNON; - } - if (methodName.compare("turnoff") == 0) { - return TELLSTICK_TURNOFF; - } - if (methodName.compare("bell") == 0) { - return TELLSTICK_BELL; - } - if (methodName.compare("dim") == 0) { - return TELLSTICK_DIM; - } - return 0; -} +int Device::maskUnsupportedMethods(int methods, int supportedMethods) { + // Bell -> On + if ((methods & TELLSTICK_BELL) && !(supportedMethods & TELLSTICK_BELL)) { + methods |= TELLSTICK_TURNON; + } + //Cut of the rest of the unsupported methods we don't have a fallback for + return methods & supportedMethods; +} + +int Device::methodId( const std::string &methodName ) { + if (methodName.compare("turnon") == 0) { + return TELLSTICK_TURNON; + } + if (methodName.compare("turnoff") == 0) { + return TELLSTICK_TURNOFF; + } + if (methodName.compare("bell") == 0) { + return TELLSTICK_BELL; + } + if (methodName.compare("dim") == 0) { + return TELLSTICK_DIM; + } + return 0; +}