Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestThing fixes #1227

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 38 additions & 14 deletions examples/testthing/testthing.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,44 @@ WoT.produce({
title: "TestThing",
properties: {
bool: {
title: "true/false",
title: "Boolean",
description: "Property that can be set to true or false",
type: "boolean",
},
int: {
title: "Integer number",
title: "Integer",
description: "An integer value that can be read and written",
type: "integer",
},
num: {
title: "Floating point",
title: "Number",
description: "A floating point value that can be read and written",
type: "number",
},
string: {
title: "String",
description: "A string value that can be read and written",
type: "string",
},
array: {
title: "Tuple",
title: "Array",
description: "An Array (List) with no structure that can be read and written",
type: "array",
items: {},
},
object: {
title: "ID-name",
description: "Object with ID and name",
title: "Object",
description: "An object with id and name that can be read and written",
type: "object",
properties: {
id: {
title: "ID",
description: "Internal identifier",
description: "Integer identifier",
type: "integer",
},
name: {
title: "Name",
description: "Public name",
description: "Name associated to the identifier",
type: "string",
},
},
Expand Down Expand Up @@ -133,18 +139,33 @@ WoT.produce({
},
events: {
"on-bool": {
title: "on-bool Event",
description: "Event with boolean data",
title: "Bool Property Change",
description: "Event with boolean data that is emitted when the bool property is written to",
data: { type: "boolean" },
},
"on-int": {
title: "on-int Event",
description: "Event with integer data",
title: "Int Property Change",
description: "Event with integer data that is emitted when the int property is written to ",
data: { type: "integer" },
},
"on-num": {
title: "on-num Event",
description: "Event with number data",
title: "Num Property Change",
description: "Event with number data that is emitted when the num property is written to",
data: { type: "number" },
},
"on-string": {
title: "String Property Change",
description: "Event with number data that is emitted when the string property is written to",
data: { type: "number" },
},
"on-array": {
title: "Array Property Change",
description: "Event with number data that is emitted when the array property is written to",
data: { type: "number" },
},
"on-object": {
title: "Object Property Change",
description: "Event with number data that is emitted when the object property is written to",
data: { type: "number" },
},
},
Expand Down Expand Up @@ -182,6 +203,7 @@ WoT.produce({
const localString = await value.value();
checkPropertyWrite("string", typeof localString);
string = localString;
thing.emitEvent("on-string", string);
})
.setPropertyReadHandler("string", async () => string)
.setPropertyWriteHandler("array", async (value) => {
Expand All @@ -192,6 +214,7 @@ WoT.produce({
checkPropertyWrite("array", typeof localArray);
}
array = localArray;
thing.emitEvent("on-array", array);
})
.setPropertyReadHandler("array", async () => array)
.setPropertyWriteHandler("object", async (value) => {
Expand All @@ -202,6 +225,7 @@ WoT.produce({
checkPropertyWrite("object", typeof localObject);
}
object = localObject;
thing.emitEvent("on-object", object);
})
.setPropertyReadHandler("object", async () => object);
// set action handlers
Expand Down
52 changes: 38 additions & 14 deletions packages/examples/src/testthing/testthing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,44 @@ WoT.produce({
title: "TestThing",
properties: {
bool: {
title: "true/false",
title: "Boolean",
description: "Property that can be set to true or false",
type: "boolean",
},
int: {
title: "Integer number",
title: "Integer",
description: "An integer value that can be read and written",
type: "integer",
},
num: {
title: "Floating point",
title: "Number",
description: "A floating point value that can be read and written",
type: "number",
},
string: {
title: "String",
description: "A string value that can be read and written",
type: "string",
},
array: {
title: "Tuple",
title: "Array",
description: "An Array (List) with no structure that can be read and written",
type: "array",
items: {},
},
object: {
title: "ID-name",
description: "Object with ID and name",
title: "Object",
description: "An object with id and name that can be read and written",
type: "object",
properties: {
id: {
title: "ID",
description: "Internal identifier",
description: "Integer identifier",
type: "integer",
},
name: {
title: "Name",
description: "Public name",
description: "Name associated to the identifier",
type: "string",
},
},
Expand Down Expand Up @@ -137,18 +143,33 @@ WoT.produce({
},
events: {
"on-bool": {
title: "on-bool Event",
description: "Event with boolean data",
title: "Bool Property Change",
description: "Event with boolean data that is emitted when the bool property is written to",
data: { type: "boolean" },
},
"on-int": {
title: "on-int Event",
description: "Event with integer data",
title: "Int Property Change",
description: "Event with integer data that is emitted when the int property is written to ",
data: { type: "integer" },
},
"on-num": {
title: "on-num Event",
description: "Event with number data",
title: "Num Property Change",
description: "Event with number data that is emitted when the num property is written to",
data: { type: "number" },
},
"on-string": {
title: "String Property Change",
description: "Event with number data that is emitted when the string property is written to",
data: { type: "number" },
},
"on-array": {
title: "Array Property Change",
description: "Event with number data that is emitted when the array property is written to",
data: { type: "number" },
},
"on-object": {
title: "Object Property Change",
description: "Event with number data that is emitted when the object property is written to",
data: { type: "number" },
},
},
Expand Down Expand Up @@ -187,6 +208,7 @@ WoT.produce({
const localString = await value.value();
checkPropertyWrite("string", typeof localString);
string = localString as string;
thing.emitEvent("on-string", string);
})
.setPropertyReadHandler("string", async () => string)
.setPropertyWriteHandler("array", async (value) => {
Expand All @@ -197,6 +219,7 @@ WoT.produce({
checkPropertyWrite("array", typeof localArray);
}
array = localArray as unknown[];
thing.emitEvent("on-array", array);
})
.setPropertyReadHandler("array", async () => array)
.setPropertyWriteHandler("object", async (value) => {
Expand All @@ -207,6 +230,7 @@ WoT.produce({
checkPropertyWrite("object", typeof localObject);
}
object = localObject as Record<string, unknown>;
thing.emitEvent("on-object", object);
})
.setPropertyReadHandler("object", async () => object);

Expand Down
Loading