Update GenericElements plugin

This commit is contained in:
Michael Zanetti 2019-09-18 00:10:47 +02:00
parent c2b8e60401
commit b76fe4abd4
2 changed files with 18 additions and 40 deletions

View File

@ -29,52 +29,30 @@ DevicePluginGenericElements::DevicePluginGenericElements()
{ {
} }
Device::DeviceSetupStatus DevicePluginGenericElements::setupDevice(Device *device) void DevicePluginGenericElements::setupDevice(DeviceSetupInfo *info)
{ {
// Toggle Button info->finish(Device::DeviceErrorNoError);
if (device->deviceClassId() == toggleButtonDeviceClassId) {
return Device::DeviceSetupStatusSuccess;
}
// Button
if (device->deviceClassId() == buttonDeviceClassId) {
return Device::DeviceSetupStatusSuccess;
}
// ON/OFF Button
if (device->deviceClassId() == onOffButtonDeviceClassId) {
return Device::DeviceSetupStatusSuccess;
}
return Device::DeviceSetupStatusFailure;
} }
Device::DeviceError DevicePluginGenericElements::executeAction(Device *device, const Action &action) void DevicePluginGenericElements::executeAction(DeviceActionInfo *info)
{ {
Device *device = info->device();
Action action = info->action();
// Toggle Button // Toggle Button
if (device->deviceClassId() == toggleButtonDeviceClassId ) { if (action.actionTypeId() == toggleButtonStateActionTypeId) {
if (action.actionTypeId() == toggleButtonStateActionTypeId) { device->setStateValue(toggleButtonStateStateTypeId, action.params().paramValue(toggleButtonStateActionStateParamTypeId).toBool());
device->setStateValue(toggleButtonStateStateTypeId, action.params().paramValue(toggleButtonStateActionStateParamTypeId).toBool());
return Device::DeviceErrorNoError;
}
return Device::DeviceErrorActionTypeNotFound;
} }
// Button // Button
if (device->deviceClassId() == buttonDeviceClassId ) { if (action.actionTypeId() == buttonButtonPressActionTypeId) {
if (action.actionTypeId() == buttonButtonPressActionTypeId) { emit emitEvent(Event(buttonButtonPressedEventTypeId, device->id()));
emit emitEvent(Event(buttonButtonPressedEventTypeId, device->id()));
return Device::DeviceErrorNoError;
}
return Device::DeviceErrorActionTypeNotFound;
} }
// ON/OFF Button // ON/OFF Button
if (device->deviceClassId() == onOffButtonDeviceClassId ) { if (action.actionTypeId() == onOffButtonOnActionTypeId) {
if (action.actionTypeId() == onOffButtonOnActionTypeId) { emit emitEvent(Event(onOffButtonOnEventTypeId, device->id()));
emit emitEvent(Event(onOffButtonOnEventTypeId, device->id()));
return Device::DeviceErrorNoError;
}
if (action.actionTypeId() == onOffButtonOffActionTypeId) {
emit emitEvent(Event(onOffButtonOffEventTypeId, device->id()));
return Device::DeviceErrorNoError;
}
return Device::DeviceErrorActionTypeNotFound;
} }
return Device::DeviceErrorDeviceClassNotFound; if (action.actionTypeId() == onOffButtonOffActionTypeId) {
emit emitEvent(Event(onOffButtonOffEventTypeId, device->id()));
}
info->finish(Device::DeviceErrorNoError);
} }

View File

@ -34,10 +34,10 @@ class DevicePluginGenericElements : public DevicePlugin
public: public:
explicit DevicePluginGenericElements(); explicit DevicePluginGenericElements();
Device::DeviceSetupStatus setupDevice(Device *device) override; void setupDevice(DeviceSetupInfo *info) override;
public slots: public slots:
Device::DeviceError executeAction(Device *device, const Action &action) override; void executeAction(DeviceActionInfo *info) override;
}; };