GSoC 2019 Coding Period Week 11
By Loong
To enable the user to add a Thing Action to a Thing, I create a custom Thing action field to associate the user-created Thing Action with a Thing.
The user needs to create a custom Thing Action and then choose which Thing Action to add when creating a Thing.
/**
* Fades a multi level switch to a given level over a given duration.
*
* @WotapiAction(
* id = "fade",
* access = {"administer site configuration"},
* description = "Fades a multi level switch to a given level over a given duration.",
* at_type = "FadeAction",
* title = "Fade",
* )
*/
class FadeAction extends WotapiActionBase {
Used to define the input data schema of the action.
/**
* {@inheritdoc}
*/
public static function input() {
return [
'type' => 'object',
'properties' => [
'brightness' => [
'type' => 'integer',
'minimum' => 0,
'maximum' => 100,
],
'duration' => [
'type' => 'integer',
'minimum' => 0,
'unit' => 'milliseconds',
],
],
];
}
After the user has coded an Action, user can add a Thing Action when creating a Thing
According to the specification, it should be possible to retrieve the Action object’s information in the /things interface.
2.11 Action object
An action object describes a function which can be carried out on a device.
In discussions with the mozilla-iot/webthing-node project maintainers, I will use the brightness test.
Also, the input for your action was invalid (you used level instead of brightness) – unless you’re on a super old version of the library.
Finally, the ::execute() method does the actual work. It is not yet possible to invoke the custom ::execute() method.But that’s how Thing action works.
/**
* {@inheritdoc}
*/
public function execute(ParameterBag $params) {
// A function which can be carried out on a device
return;
}