Skip to content

Commit

Permalink
Merge pull request #968 from danielpeintner/issue-966
Browse files Browse the repository at this point in the history
TestThing - fire events on write
  • Loading branch information
relu91 authored May 3, 2023
2 parents 15abd26 + ff56ec8 commit 3857aab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 6 additions & 4 deletions examples/testthing/testthing.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -12,7 +12,6 @@
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/

function checkPropertyWrite(expected, actual) {
const output = "Property " + expected + " written with " + actual;
if (expected === actual) {
Expand Down Expand Up @@ -83,8 +82,8 @@ WoT.produce({
description: "Action without input nor output",
},
"void-int": {
title: "void-void Action",
description: "Action without input nor output",
title: "void-int Action",
description: "Action without input, but with integer output",
},
"int-void": {
title: "int-void Action",
Expand Down Expand Up @@ -158,6 +157,7 @@ WoT.produce({
const localBool = await value.value();
checkPropertyWrite("boolean", typeof localBool);
bool = localBool;
thing.emitEvent("on-bool", bool);
})
.setPropertyReadHandler("bool", async () => bool)
.setPropertyWriteHandler("int", async (value) => {
Expand All @@ -168,12 +168,14 @@ WoT.produce({
checkPropertyWrite("integer", typeof value);
}
int = localInt;
thing.emitEvent("on-int", int);
})
.setPropertyReadHandler("int", async () => int)
.setPropertyWriteHandler("num", async (value) => {
const localNum = await value.value();
checkPropertyWrite("number", typeof localNum);
num = localNum;
thing.emitEvent("on-num", num);
})
.setPropertyReadHandler("num", async () => num)
.setPropertyWriteHandler("string", async (value) => {
Expand Down
9 changes: 6 additions & 3 deletions packages/examples/src/testthing/testthing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -86,8 +86,8 @@ WoT.produce({
description: "Action without input nor output",
},
"void-int": {
title: "void-void Action",
description: "Action without input nor output",
title: "void-int Action",
description: "Action without input, but with integer output",
},
"int-void": {
title: "int-void Action",
Expand Down Expand Up @@ -162,6 +162,7 @@ WoT.produce({
const localBool = await value.value();
checkPropertyWrite("boolean", typeof localBool);
bool = localBool as boolean;
thing.emitEvent("on-bool", bool);
})
.setPropertyReadHandler("bool", async () => bool)
.setPropertyWriteHandler("int", async (value) => {
Expand All @@ -172,12 +173,14 @@ WoT.produce({
checkPropertyWrite("integer", typeof value);
}
int = localInt as number;
thing.emitEvent("on-int", int);
})
.setPropertyReadHandler("int", async () => int)
.setPropertyWriteHandler("num", async (value) => {
const localNum = await value.value();
checkPropertyWrite("number", typeof localNum);
num = localNum as number;
thing.emitEvent("on-num", num);
})
.setPropertyReadHandler("num", async () => num)
.setPropertyWriteHandler("string", async (value) => {
Expand Down

0 comments on commit 3857aab

Please sign in to comment.