Make use of interfaces in generic elements and add trigger button

This commit is contained in:
Simon Stürz 2021-09-04 11:43:50 +02:00
parent f966532b57
commit 5a1c3445d7
2 changed files with 74 additions and 29 deletions

View File

@ -47,20 +47,35 @@ void IntegrationPluginGenericElements::executeAction(ThingActionInfo *info)
Thing *thing = info->thing(); Thing *thing = info->thing();
Action action = info->action(); Action action = info->action();
// Toggle Button // Power Button
if (action.actionTypeId() == toggleButtonStateActionTypeId) { if (thing->thingClassId() == powerButtonThingClassId) {
thing->setStateValue(toggleButtonStateStateTypeId, action.params().paramValue(toggleButtonStateActionStateParamTypeId).toBool()); if (action.actionTypeId() == powerButtonPowerActionTypeId) {
thing->setStateValue(powerButtonPowerStateTypeId, action.params().paramValue(powerButtonPowerActionPowerParamTypeId).toBool());
}
} }
// Button // Button
if (action.actionTypeId() == buttonButtonPressActionTypeId) { if (thing->thingClassId() == buttonThingClassId) {
emit emitEvent(Event(buttonButtonPressedEventTypeId, thing->id())); if (action.actionTypeId() == buttonPressActionTypeId) {
emit emitEvent(Event(buttonPressedEventTypeId, thing->id()));
}
} }
// Trigger button
if (thing->thingClassId() == triggerButtonThingClassId) {
if (action.actionTypeId() == triggerButtonTriggerActionTypeId) {
emit emitEvent(Event(triggerButtonPressedEventTypeId, thing->id()));
}
}
// ON/OFF Button // ON/OFF Button
if (action.actionTypeId() == onOffButtonOnActionTypeId) { if (thing->thingClassId() == onOffButtonThingClassId) {
emit emitEvent(Event(onOffButtonOnEventTypeId, thing->id())); if (action.actionTypeId() == onOffButtonOnActionTypeId) {
} emit emitEvent(Event(onOffButtonPressedEventTypeId, thing->id(), ParamList() << Param(onOffButtonPressedEventButtonNameParamTypeId, "On")));
if (action.actionTypeId() == onOffButtonOffActionTypeId) { } else if (action.actionTypeId() == onOffButtonOffActionTypeId) {
emit emitEvent(Event(onOffButtonOffEventTypeId, thing->id())); emit emitEvent(Event(onOffButtonPressedEventTypeId, thing->id(), ParamList() << Param(onOffButtonPressedEventButtonNameParamTypeId, "Off")));
}
} }
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
} }

View File

@ -10,20 +10,22 @@
"thingClasses": [ "thingClasses": [
{ {
"id": "c0f511f9-70f5-499b-bd70-2c0e9ddd68c4", "id": "c0f511f9-70f5-499b-bd70-2c0e9ddd68c4",
"name": "toggleButton", "name": "powerButton",
"displayName": "Toggle Button", "displayName": "Power Button",
"createMethods": ["user"], "createMethods": [ "user" ],
"interfaces": [ "power" ],
"paramTypes": [ ], "paramTypes": [ ],
"stateTypes": [ "stateTypes": [
{ {
"id": "b5e90567-54aa-49bd-a78a-3c19fb38aaf5", "id": "b5e90567-54aa-49bd-a78a-3c19fb38aaf5",
"name": "state", "name": "power",
"displayName": "state", "displayName": "state",
"displayNameEvent": "state changed", "displayNameEvent": "power changed",
"displayNameAction": "Set state", "displayNameAction": "set power",
"type": "bool", "type": "bool",
"defaultValue": false, "defaultValue": false,
"writable": true "writable": true,
"ioType": "digitalOutput"
} }
] ]
}, },
@ -31,51 +33,79 @@
"id": "820b2f2d-0d92-48c8-8fd4-f94ce8fc4103", "id": "820b2f2d-0d92-48c8-8fd4-f94ce8fc4103",
"name": "button", "name": "button",
"displayName": "Button", "displayName": "Button",
"createMethods": ["user"], "createMethods": [ "user" ],
"interfaces": [ "button" ],
"paramTypes": [ ], "paramTypes": [ ],
"actionTypes": [ "actionTypes": [
{ {
"id": "01f38af1-b2ab-4ec3-844e-ef52f0f229a9", "id": "01f38af1-b2ab-4ec3-844e-ef52f0f229a9",
"name": "buttonPress", "name": "press",
"displayName": "press" "displayName": "press"
} }
], ],
"eventTypes": [ "eventTypes": [
{ {
"id": "effdbc2d-e467-4b0b-80a9-9dda251bfa5c", "id": "effdbc2d-e467-4b0b-80a9-9dda251bfa5c",
"name": "buttonPressed", "name": "pressed",
"displayName": "button pressed" "displayName": "button pressed"
} }
] ]
}, },
{
"id": "5f91923e-fc8e-48db-9de7-9a2fc36798dd",
"name": "triggerButton",
"displayName": "Trigger button",
"createMethods": [ "user" ],
"interfaces": [ "outputtrigger", "button" ],
"paramTypes": [ ],
"actionTypes": [
{
"id": "da322b8e-2116-4565-805a-03f7726373c8",
"name": "trigger",
"displayName": "trigger"
}
],
"eventTypes": [
{
"id": "51197853-0559-42a0-a97b-6ead56ae22f6",
"name": "pressed",
"displayName": "triggered"
}
]
},
{ {
"id": "430d188c-476d-4825-a9bd-86dfa3094b56", "id": "430d188c-476d-4825-a9bd-86dfa3094b56",
"name": "onOffButton", "name": "onOffButton",
"displayName": "ON/OFF Button", "displayName": "ON/OFF Button",
"createMethods": ["user"], "createMethods": ["user"],
"interfaces": [ "multibutton" ],
"paramTypes": [ ], "paramTypes": [ ],
"actionTypes": [ "actionTypes": [
{ {
"id": "892596d2-0863-4807-97da-469b9f7003f2", "id": "892596d2-0863-4807-97da-469b9f7003f2",
"name": "on", "name": "on",
"displayName": "press ON" "displayName": "on"
}, },
{ {
"id": "a8d64050-0b58-4ccf-b052-77ce2b7368ad", "id": "a8d64050-0b58-4ccf-b052-77ce2b7368ad",
"name": "off", "name": "off",
"displayName": "press OFF" "displayName": "off"
} }
], ],
"eventTypes": [ "eventTypes": [
{ {
"id": "4eeba6a2-e4c7-4a2e-8360-2797d98114e6", "id": "4eeba6a2-e4c7-4a2e-8360-2797d98114e6",
"name": "on", "name": "pressed",
"displayName": "ON pressed" "displayName": "Button pressed",
}, "paramTypes": [
{ {
"id": "b636c5f3-2eb0-4682-96d4-88a4aa9d2c12", "id": "2e6bc343-41a3-4634-b514-4512ae54afbc",
"name": "off", "name": "buttonName",
"displayName": "OFF pressed" "displayName": "Button name",
"type": "QString",
"allowedValues": ["Off", "On"]
}
]
} }
] ]
} }