-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from eclipse/readAllProperties
Read all properties
- Loading branch information
Showing
5 changed files
with
149 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2018 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and | ||
* Document License (2015-05-13) which is available at | ||
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513 | ||
********************************************************************************/ | ||
|
||
const NAME_PROPERTY_COUNT = "count"; | ||
const NAME_PROPERTY_LAST_CHANGE = "lastChange"; | ||
const NAME_ACTION_INCREMENT = "increment"; | ||
const NAME_ACTION_DECREMENT = "decrement"; | ||
const NAME_ACTION_RESET = "reset"; | ||
|
||
let thing = WoT.produce({ | ||
name: "counter", | ||
description: "counter example Thing", | ||
"@context": ["http://www.w3.org/ns/td", {"iot": "http://example.org/iot"}], | ||
}); | ||
|
||
console.log("Produced " + thing.name); | ||
|
||
thing.addProperty( | ||
NAME_PROPERTY_COUNT, | ||
{ | ||
type: "integer", | ||
description: "current counter value", | ||
"iot:Custom": "example annotation", | ||
observable: true, | ||
writable: true | ||
}, | ||
0); | ||
thing.addProperty( | ||
NAME_PROPERTY_LAST_CHANGE, | ||
{ | ||
type: "string", | ||
description: "last change of counter value", | ||
observable: true, | ||
writable: false | ||
}, | ||
(new Date()).toUTCString()); | ||
|
||
thing.addAction( | ||
NAME_ACTION_INCREMENT, | ||
{}, | ||
() => { | ||
console.log("Incrementing"); | ||
return thing.properties[NAME_PROPERTY_COUNT].read().then( (count) => { | ||
let value = count + 1; | ||
thing.properties[NAME_PROPERTY_COUNT].write(value); | ||
thing.properties[NAME_PROPERTY_LAST_CHANGE].write((new Date()).toUTCString()); | ||
}); | ||
}); | ||
|
||
thing.addAction( | ||
NAME_ACTION_DECREMENT, | ||
{}, | ||
() => { | ||
console.log("Decrementing"); | ||
return thing.properties[NAME_PROPERTY_COUNT].read().then( (count) => { | ||
let value = count - 1; | ||
thing.properties[NAME_PROPERTY_COUNT].write(value); | ||
thing.properties[NAME_PROPERTY_LAST_CHANGE].write((new Date()).toUTCString()); | ||
}); | ||
}); | ||
|
||
thing.addAction( | ||
NAME_ACTION_RESET, | ||
{}, | ||
() => { | ||
console.log("Resetting"); | ||
thing.properties[NAME_PROPERTY_COUNT].write(0); | ||
thing.properties[NAME_PROPERTY_LAST_CHANGE].write((new Date()).toUTCString()); | ||
}); | ||
|
||
// test setting metadata | ||
thing["support"] = "git://github.com/eclipse/thingweb.node-wot.git"; | ||
|
||
thing.expose().then( () => { console.info(thing.name + " ready"); } ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters