Commands
Let people send commands to a device from its detail and handle them in the driver.
Diese Seite ist noch nicht übersetzt. Du liest das Original.
Auf dieser Seite
A command is an input of the driver with a small form. People send it with Commands in the device detail, and the driver receives it in instance.message.
Define a command
Add an input with an html property. The HTML is the form of the command, and each field writes to one key of the payload:
exports.inputs = [
{ id: 'input', name: 'Input' },
{ id: 'interval', name: 'Change interval', html: '<ui-component name="input" path="?.minutes" config="type:number;required:1">Minutes between readings</ui-component>' }
];Inputs without html are not commands. The Commands button is available only when the driver has at least one command.
Handle a command
$.input is the id of the input, and $.data is the payload of the form:
instance.message = function($) {
if ($.input === 'interval') {
instance.debug('Interval changed to', $.data.minutes, 'minutes');
// Send the new interval to the device here
$.destroy();
return;
}
// ... readings
$.destroy();
};The stream checks for new commands every five seconds and delivers each command once. How the command reaches the device, for example through an API of the device, is up to the driver.