Skip to content

Commit

Permalink
Merge PR #474: GenericElements: Make use of interfaces in generic ele…
Browse files Browse the repository at this point in the history
…ments and add trigger button
  • Loading branch information
nymea-jenkins committed Sep 7, 2021
2 parents d07dfa3 + 68d5ce3 commit d2dd52f
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 120 deletions.
35 changes: 25 additions & 10 deletions genericelements/integrationplugingenericelements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,35 @@ void IntegrationPluginGenericElements::executeAction(ThingActionInfo *info)
Thing *thing = info->thing();
Action action = info->action();

// Toggle Button
if (action.actionTypeId() == toggleButtonStateActionTypeId) {
thing->setStateValue(toggleButtonStateStateTypeId, action.params().paramValue(toggleButtonStateActionStateParamTypeId).toBool());
// Power Button
if (thing->thingClassId() == powerButtonThingClassId) {
if (action.actionTypeId() == powerButtonPowerActionTypeId) {
thing->setStateValue(powerButtonPowerStateTypeId, action.params().paramValue(powerButtonPowerActionPowerParamTypeId).toBool());
}
}

// Button
if (action.actionTypeId() == buttonButtonPressActionTypeId) {
emit emitEvent(Event(buttonButtonPressedEventTypeId, thing->id()));
if (thing->thingClassId() == buttonThingClassId) {
if (action.actionTypeId() == buttonPressActionTypeId) {
emit emitEvent(Event(buttonPressedEventTypeId, thing->id()));
}
}
// ON/OFF Button
if (action.actionTypeId() == onOffButtonOnActionTypeId) {
emit emitEvent(Event(onOffButtonOnEventTypeId, thing->id()));

// Trigger button
if (thing->thingClassId() == triggerButtonThingClassId) {
if (action.actionTypeId() == triggerButtonTriggerActionTypeId) {
emit emitEvent(Event(triggerButtonPressedEventTypeId, thing->id()));
}
}
if (action.actionTypeId() == onOffButtonOffActionTypeId) {
emit emitEvent(Event(onOffButtonOffEventTypeId, thing->id()));

// ON/OFF Button
if (thing->thingClassId() == onOffButtonThingClassId) {
if (action.actionTypeId() == onOffButtonOnActionTypeId) {
emit emitEvent(Event(onOffButtonPressedEventTypeId, thing->id(), ParamList() << Param(onOffButtonPressedEventButtonNameParamTypeId, "On")));
} else if (action.actionTypeId() == onOffButtonOffActionTypeId) {
emit emitEvent(Event(onOffButtonPressedEventTypeId, thing->id(), ParamList() << Param(onOffButtonPressedEventButtonNameParamTypeId, "Off")));
}
}

info->finish(Thing::ThingErrorNoError);
}
68 changes: 49 additions & 19 deletions genericelements/integrationplugingenericelements.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,102 @@
"thingClasses": [
{
"id": "c0f511f9-70f5-499b-bd70-2c0e9ddd68c4",
"name": "toggleButton",
"displayName": "Toggle Button",
"createMethods": ["user"],
"name": "powerButton",
"displayName": "Power Button",
"createMethods": [ "user" ],
"interfaces": [ "power" ],
"paramTypes": [ ],
"stateTypes": [
{
"id": "b5e90567-54aa-49bd-a78a-3c19fb38aaf5",
"name": "state",
"name": "power",
"displayName": "state",
"displayNameEvent": "state changed",
"displayNameAction": "Set state",
"displayNameEvent": "power changed",
"displayNameAction": "set power",
"type": "bool",
"defaultValue": false,
"writable": true
"writable": true,
"ioType": "digitalOutput"
}
]
},
{
"id": "820b2f2d-0d92-48c8-8fd4-f94ce8fc4103",
"name": "button",
"displayName": "Button",
"createMethods": ["user"],
"createMethods": [ "user" ],
"interfaces": [ "button" ],
"paramTypes": [ ],
"actionTypes": [
{
"id": "01f38af1-b2ab-4ec3-844e-ef52f0f229a9",
"name": "buttonPress",
"name": "press",
"displayName": "press"
}
],
"eventTypes": [
{
"id": "effdbc2d-e467-4b0b-80a9-9dda251bfa5c",
"name": "buttonPressed",
"name": "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",
"name": "onOffButton",
"displayName": "ON/OFF Button",
"createMethods": ["user"],
"interfaces": [ "multibutton" ],
"paramTypes": [ ],
"actionTypes": [
{
"id": "892596d2-0863-4807-97da-469b9f7003f2",
"name": "on",
"displayName": "press ON"
"displayName": "on"
},
{
"id": "a8d64050-0b58-4ccf-b052-77ce2b7368ad",
"name": "off",
"displayName": "press OFF"
"displayName": "off"
}
],
"eventTypes": [
{
"id": "4eeba6a2-e4c7-4a2e-8360-2797d98114e6",
"name": "on",
"displayName": "ON pressed"
},
{
"id": "b636c5f3-2eb0-4682-96d4-88a4aa9d2c12",
"name": "off",
"displayName": "OFF pressed"
"name": "pressed",
"displayName": "Button pressed",
"paramTypes": [
{
"id": "2e6bc343-41a3-4634-b514-4512ae54afbc",
"name": "buttonName",
"displayName": "Button name",
"type": "QString",
"allowedValues": ["Off", "On"]
}
]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,94 +4,112 @@
<context>
<name>GenericElements</name>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="39"/>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="53"/>
<source>Generic Elements</source>
<extracomment>The name of the plugin GenericElements ({6e22161e-39b7-4416-8623-39e730721efb})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="60"/>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="68"/>
<source>nymea</source>
<extracomment>The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="54"/>
<source>Toggle Button</source>
<extracomment>The name of the ThingClass ({c0f511f9-70f5-499b-bd70-2c0e9ddd68c4})</extracomment>
<translation>Toggle Taster</translation>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="86"/>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="89"/>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="92"/>
<source>state</source>
<extracomment>The name of the ParamType (ThingClass: powerButton, ActionType: power, ID: {b5e90567-54aa-49bd-a78a-3c19fb38aaf5})
----------
The name of the ParamType (ThingClass: powerButton, EventType: power, ID: {b5e90567-54aa-49bd-a78a-3c19fb38aaf5})
----------
The name of the StateType ({b5e90567-54aa-49bd-a78a-3c19fb38aaf5}) of ThingClass powerButton</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="81"/>
<source>state changed</source>
<extracomment>The name of the EventType ({b5e90567-54aa-49bd-a78a-3c19fb38aaf5}) of ThingClass toggleButton</extracomment>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="44"/>
<source>Button</source>
<extracomment>The name of the ThingClass ({820b2f2d-0d92-48c8-8fd4-f94ce8fc4103})</extracomment>
<translation>Taster</translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="47"/>
<source>Button name</source>
<extracomment>The name of the ParamType (ThingClass: onOffButton, EventType: pressed, ID: {2e6bc343-41a3-4634-b514-4512ae54afbc})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="72"/>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="75"/>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="78"/>
<source>state</source>
<extracomment>The name of the ParamType (ThingClass: toggleButton, ActionType: state, ID: {b5e90567-54aa-49bd-a78a-3c19fb38aaf5})
----------
The name of the ParamType (ThingClass: toggleButton, EventType: state, ID: {b5e90567-54aa-49bd-a78a-3c19fb38aaf5})
----------
The name of the StateType ({b5e90567-54aa-49bd-a78a-3c19fb38aaf5}) of ThingClass toggleButton</extracomment>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="50"/>
<source>Button pressed</source>
<extracomment>The name of the EventType ({4eeba6a2-e4c7-4a2e-8360-2797d98114e6}) of ThingClass onOffButton</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="51"/>
<source>Set state</source>
<extracomment>The name of the ActionType ({b5e90567-54aa-49bd-a78a-3c19fb38aaf5}) of ThingClass toggleButton</extracomment>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="59"/>
<source>Power Button</source>
<extracomment>The name of the ThingClass ({c0f511f9-70f5-499b-bd70-2c0e9ddd68c4})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="36"/>
<source>Button</source>
<extracomment>The name of the ThingClass ({820b2f2d-0d92-48c8-8fd4-f94ce8fc4103})</extracomment>
<translation>Taster</translation>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="62"/>
<source>Trigger button</source>
<extracomment>The name of the ThingClass ({5f91923e-fc8e-48db-9de7-9a2fc36798dd})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="63"/>
<source>press</source>
<extracomment>The name of the ActionType ({01f38af1-b2ab-4ec3-844e-ef52f0f229a9}) of ThingClass button</extracomment>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="71"/>
<source>off</source>
<extracomment>The name of the ActionType ({a8d64050-0b58-4ccf-b052-77ce2b7368ad}) of ThingClass onOffButton</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="57"/>
<source>button pressed</source>
<extracomment>The name of the EventType ({effdbc2d-e467-4b0b-80a9-9dda251bfa5c}) of ThingClass button</extracomment>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="74"/>
<source>on</source>
<extracomment>The name of the ActionType ({892596d2-0863-4807-97da-469b9f7003f2}) of ThingClass onOffButton</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="48"/>
<source>ON/OFF Button</source>
<extracomment>The name of the ThingClass ({430d188c-476d-4825-a9bd-86dfa3094b56})</extracomment>
<translation>An/Aus Taster</translation>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="77"/>
<source>power changed</source>
<extracomment>The name of the EventType ({b5e90567-54aa-49bd-a78a-3c19fb38aaf5}) of ThingClass powerButton</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="69"/>
<source>press ON</source>
<extracomment>The name of the ActionType ({892596d2-0863-4807-97da-469b9f7003f2}) of ThingClass onOffButton</extracomment>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="80"/>
<source>press</source>
<extracomment>The name of the ActionType ({01f38af1-b2ab-4ec3-844e-ef52f0f229a9}) of ThingClass button</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="66"/>
<source>press OFF</source>
<extracomment>The name of the ActionType ({a8d64050-0b58-4ccf-b052-77ce2b7368ad}) of ThingClass onOffButton</extracomment>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="83"/>
<source>set power</source>
<extracomment>The name of the ActionType ({b5e90567-54aa-49bd-a78a-3c19fb38aaf5}) of ThingClass powerButton</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="45"/>
<source>ON pressed</source>
<extracomment>The name of the EventType ({4eeba6a2-e4c7-4a2e-8360-2797d98114e6}) of ThingClass onOffButton</extracomment>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="95"/>
<source>trigger</source>
<extracomment>The name of the ActionType ({da322b8e-2116-4565-805a-03f7726373c8}) of ThingClass triggerButton</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="98"/>
<source>triggered</source>
<extracomment>The name of the EventType ({51197853-0559-42a0-a97b-6ead56ae22f6}) of ThingClass triggerButton</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="42"/>
<source>OFF pressed</source>
<extracomment>The name of the EventType ({b636c5f3-2eb0-4682-96d4-88a4aa9d2c12}) of ThingClass onOffButton</extracomment>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="65"/>
<source>button pressed</source>
<extracomment>The name of the EventType ({effdbc2d-e467-4b0b-80a9-9dda251bfa5c}) of ThingClass button</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/genericelements/plugininfo.h" line="56"/>
<source>ON/OFF Button</source>
<extracomment>The name of the ThingClass ({430d188c-476d-4825-a9bd-86dfa3094b56})</extracomment>
<translation>An/Aus Taster</translation>
</message>
</context>
</TS>
Loading

0 comments on commit d2dd52f

Please sign in to comment.