Skip to content

Commit

Permalink
Improve TD to reflect latest binding spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-work committed Feb 2, 2018
1 parent 62bd37b commit a3102be
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 10 deletions.
10 changes: 5 additions & 5 deletions Prague Plugfest/PragueAPI.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* Source: https://github.com/w3c/wot-scripting-api/issues/82
*
*/

interface WoT {
interface WoT {
Observable<ConsumedThing> discover(optional ThingFilter filter);
Promise<ThingDescription> fetchTD(USVString url);
ConsumedThing consume(ThingDescription td); // with fetch split out, we could make it synchrounous
Expand Down Expand Up @@ -46,7 +46,7 @@ interface ExposedThing: ConsumedThing {
Promise<void> register(USVString url); // convenience for Thing Directory
Promise<void> unregister(USVString url); // convenience for Thing Directory
Promise<void> emitEvent(DOMString eventName, any payload);

void addProperty(ThingPropertyInit property); // throws on error
void removeProperty(DOMString name); // throws on error
void addAction(ThingActionInit action); // throws on error
Expand All @@ -59,7 +59,7 @@ typedef DOMString ValueType; // Linked Data JSON Schema

dictionary ThingPropertyInit {
DOMString name;
ValueType type;
ValueType type;
any initValue;
boolean? writable = false;
boolean? observable = false;
Expand All @@ -71,7 +71,7 @@ dictionary ThingPropertyInit {

dictionary ThingActionInit {
DOMString name;
ValueType inputType;
ValueType inputType;
ValueType outputType;
Function action;
sequence<SemanticType>? semanticTypes = [];
Expand Down
31 changes: 26 additions & 5 deletions Prague Plugfest/TD-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,29 @@
"type": "object",

"properties": {
"@type": { "$ref": "#/definitions/type_declaration"},
"@context": { "type": "array",
"items": {"$ref": "#/definitions/jsonld_url"}},
"base" : {"$ref": "#/definitions/url"},
"@type": { "$ref": "#/definitions/type_declaration"},
"@context": { "type": "array",
"items": {"$ref": "#/definitions/context"}},
"name": { "type": "string" },
"interaction": { "type": "array",
"items": { "$ref": "#/definitions/interaction" }},
"link": { "type": "array",
"items": { "$ref": "#/definitions/link" }}
"items": { "$ref": "#/definitions/link" }},
"form": { "type": "array",
"items": { "$ref": "#/definitions/form" }}
},
"required": ["@type", "name", "interaction", "link"],
"required": ["@type", "name", "interaction"],
"additionalProperties": false,


"definitions": {
"context": { "anyOf": [
{ "$ref": "#/definitions/jsonld_url" },
{ "type": "object" }
]
},

"type_declaration": { "type": "array",
"items": { "type" : "string" }},

Expand Down Expand Up @@ -89,11 +98,23 @@
},
"required": ["href", "rel"]
},

"form": {
"type": "object",
"properties": {
"href": { "$ref": "#/definitions/url" },
"rel": { "type": "string" }
},
"required": ["href", "rel"]
},


"url": {
"type": "string",
"format": "uri",
"pattern": "(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(([^#]*))?(#(.*))?"
},

"jsonld_url": {
"type": "string",
"format": "uri",
Expand Down
83 changes: 83 additions & 0 deletions Prague Plugfest/binding1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"@context": [
"http://w3c.github.io/wot/w3c-wot-td-context.jsonld",
"http://w3c.github.io/wot/w3c-wot-common-context.jsonld",
{"iot": "http://iotschema.org/"}
],
"@type": [ "Thing", "iot:Light", "iot:Dimmer", "iot:BinarySwitch" ],
"name": "Lamp",
"interaction": [
{
"name": "Switch State",
"@type": ["Property", "iot:SwitchStatus"],
"outputdata": {
"@type": ["iot:SwitchData"],
"type": "boolean"
},
"form": [
{
"href": "/example/light/currentswitch",
"mediatype": "application/json"
}
]
},
{
"name": "Current brightness",
"@type": ["Property", "iot:CurrentDimmer"],
"outputdata": {
"@type": ["iot:DimmerData"],
"type": "number"
},
"form": [
{
"href": "/example/light/currentdimmer",
"mediatype": "application/json"
}
]
},
{
"name": "Switch On",
"@type": ["Action", "iot:SwitchOn"],
"outputdata": {
"@type": "iot:SwitchData",
"type": "boolean",
"const": true
},
"form": [
{
"href": "/example/light/currentswitch",
"mediatype": "application/json"
}
]
},
{
"name": "Switch Off",
"@type": ["Action", "iot:SwitchOff"],
"outputdata": {
"@type": "iot:SwitchData",
"type": "boolean",
"const": false
},
"form": [
{
"href": "/example/light/currentswitch",
"mediatype": "application/json"
}
]
},
{
"name": "Set brightness level",
"@type": ["Action", "iot:SetDimmer"],
"inputdata": {
"@type": ["iot:DimmerData"],
"type": "number"
},
"form": [
{
"href": "/example/light/currentdimmer",
"mediatype": "application/json"
}
]
}
]
}
185 changes: 185 additions & 0 deletions Prague Plugfest/binding2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
{
"@context": [
"http://w3c.github.io/wot/w3c-wot-td-context.jsonld",
"http://w3c.github.io/wot/w3c-wot-common-context.jsonld",
{"iot": "http://iotschema.org/"}
],
"base": "http://exampl.com/",
"@type": [ "Thing", "iot:Light", "iot:Dimmer", "iot:BinarySwitch" ],
"name": "Lamp",
"interaction": [
{
"name": "Switch State",
"@type": ["Property", "iot:SwitchStatus"],
"outputdata": {
"type": "object",
"observable": "true",
"field": [
{
"name": "switch",
"@type": ["iot:SwitchData"],
"type": "boolean"
}
]
},
"form": [
{
"href": "/example/light/currentswitch",
"mediatype": "application/json",
"rel": "td:readProperty",
"http:methodName": "http:get"
},
{
"href": "/example/light/currentswitch",
"mediatype": "application/json",
"rel": "td:writeProperty",
"http:methodName": "http:post"
},
{
"href": "mqtt://example.com/example/light/currentswitch",
"rel": "td:observe",
"mqtt:methodName": "mqtt:subscribe"
}
]
},
{
"name": "Current brightness",
"@type": ["Property", "iot:CurrentDimmer"],
"outputData": {
"type": "object",
"observable": "true",
"field": [
{
"name": "brightness",
"type": "integer",
"@type": ["iot:DimmerData" ],
"min": 0,
"max": 255
}
]
},
"form": [
{
"href": "/example/light/currentdimmer",
"mediatype": "application/json",
"rel": "td:readProperty",
"http:methodName": "http:get"
},
{
"href": "/example/light/currentdimmer",
"mediatype": "application/json",
"rel": "td:writeProperty",
"http:methodName": "http:post"
},
{
"href": "mqtt://example.com/example/light/currentdimmer",
"rel": "td:observe",
"mqtt:methodName": "mqtt:subscribe"
}
]
},
{
"name": "Transition Time",
"@type": ["Property", "iot:TransitionTime"],
"outputData": {
"type": "object",
"field": [
{
"name": "transitiontime",
"type": "integer",
"@type": ["iot:TransitionTimeData" ],
"min": 0,
"max": 255
}
]
},
"form": [
{
"href": "/example/light/transitiontime",
"mediatype": "application/json",
"rel": "td:readProperty",
"http:methodName": "http:get"
},
{
"href": "/example/light/transitiontime",
"mediatype": "application/json",
"rel": "td:writeProperty",
"http:methodName": "http:post"
}
]
},
{
"name": "Switch On",
"@type": ["Action", "iot:SwitchOn"],
"outputdata": {
"type": "object",
"field": [
{
"name": "switch",
"const": true
}
]
},
"form": [
{
"href": "/example/light/currentswitch",
"mediatype": "application/json",
"rel": "td:invokeAction",
"http:methodName": "http:post"
}
]
},
{
"name": "Switch Off",
"@type": ["Action", "iot:SwitchOff"],
"outputdata": {
"type": "object",
"field": [
{
"name": "switch",
"const": false
}
]
},
"form": [
{
"href": "/example/light/currentswitch",
"mediatype": "application/json",
"rel": "td:invokeAction",
"http:methodName": "http:post"
}
]
},
{
"name": "Set brightness level",
"@type": ["Action", "iot:SetDimmer"],
"inputData": {
"type": "object",
"field": [
{
"name": "brightness",
"type": "integer",
"@type": ["iot:DimmerData"],
"min": 0,
"max": 255
},
{
"name": "transitiontime",
"type": "integer",
"@type": ["iot:TransitionTimeData"],
"min": 0,
"max": 65535
}
]
},
"form": [
{
"href": "/example/light/",
"mediatype": "application/json",
"rel": "td:invokeAction",
"http:methodName": "http:post"
}
]
}
]
}

0 comments on commit a3102be

Please sign in to comment.