Spanish Total.js
Deutsch
Dokumentation Für KI-Agenten
Inhalt

Settings and options

Give each device its own configuration and the whole driver its own options.

.md Website

Diese Seite ist noch nicht übersetzt. Du liest das Original.

Auf dieser Seite

A driver has two kinds of settings:

  • The configuration belongs to one device. People change it with Options > Configure in the device detail.
  • The options belong to the driver and apply to all its devices. People change them with Drivers > ... > Settings.

Configuration of a device

Set the default values in exports.config and add a <settings> form with a field for each key:

<script total>
    exports.config = { offset: 0 };

    exports.make = function(instance, config) {
        instance.message = function($) {
            var data = $.data;
            if (data.temperature != null)
                instance.newmessage(data.temperature + (config.offset || 0)).send('temperature');
            $.destroy();
        };
    };
</script>

<settings>
    <div class="padding">
        <ui-component name="input" path="?.offset" config="type:number">Temperature correction (°C)</ui-component>
    </div>
</settings>

A new device starts with a copy of exports.config. The config argument of exports.make holds the configuration of the device, and the stream applies a changed configuration within three minutes. config.sn holds the Device identifier too.

Without a <settings> part, the device menu has no Configure item.

Options of the driver

exports.options lists the options with their default values:

exports.options = [{ id: 'token', type: 'string', name: 'Token', value: '' }];

The Settings dialog of the driver shows one field for each option. In the code, the values are in com.options in exports.install, and in instance.module.options in exports.make:

exports.make = function(instance, config) {
    instance.message = function($) {
        var token = instance.module.options.token;
        // ...
    };
};

Saving a new version of the driver keeps the values people set. The stream applies changed options within three minutes.

Hergestellt in Europa