mirror of https://github.com/nymea/nymea.git
added ON/OFF button and button
fixed cmdmgr double execution of actions without paramspull/135/head
parent
78272ecdd3
commit
cc772678ec
|
|
@ -25,6 +25,16 @@ DeviceClassId toggleButtonDeviceClassId = DeviceClassId("c0f511f9-70f5-499b-bd70
|
|||
ActionTypeId toggleButtonToggleActionTypeId = ActionTypeId("47bdc15a-b393-4dc2-801b-845420cdfda3");
|
||||
StateTypeId toggleButtonStatusStateTypeId = StateTypeId("b5e90567-54aa-49bd-a78a-3c19fb38aaf5");
|
||||
|
||||
DeviceClassId buttonDeviceClassId = DeviceClassId("820b2f2d-0d92-48c8-8fd4-f94ce8fc4103");
|
||||
ActionTypeId buttonPressActionTypeId = ActionTypeId("01f38af1-b2ab-4ec3-844e-ef52f0f229a9");
|
||||
EventTypeId buttonPressedEventTypeId = EventTypeId("effdbc2d-e467-4b0b-80a9-9dda251bfa5c");
|
||||
|
||||
DeviceClassId onOffButtonDeviceClassId = DeviceClassId("430d188c-476d-4825-a9bd-86dfa3094b56");
|
||||
ActionTypeId onOffButtonOnActionTypeId = ActionTypeId("892596d2-0863-4807-97da-469b9f7003f2");
|
||||
ActionTypeId onOffButtonOffActionTypeId = ActionTypeId("a8d64050-0b58-4ccf-b052-77ce2b7368ad");
|
||||
EventTypeId onOffButtonOnEventTypeId = EventTypeId("4eeba6a2-e4c7-4a2e-8360-2797d98114e6");
|
||||
EventTypeId onOffButtonOffEventTypeId = EventTypeId("b636c5f3-2eb0-4682-96d4-88a4aa9d2c12");
|
||||
|
||||
DevicePluginGenericElements::DevicePluginGenericElements()
|
||||
{
|
||||
}
|
||||
|
|
@ -36,20 +46,53 @@ DeviceManager::HardwareResources DevicePluginGenericElements::requiredHardware()
|
|||
|
||||
DeviceManager::DeviceSetupStatus DevicePluginGenericElements::setupDevice(Device *device)
|
||||
{
|
||||
// Toggle Button
|
||||
if (device->deviceClassId() == toggleButtonDeviceClassId) {
|
||||
device->setName(device->paramValue("name").toString() +" (Toggle Button)");
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
// Button
|
||||
if (device->deviceClassId() == buttonDeviceClassId) {
|
||||
device->setName(device->paramValue("name").toString() +" (Button)");
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
// ON/OFF Button
|
||||
if (device->deviceClassId() == onOffButtonDeviceClassId) {
|
||||
device->setName(device->paramValue("name").toString() +" (ON/OFF Button)");
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
return DeviceManager::DeviceSetupStatusFailure;
|
||||
}
|
||||
|
||||
DeviceManager::DeviceError DevicePluginGenericElements::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
if (device->deviceClassId() == toggleButtonDeviceClassId
|
||||
&& action.actionTypeId() == toggleButtonToggleActionTypeId) {
|
||||
bool currentStatus = device->stateValue(toggleButtonStatusStateTypeId).toBool();
|
||||
device->setStateValue(toggleButtonStatusStateTypeId, !currentStatus);
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
// Toggle Button
|
||||
if (device->deviceClassId() == toggleButtonDeviceClassId ) {
|
||||
if (action.actionTypeId() == toggleButtonToggleActionTypeId) {
|
||||
device->setStateValue(toggleButtonStatusStateTypeId, !device->stateValue(toggleButtonStatusStateTypeId).toBool());
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
}
|
||||
// Button
|
||||
if (device->deviceClassId() == buttonDeviceClassId ) {
|
||||
if (action.actionTypeId() == buttonPressActionTypeId) {
|
||||
emit emitEvent(Event(buttonPressedEventTypeId, device->id()));
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
}
|
||||
// ON/OFF Button
|
||||
if (device->deviceClassId() == onOffButtonDeviceClassId ) {
|
||||
if (action.actionTypeId() == onOffButtonOnActionTypeId) {
|
||||
emit emitEvent(Event(onOffButtonOnEventTypeId, device->id()));
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
if (action.actionTypeId() == onOffButtonOffActionTypeId) {
|
||||
emit emitEvent(Event(onOffButtonOffEventTypeId, device->id()));
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
}
|
||||
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,9 @@
|
|||
"stateTypes": [
|
||||
{
|
||||
"id": "b5e90567-54aa-49bd-a78a-3c19fb38aaf5",
|
||||
"name": "status",
|
||||
"name": "state",
|
||||
"type": "bool",
|
||||
"defaultValue": false
|
||||
}
|
||||
],
|
||||
"actionTypes": [
|
||||
|
|
@ -29,6 +30,60 @@
|
|||
"name": "toggle"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"deviceClassId": "820b2f2d-0d92-48c8-8fd4-f94ce8fc4103",
|
||||
"name": "Button",
|
||||
"createMethods": ["user"],
|
||||
"paramTypes": [
|
||||
{
|
||||
"name": "name",
|
||||
"type": "QString"
|
||||
}
|
||||
],
|
||||
"actionTypes": [
|
||||
{
|
||||
"id": "01f38af1-b2ab-4ec3-844e-ef52f0f229a9",
|
||||
"name": "press"
|
||||
}
|
||||
],
|
||||
"eventTypes": [
|
||||
{
|
||||
"id": "effdbc2d-e467-4b0b-80a9-9dda251bfa5c",
|
||||
"name": "button pressed"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"deviceClassId": "430d188c-476d-4825-a9bd-86dfa3094b56",
|
||||
"name": "ON/OFF Button",
|
||||
"createMethods": ["user"],
|
||||
"paramTypes": [
|
||||
{
|
||||
"name": "name",
|
||||
"type": "QString"
|
||||
}
|
||||
],
|
||||
"actionTypes": [
|
||||
{
|
||||
"id": "892596d2-0863-4807-97da-469b9f7003f2",
|
||||
"name": "press ON"
|
||||
},
|
||||
{
|
||||
"id": "a8d64050-0b58-4ccf-b052-77ce2b7368ad",
|
||||
"name": "press OFF"
|
||||
}
|
||||
],
|
||||
"eventTypes": [
|
||||
{
|
||||
"id": "4eeba6a2-e4c7-4a2e-8360-2797d98114e6",
|
||||
"name": "ON pressed"
|
||||
},
|
||||
{
|
||||
"id": "b636c5f3-2eb0-4682-96d4-88a4aa9d2c12",
|
||||
"name": "OFF pressed"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -344,7 +344,7 @@ def execute_action():
|
|||
params = {}
|
||||
params['actionTypeId'] = actionTypeId
|
||||
params['deviceId'] = deviceId
|
||||
send_command("Actions.ExecuteAction", params)
|
||||
# send_command("Actions.ExecuteAction", params)
|
||||
actionType = get_actionType(actionTypeId)
|
||||
actionParams = read_params(actionType['paramTypes'])
|
||||
params['params'] = actionParams
|
||||
|
|
|
|||
Loading…
Reference in New Issue