Update GenericInterfaces plugin

This commit is contained in:
Michael Zanetti 2019-09-18 00:19:16 +02:00
parent dc0ed6fd69
commit fbd2d5256a
2 changed files with 27 additions and 50 deletions

View File

@ -53,56 +53,36 @@ DevicePluginGenericInterfaces::DevicePluginGenericInterfaces()
{ {
} }
Device::DeviceSetupStatus DevicePluginGenericInterfaces::setupDevice(Device *device) void DevicePluginGenericInterfaces::setupDevice(DeviceSetupInfo *info)
{ {
if (device->deviceClassId() == awningDeviceClassId) { info->finish(Device::DeviceErrorNoError);
return Device::DeviceSetupStatusSuccess;
}
if (device->deviceClassId() == blindDeviceClassId) {
return Device::DeviceSetupStatusSuccess;
}
if (device->deviceClassId() == shutterDeviceClassId) {
return Device::DeviceSetupStatusSuccess;
}
if (device->deviceClassId() == socketDeviceClassId) {
return Device::DeviceSetupStatusSuccess;
}
if (device->deviceClassId() == lightDeviceClassId) {
return Device::DeviceSetupStatusSuccess;
}
if (device->deviceClassId() == heatingDeviceClassId) {
return Device::DeviceSetupStatusSuccess;
}
return Device::DeviceSetupStatusFailure;
} }
Device::DeviceError DevicePluginGenericInterfaces::executeAction(Device *device, const Action &action) void DevicePluginGenericInterfaces::executeAction(DeviceActionInfo *info)
{ {
Device *device = info->device();
Action action = info->action();
if (device->deviceClassId() == awningDeviceClassId) { if (device->deviceClassId() == awningDeviceClassId) {
if (action.actionTypeId() == awningOpenActionTypeId) { if (action.actionTypeId() == awningOpenActionTypeId) {
device->setStateValue(awningStatusStateTypeId, "Opening"); device->setStateValue(awningStatusStateTypeId, "Opening");
device->setStateValue(awningClosingOutputStateTypeId, false); device->setStateValue(awningClosingOutputStateTypeId, false);
device->setStateValue(awningOpeningOutputStateTypeId, true); device->setStateValue(awningOpeningOutputStateTypeId, true);
return Device::DeviceErrorNoError; return info->finish(Device::DeviceErrorNoError);
} }
if (action.actionTypeId() == awningStopActionTypeId) { if (action.actionTypeId() == awningStopActionTypeId) {
device->setStateValue(awningStatusStateTypeId, "Stopped"); device->setStateValue(awningStatusStateTypeId, "Stopped");
device->setStateValue(awningOpeningOutputStateTypeId, false); device->setStateValue(awningOpeningOutputStateTypeId, false);
device->setStateValue(awningClosingOutputStateTypeId, false); device->setStateValue(awningClosingOutputStateTypeId, false);
return Device::DeviceErrorNoError; return info->finish(Device::DeviceErrorNoError);
} }
if (action.actionTypeId() == awningCloseActionTypeId) { if (action.actionTypeId() == awningCloseActionTypeId) {
device->setStateValue(awningStatusStateTypeId, "Closing"); device->setStateValue(awningStatusStateTypeId, "Closing");
device->setStateValue(awningOpeningOutputStateTypeId, false); device->setStateValue(awningOpeningOutputStateTypeId, false);
device->setStateValue(awningClosingOutputStateTypeId, true); device->setStateValue(awningClosingOutputStateTypeId, true);
return Device::DeviceErrorNoError; return info->finish(Device::DeviceErrorNoError);
} }
return Device::DeviceErrorActionTypeNotFound; return info->finish(Device::DeviceErrorActionTypeNotFound);
} }
if (device->deviceClassId() == blindDeviceClassId ) { if (device->deviceClassId() == blindDeviceClassId ) {
@ -110,21 +90,21 @@ Device::DeviceError DevicePluginGenericInterfaces::executeAction(Device *device,
device->setStateValue(blindStatusStateTypeId, "Opening"); device->setStateValue(blindStatusStateTypeId, "Opening");
device->setStateValue(blindClosingOutputStateTypeId, false); device->setStateValue(blindClosingOutputStateTypeId, false);
device->setStateValue(blindOpeningOutputStateTypeId, true); device->setStateValue(blindOpeningOutputStateTypeId, true);
return Device::DeviceErrorNoError; return info->finish(Device::DeviceErrorNoError);
} }
if (action.actionTypeId() == blindStopActionTypeId) { if (action.actionTypeId() == blindStopActionTypeId) {
device->setStateValue(blindStatusStateTypeId, "Stopped"); device->setStateValue(blindStatusStateTypeId, "Stopped");
device->setStateValue(blindOpeningOutputStateTypeId, false); device->setStateValue(blindOpeningOutputStateTypeId, false);
device->setStateValue(blindClosingOutputStateTypeId, false); device->setStateValue(blindClosingOutputStateTypeId, false);
return Device::DeviceErrorNoError; return info->finish(Device::DeviceErrorNoError);
} }
if (action.actionTypeId() == blindCloseActionTypeId) { if (action.actionTypeId() == blindCloseActionTypeId) {
device->setStateValue(blindStatusStateTypeId, "Closing"); device->setStateValue(blindStatusStateTypeId, "Closing");
device->setStateValue(blindOpeningOutputStateTypeId, false); device->setStateValue(blindOpeningOutputStateTypeId, false);
device->setStateValue(blindClosingOutputStateTypeId, true); device->setStateValue(blindClosingOutputStateTypeId, true);
return Device::DeviceErrorNoError; return info->finish(Device::DeviceErrorNoError);
} }
return Device::DeviceErrorActionTypeNotFound; return info->finish(Device::DeviceErrorActionTypeNotFound);
} }
if (device->deviceClassId() == shutterDeviceClassId) { if (device->deviceClassId() == shutterDeviceClassId) {
@ -132,45 +112,45 @@ Device::DeviceError DevicePluginGenericInterfaces::executeAction(Device *device,
device->setStateValue(shutterStatusStateTypeId, "Opening"); device->setStateValue(shutterStatusStateTypeId, "Opening");
device->setStateValue(shutterClosingOutputStateTypeId, false); device->setStateValue(shutterClosingOutputStateTypeId, false);
device->setStateValue(shutterOpeningOutputStateTypeId, true); device->setStateValue(shutterOpeningOutputStateTypeId, true);
return Device::DeviceErrorNoError; return info->finish(Device::DeviceErrorNoError);
} }
if (action.actionTypeId() == shutterStopActionTypeId) { if (action.actionTypeId() == shutterStopActionTypeId) {
device->setStateValue(shutterStatusStateTypeId, "Stopped"); device->setStateValue(shutterStatusStateTypeId, "Stopped");
device->setStateValue(shutterOpeningOutputStateTypeId, false); device->setStateValue(shutterOpeningOutputStateTypeId, false);
device->setStateValue(shutterClosingOutputStateTypeId, false); device->setStateValue(shutterClosingOutputStateTypeId, false);
return Device::DeviceErrorNoError; return info->finish(Device::DeviceErrorNoError);
} }
if (action.actionTypeId() == shutterCloseActionTypeId) { if (action.actionTypeId() == shutterCloseActionTypeId) {
device->setStateValue(shutterStatusStateTypeId, "Closing"); device->setStateValue(shutterStatusStateTypeId, "Closing");
device->setStateValue(shutterOpeningOutputStateTypeId, false); device->setStateValue(shutterOpeningOutputStateTypeId, false);
device->setStateValue(shutterClosingOutputStateTypeId, true); device->setStateValue(shutterClosingOutputStateTypeId, true);
return Device::DeviceErrorNoError; return info->finish(Device::DeviceErrorNoError);
} }
return Device::DeviceErrorActionTypeNotFound; return info->finish(Device::DeviceErrorActionTypeNotFound);
} }
if (device->deviceClassId() == socketDeviceClassId) { if (device->deviceClassId() == socketDeviceClassId) {
if (action.actionTypeId() == socketPowerActionTypeId) { if (action.actionTypeId() == socketPowerActionTypeId) {
device->setStateValue(socketPowerStateTypeId, action.param(socketPowerActionPowerParamTypeId).value()); device->setStateValue(socketPowerStateTypeId, action.param(socketPowerActionPowerParamTypeId).value());
return Device::DeviceErrorNoError; return info->finish(Device::DeviceErrorNoError);
} }
return Device::DeviceErrorActionTypeNotFound; return info->finish(Device::DeviceErrorActionTypeNotFound);
} }
if (device->deviceClassId() == lightDeviceClassId) { if (device->deviceClassId() == lightDeviceClassId) {
if (action.actionTypeId() == lightPowerActionTypeId) { if (action.actionTypeId() == lightPowerActionTypeId) {
device->setStateValue(lightPowerStateTypeId, action.param(lightPowerActionPowerParamTypeId).value()); device->setStateValue(lightPowerStateTypeId, action.param(lightPowerActionPowerParamTypeId).value());
return Device::DeviceErrorNoError; return info->finish(Device::DeviceErrorNoError);
} }
return Device::DeviceErrorActionTypeNotFound; return info->finish(Device::DeviceErrorActionTypeNotFound);
} }
if (device->deviceClassId() == heatingDeviceClassId) { if (device->deviceClassId() == heatingDeviceClassId) {
if (action.actionTypeId() == heatingPowerActionTypeId) { if (action.actionTypeId() == heatingPowerActionTypeId) {
device->setStateValue(heatingPowerStateTypeId, action.param(heatingPowerActionPowerParamTypeId).value()); device->setStateValue(heatingPowerStateTypeId, action.param(heatingPowerActionPowerParamTypeId).value());
return Device::DeviceErrorNoError; return info->finish(Device::DeviceErrorNoError);
} }
return Device::DeviceErrorActionTypeNotFound; return info->finish(Device::DeviceErrorActionTypeNotFound);
} }
return Device::DeviceErrorDeviceClassNotFound; return info->finish(Device::DeviceErrorDeviceClassNotFound);
} }

View File

@ -34,11 +34,8 @@ class DevicePluginGenericInterfaces : public DevicePlugin
public: public:
explicit DevicePluginGenericInterfaces(); explicit DevicePluginGenericInterfaces();
Device::DeviceSetupStatus setupDevice(Device *device) override; void setupDevice(DeviceSetupInfo *info) override;
void executeAction(DeviceActionInfo *info) override;
public slots:
Device::DeviceError executeAction(Device *device, const Action &action) override;
}; };
#endif // DEVICEPLUGINGENERICINTERFACES_H #endif // DEVICEPLUGINGENERICINTERFACES_H