You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As in these examples,
in a TD we may want to define security metadata dictionaries and reuse them later by name.
Similarly, we could have a section in the TD that would define type definitions which can be reused inside the TD (e.g. in action parameters).
Mapping this to the Scripting API, it would be possible to use the following conventions:
have @securityDefinitions and @typeDefinitions array properties in the ThingTemplate. If defined and not empty, they would initialize internal slots for the given Thing, as dictionaries of dictionaries.
everywhere a security dictionary or type definition dictionary is needed, also a string would be accepted, if it matched one of the entries in the corresponding internal slot.
This would make the example code shorter and more concise (define types and security metadata only in one place).
For instance, the quite verbose Example 7 would become a little more concise:
//EXAMPLE 7: Create a new blank exposed Thingtry{varthing=WoT.produce({name: "tempSensor","@typeDefinitions": {temperatureType: {type: "number",value: 0.0,minimum: -50,maximum: 10000,forms: []}},properties: {temperature: "temperatureType"},actions: {reset: {description: "Reset the temperature sensor",input: {temperature: "temperatureType"},output: null,forms: []},},events: {onchange: {type: "temperatureType"},links: []});thing.expose().then(()=>{thing.register();});// define Thing business logicsetInterval(async()=>{letmock=Math.random()*100;thing.writeProperty("temperature",mock);letold=awaitthing.readProperty("max");if(old<mock){thing.writeProperty("max",mock);thing.emitEvent("onchange");}},1000);}catch(err){console.log("Error creating ExposedThing: "+err);}
The text was updated successfully, but these errors were encountered:
As in these examples,
in a TD we may want to define security metadata dictionaries and reuse them later by name.
Similarly, we could have a section in the TD that would define type definitions which can be reused inside the TD (e.g. in action parameters).
Mapping this to the Scripting API, it would be possible to use the following conventions:
@securityDefinitions
and@typeDefinitions
array properties in the ThingTemplate. If defined and not empty, they would initialize internal slots for the given Thing, as dictionaries of dictionaries.This would make the example code shorter and more concise (define types and security metadata only in one place).
For instance, the quite verbose Example 7 would become a little more concise:
The text was updated successfully, but these errors were encountered: