├── .jshintrc
├── DIST.sh
├── Gruntfile.js
├── LICENSE.txt
├── README.md
├── bridge.js
├── docs
├── README.md
├── architecture.md
├── atomic-theory.md
├── bands.md
├── bridges.md
├── core.md
├── faq.md
├── homestar-old.md
├── homestar.md
├── install.md
├── modules.md
├── semantics.md
├── thing.md
└── transporters.md
├── exit.js
├── helpers.js
├── helpers
├── bridge.js
├── id.js
├── is.js
└── version.js
├── iotdb.js
├── modules.js
├── package.json
├── samples
├── test-denon-band.js
├── test-denon-volume.js
├── test-earthquake.js
├── test-hue.js
├── test-lifx.js
├── test-multiple.js
├── test-plug.js
├── test-smartthings.js
└── test-wemo.js
├── settings.js
├── test
├── data
│ ├── abstract-clock.jsonld
│ ├── abstract-stove-oven.jsonld
│ ├── cfg1
│ │ ├── .d
│ │ ├── .d.js
│ │ ├── .d.json
│ │ ├── a.js
│ │ ├── a.json
│ │ ├── b.js
│ │ └── c.json
│ ├── cfg2
│ │ ├── a.json
│ │ ├── b.js
│ │ ├── e.js
│ │ └── f.json
│ └── cfg3
│ │ ├── sub1
│ │ └── file1.txt
│ │ └── sub2
│ │ └── file2.txt
├── instrument
│ ├── attribute.js
│ ├── definitions.js
│ ├── homestar-broken
│ │ ├── index.js
│ │ └── package.json
│ ├── homestar-test
│ │ ├── .jshintrc
│ │ ├── DIST.sh
│ │ ├── Gruntfile.js
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── TestBridge.js
│ │ ├── homestar.json
│ │ ├── index.js
│ │ ├── models
│ │ │ ├── Test.iotql
│ │ │ ├── Test.js
│ │ │ ├── TestMatch.js
│ │ │ ├── TestMissingBridge.js
│ │ │ ├── TestMissingModel.js
│ │ │ ├── TestNoDiscover.js
│ │ │ └── test.json
│ │ ├── package.json
│ │ └── samples
│ │ │ └── iotdb_template.js
│ ├── iotdb.js
│ ├── model_maker.js
│ └── settings
│ │ └── .iotdb
├── test_bridge.js
├── test_bridge_wrapper.js
├── test_color.js
├── test_connect_bands.js
├── test_convert.js
├── test_d_transform.js
├── test_exit.js
├── test_hash.js
├── test_helpers_identifier.js
├── test_helpers_identity.js
├── test_id.js
├── test_id_thing_urn.js
├── test_id_user.js
├── test_iotdb.js
├── test_iotdb_connect.js
├── test_iotdb_id.js
├── test_iotdb_things.js
├── test_is.js
├── test_ld.js
├── test_ld_add.js
├── test_ld_compact.js
├── test_ld_contains.js
├── test_ld_extend.js
├── test_ld_first.js
├── test_ld_list.js
├── test_ld_remove.js
├── test_ld_set.js
├── test_modules.js
├── test_net.js
├── test_queue.js
├── test_reset.js
├── test_settings.js
├── test_settings_set.js
├── test_temperature.js
├── test_thing_manager.js
├── test_thing_set.js
├── test_thing_set_connect.js
├── test_thing_set_search.js
├── test_thing_set_search_dynamic.js
├── test_thing_set_values.js
├── test_thing_set_with.js
├── test_thing_set_with_facets.js
├── test_thing_set_with_name.js
├── test_thing_set_with_tag.js
├── test_thing_set_with_zones.js
├── test_timestamp.js
├── test_users.js
├── test_version.js
├── test_windows.js
└── to-be-deleted
│ ├── test_attribute_bounds.js
│ ├── test_attribute_convert.js
│ ├── test_attribute_datetime.js
│ ├── test_attribute_format.js
│ ├── test_attribute_io.js
│ ├── test_attribute_list.js
│ ├── test_attribute_preference.js
│ ├── test_attribute_rgb.js
│ ├── test_attribute_set.js
│ ├── test_attribute_setget.js
│ ├── test_attribute_setup.js
│ ├── test_attribute_validate.js
│ ├── test_meta.js
│ ├── test_model.js
│ ├── test_thing_find.js
│ ├── test_thing_model_code.js
│ ├── test_thing_set.js
│ ├── test_thing_setup.js
│ └── test_thing_validate.js
├── thing_manager.js
├── thing_set.js
├── users.js
└── windows.js
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "curly": true,
3 | "eqeqeq": true,
4 | "immed": true,
5 | "latedef": "nofunc",
6 | "newcap": false,
7 | "noarg": true,
8 | "sub": true,
9 | "undef": true,
10 | "unused": "var",
11 | "boss": true,
12 | "eqnull": true,
13 | "node": true,
14 | "-W086": true
15 | }
16 |
--------------------------------------------------------------------------------
/DIST.sh:
--------------------------------------------------------------------------------
1 | #
2 | # DIST.sh
3 | #
4 | # David Janes
5 | # IOTDB
6 | # 2014-04-18
7 | #
8 | # Distribute iotdb to NPM
9 | #
10 |
11 | DO_NPM_IOTDB_PACKAGE=true
12 | DIST_ROOT=/var/tmp/node-iotdb.dist.$$
13 | IOTDB_ROOT=$HOME/iotdb
14 |
15 | if [ ! -d "$DIST_ROOT" ]
16 | then
17 | mkdir "$DIST_ROOT"
18 | fi
19 |
20 | if $DO_NPM_IOTDB_PACKAGE
21 | then
22 | echo "=================="
23 | echo "NPM Packge: iotdb"
24 | echo "=================="
25 | (
26 | NPM_IOTDB_SRC=../node-iotdb
27 | cd $NPM_IOTDB_SRC || exit 1
28 |
29 | NPM_IOTDB_DST=$DIST_ROOT/iotdb
30 | echo "NPM_IOTDB_DST=$NPM_IOTDB_DST"
31 |
32 | if [ -d ${NPM_IOTDB_DST} ]
33 | then
34 | rm -rf "${NPM_IOTDB_DST}"
35 | fi
36 | mkdir "${NPM_IOTDB_DST}" || exit 1
37 |
38 | update-package --increment-version || exit 1
39 |
40 | tar cf - \
41 | --exclude "xx*" \
42 | --exclude "yy*" \
43 | README.md \
44 | LICENSE.txt \
45 | *.js *.json helpers/*js \
46 | |
47 | ( cd "${NPM_IOTDB_DST}" && tar xvf - && npm publish ) || exit 1
48 | git commit -m "new release" package.json || exit 1
49 | git push || exit 1
50 |
51 | echo "end"
52 | )
53 | fi
54 |
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = function (grunt) {
4 | // Show elapsed time at the end
5 | // require('time-grunt')(grunt);
6 | // Load all grunt tasks
7 | require('load-grunt-tasks')(grunt);
8 |
9 | // Project configuration.
10 | grunt.initConfig({
11 | nodeunit: {
12 | files: []
13 | },
14 | jshint: {
15 | options: {
16 | jshintrc: '.jshintrc',
17 | reporter: require('jshint-stylish')
18 | },
19 | gruntfile: {
20 | src: 'Gruntfile.js'
21 | },
22 | lib: {
23 | src: [
24 | '*.js',
25 | 'helpers/*.js'
26 | ]
27 | },
28 | test: {
29 | src: []
30 | }
31 | },
32 | watch: {
33 | gruntfile: {
34 | files: '<%= jshint.gruntfile.src %>',
35 | tasks: ['jshint:gruntfile']
36 | },
37 | lib: {
38 | files: '<%= jshint.lib.src %>',
39 | tasks: ['jshint:lib']
40 | },
41 | test: {
42 | files: '<%= jshint.test.src %>',
43 | tasks: ['jshint:test']
44 | }
45 | },
46 | jsbeautifier: {
47 | files: [
48 | '*.js',
49 | 'helpers/*.js'
50 | ],
51 | options: {
52 | js: {
53 | jslint_happy: true,
54 | indentChar: ' ',
55 | indentSize: 4
56 | }
57 | },
58 | }
59 | });
60 |
61 | // Default task.
62 | grunt.registerTask('default', ['jsbeautifier', 'jshint']);
63 |
64 | };
65 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # node-iotdb
2 |
3 |
4 |
5 | A Node.JS platform for semantically control all your Things.
6 | 100% test coverage.
7 |
8 | **Node.JS 6 or higher is required!**
9 |
10 | # Hello, World
11 |
12 | ## Install IOTDB
13 |
14 | $ npm install iotdb
15 |
16 | ## Turn WeMo on or off
17 |
18 | const iotdb = require("iotdb");
19 | iotdb.use("homestar-wemo");
20 |
21 | things = iotdb.connect("WeMoSocket");
22 | things.set(":on", true)
23 | things.set(":on", false)
24 |
25 | N.B.
26 | * you must have installed the NPM package homestar-wemo
27 | * :on
is the "semantic" term that universally means "turn/is something on or off". It expands to iot-purpose:on
which in turn expands to the URL https://iotdb.org/pub/iot-purpose#on
.
28 |
29 | ## Wait for a WeMo to change state
30 |
31 | const iotdb = require("iotdb");
32 | iotdb.use("homestar-wemo");
33 |
34 | things = iotdb.connect("WeMoSocket");
35 | things.on("istate", thing => {
36 | console.log("istate", thing.state("istate"));
37 | console.log("on", thing.get(":on"));
38 | })
39 |
40 | N.B.
41 | * istate
is the actual current state of the Thing. In IOTDB a Thing may have many states associated with it, called bands.
42 |
43 | # Documentation
44 |
45 | We are in the process of collecting all the documents into this project.
46 |
47 | Start here:
48 | * [https://github.com/dpjanes/node-iotdb/tree/master/docs](https://github.com/dpjanes/node-iotdb/tree/master/docs)
49 |
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | # IOTDB Docs
2 |
3 | These are somewhat disjointed.
4 | Our apologies.
5 | If there's some section you'd like to see convered in more depth,
6 | or just have a question, please
7 | [send me a note](mailto:davidjanes@iotdb.org).
8 |
9 | # Sections
10 |
11 | These are in alphabetical order.
12 |
13 | * [Architecture](architecture.md)
14 | * [Atomic Theory](atomic-theory.md)
15 | * [Bands](bands.md)
16 | * [Briges](bridges.md)
17 | * [Core Ideas](core.md)
18 | * [FAQ](faq.md)
19 | * [HomeStar](homestar.md)
20 | * [Installation](install.md)
21 | * [Modules](modules.md)
22 | * [Semantics](semantics.md)
23 | * [Thing](thing.md)
24 | * [Transporters](transporters.md)
25 |
--------------------------------------------------------------------------------
/docs/architecture.md:
--------------------------------------------------------------------------------
1 | # Architecture
2 |
3 | Here's the architecture of a typical IOTDB program:
4 |
5 | +----------------+
6 | | Your Code |
7 | +----------------+
8 | | ThingSet | node-iotdb/thing_set.js
9 | +----------------+
10 | | Thing | iotdb-thing/thing.s
11 | +----------------+
12 | | ThingManager | node-iotdb/thing_manager.js
13 | +----------------+
14 | | Bridge | homestar-*/*Bridge.js
15 | +----------------+
16 | | Native Code |
17 | +----------------+
18 |
19 | ## Your Code
20 |
21 | const iotdb = require("iotdb")
22 | iotdb.use("homestar-wemo")
23 |
24 | const things = iotdb.connect("WeMoSocket")
25 | things.set(":on", true);
26 |
27 | ## ThingSet
28 |
29 | A ThingSet manages many Things at once.
30 | The 'clever' bit about ThingSet is that it *defers* commands.
31 | For example, when you do
32 |
33 | thing.set(":on", true)
34 |
35 | It's almost certain **that the WeMo Socket has not been discovered yet**.
36 | The ThingSet will issue the command once the Thing has been discovered.
37 |
38 | ThingSets can chain creation and can filter for specific results.
39 |
40 | iotdb
41 | .connect("WeMoSocket")
42 | .connect("WeMoInsight")
43 | .with_zone("David's Living Room")
44 |
45 | See the [source code here](https://github.com/dpjanes/node-iotdb/blob/master/thing_set.js)
46 | for more operations.
47 |
48 | ## Thing
49 |
50 | ## ThingManager
51 |
52 | ## Bridge
53 |
54 | ## Native Code
55 |
--------------------------------------------------------------------------------
/docs/bands.md:
--------------------------------------------------------------------------------
1 | # Bands
2 |
3 | In IOTDB, a Thing is a collection of **bands**, which are simply JSON-like dictionaries.
4 |
5 | # Bands
6 | ## `model`
7 |
8 | This is a semantic model written in JSON-LD, describing the values in `ostate` and `istate`.
9 | You can see an example of a Model in JSON-LD [here for a WeMo Switch](https://github.com/dpjanes/homestar-wemo/blob/master/models/we-mo-socket.json).
10 |
11 | Models are typically written in IoTQL.
12 | [Here' the IoTQL Model for the WeMo Switch](https://github.com/dpjanes/homestar-wemo/blob/master/models/WeMoSocket.iotql).
13 | You'll note this is much more compact.
14 |
15 | ## `meta`
16 |
17 | {
18 | "@context": "https://iotdb.org/pub/iot",
19 | "iot:facet": [
20 | "iot-facet:plug",
21 | "iot-facet:switch"
22 | ],
23 | "iot:model-id": "we-mo-socket",
24 | "iot:thing-id": "urn:iotdb:t:sArvozfc:092qoWwd",
25 | "iot:vendor.model": "Socket",
26 | "iot:vendor.type": "urn:Belkin:device:controllee:1",
27 | "schema:description": "Belkin WeMo Socket",
28 | "schema:manufacturer": "http://www.belkin.com/",
29 | "schema:name": "WeMo Socket"
30 | }
31 |
32 | ## `istate`
33 |
34 | The `istate` for a WeMo Socket looks like this:
35 |
36 | {
37 | "on": true
38 | }
39 |
40 | Indicating the device is on.
41 | If you look at the Model above, you'll see see an `iot:atttribute` that describes this.
42 |
43 | ## `ostate`
44 |
45 | The `ostate` for a WeMo Switch looks like this:
46 |
47 | {
48 | "on": null
49 | }
50 |
51 | Indicating there is no command currently being executed.
52 | If you want to turn of the socket, write this to the band:
53 |
54 | {
55 | "on": false
56 | }
57 |
58 | Once the socket has changed state, it will revert.
59 |
60 | ## `connection`
61 |
62 | ## `transient`
63 |
64 | # See Also
65 |
66 | * [Interoperability with Standardless IoT](http://www.slideshare.net/dpjanes/2015-04-global-io-t-day-wien-interoperability-with-stanardless-iot)
67 | * [What a Thing API Should Look Like](http://www.slideshare.net/dpjanes/what-a-thing-api-should-look-like-global-iot-day)
68 |
--------------------------------------------------------------------------------
/docs/core.md:
--------------------------------------------------------------------------------
1 | # Core Ideas
2 |
3 | The "core ideas" of IOTDB are:
4 |
5 | * we describe Things by semantically annotating the _data associated with the Thing_
6 | * Things have many different _bands_ of data associated with them, e.g. the metadata, the actual state, etc.
7 | * our description is built from _atomic_ elements, ones that cannot be meaningfully subdivided further.
8 | * our descriptions are built be _composition_ of those atomic elements,
9 | * our descriptions are _extensible / open ended_, meaning we can freely add in elements from other Semantic ontologies, such as SAREF or [Project Haystack](http://project-haystack.org/)
10 | * Things _are what they say they are_, something is a Switch if it says its a switch; it is up to the client to manipulate the switch based on information exposed in the data model
11 | * Things _do what they say they do_, something can be turned on or off if they present an attribute of `iot:purpose` `iot-purpose:on`
12 | * where possible, we should be _descriptive_ not _prescriptive_, i.e. describing what people _are_ doing, not how they _should_ do
13 | * descriptions should be _true_, e.g. oneIoTa models [brightness](http://oneiota.org/revisions/1746) as a value between 0 and 100. This inaccurately models a light that can be on, off or half-brightness only
14 | * _semantic specifications_ should be written using W3C semantic tools, specifically _Linked Data_, e.g. the definition of temperature in Celsius should be a Hyperlink, not "C" or "celsius" or "org.something.temperatureunit.celsius" or some other magic word (e.g. like [IPSO](https://github.com/IPSO-Alliance/pub))
15 |
16 |
--------------------------------------------------------------------------------
/docs/faq.md:
--------------------------------------------------------------------------------
1 | # Models
2 | ## How to get all the attributes of a thing?
3 |
4 | thing.attributes()
5 |
6 | ## How to get all the attribute keys?
7 |
8 | thing.attributes().map(_.id.code.from.attribute)
9 |
10 | # Bands
11 | ## How to get an event for when a thing becomes unreachable?
12 |
13 | For one Thing:
14 |
15 | thing
16 | .band("connection")
17 | .on("iot:reachable", (thing, band, is_reachable) => {
18 | console.log("+", "thing", thing.thing_id(), "reachable", thing.reachable());
19 | })
20 |
21 | For many Things - note that this may be triggered on other events,
22 | because it's granular on any change to `connection`
23 |
24 | things
25 | .on("connection", (thing, band, is_reachable) => {
26 | console.log("+", "thing", thing.thing_id(), "reachable", thing.reachable());
27 | })
28 |
--------------------------------------------------------------------------------
/docs/homestar.md:
--------------------------------------------------------------------------------
1 | # Home☆Star
2 |
3 | Home☆Star is three things:
4 |
5 | * it's the command line management utilities for [IOTDB](https://github.com/dpjanes/node-iotdb)
6 | * it makes a web interface / API to your Things (if you want it)
7 | * it's a naming convention for all IOTDB Bridges, e.g. `homestae-hue`
8 |
9 | # Installation
10 |
11 | Make sure to review the normal [install](./install.md) docs
12 |
13 | This gives you some CLI tools for managing your installation,
14 | and allows certain [Bridges](./bridges.md) to automatically `use`d.
15 |
16 | $ npm install -g homestar ## may require sudo
17 | $ homestar setup
18 |
19 | This will create the following:
20 |
21 | * `boot/index.js` - sample code
22 | * `.iotdb/keystore.json` - settings
23 |
24 | It will also install `iotdb` and some other useful modules.
25 | If you install using HomeStar:
26 |
27 | $ homestar install homestar-wemo
28 |
29 | Then you don't need to do `use()`:
30 |
31 | const iotdb = require("iotdb")
32 |
33 | const things = iotdb.connect("WeMoSocket")
34 | things.set(":on", true);
35 |
36 | It does this by adding the following configuration
37 | to `.iotdb/keystore.json`:
38 |
39 | {
40 | "modules": {
41 | "homestar-wemo": "/Users/davidjanes/iotdb/iot/homestar-wemo"
42 | }
43 | }
44 |
45 | # Use
46 | ## Web Interface
47 |
48 | To run the web interface
49 |
50 | $ homestar runner
51 |
52 | You'll want to edit the file `boot/index.js` to add your Things.
53 | If you haven't installed any Things yet, see [Bridges](https://github.com/dpjanes/node-iotdb/blob/master/docs/bridges.md).
54 |
55 | ## Setup
56 |
57 | This only needs to be run once.
58 |
59 | $ homestar setup
60 |
61 | It will:
62 |
63 | * set up the `./boot` folder, so you can define whatever Things you want to be loaded into `homestar runner`
64 | * set up the `./.iotdb` folder, for local configuration
65 | * install in `./node_modules` all IOTDB modules needed
66 |
67 | ## Update
68 |
69 | This will pull new version of HomeStar and IOTDB modules in `./node_modules`.
70 |
71 | $ homestar update
72 |
73 | ## Configuration
74 |
75 | Some Bridges (code that talks to Things) require configuration, e.g. to do pairing,
76 | adding API keys, etc.. If this is so, it will be mentioned in the README for the Bridge module.
77 |
78 | e.g. here's how you do it
79 |
80 | $ homestar configure homestar-hue
81 |
82 | ## Settings
83 |
84 | This will modify values in `./.iotdb/keystore.json`, the local configuration.
85 |
86 | e.g.
87 |
88 | homestar set browser 0 ## don't open the browser
89 | homestar set name "name for this system"
90 |
--------------------------------------------------------------------------------
/docs/install.md:
--------------------------------------------------------------------------------
1 | # Installation
2 |
3 | ## Easy Way
4 |
5 | Do:
6 |
7 | $ npm install iotdb
8 | $ npm install homestar-wemo
9 |
10 | Then:
11 |
12 | const iotdb = require("iotdb")
13 | iotdb.use("homestar-wemo")
14 |
15 | const things = iotdb.connect("WeMoSocket")
16 | things.set(":on", true);
17 |
18 | ## HomeStar Way
19 |
20 | Optional. This gives you some CLI tools for managing your installation,
21 | and allows certain [Bridges](./bridges.md) to automatically `use`d.
22 |
23 | See the [documentation here](./homestar.md).
24 |
--------------------------------------------------------------------------------
/docs/modules.md:
--------------------------------------------------------------------------------
1 | # Modules
2 |
3 | Modules are our term for [NPM Packages](https://www.npmjs.com/)
4 | designed to extend IOTDB (or HomeStar) functionality.
5 | The most important of these are [Bridges](bridges.md).
6 |
7 | # Other Modules
8 |
9 | * [homestar-aws](https://github.com/dpjanes/homestar-aws) - send data to and from AWS IoT
10 | * [iotdb-commands](https://github.com/dpjanes/iotdb-commands) - convert human commands into thing actions
11 |
12 |
--------------------------------------------------------------------------------
/docs/semantics.md:
--------------------------------------------------------------------------------
1 | # IOTDB
2 |
3 | IOTDB is an Open Source project, started in 2013, to describe the Things in the Internet of Things using semantics. It is explicitly built on top of Schema.org and JSON-LD.
4 |
5 | The "core ideas" of IOTDB are:
6 |
7 | * we describe Things by semantically annotating the data associated with the Thing
8 | * Things have many different bands of data associated with them, e.g. the metadata, the actual state, etc.
9 | * our description is built from atomic elements, ones that cannot be meaningfully subdivided further.
10 | * our descriptions are built be composition of those atomic elements,
11 | * our descriptions are extensible / open ended, meaning we can freely add in elements from other Semantic ontologies, such as SAREF or Project Haystack
12 | * Things are what they say they are, something is a Switch if it says its a switch; it is up to the client to manipulate the switch based on information exposed in the data model
13 | * Things do what they say they do, something can be turned on or off if they present an attribute of iot:purpose iot-purpose:on
14 | * where possible, we should be descriptive not prescriptive, i.e. describing what people are doing, not how they should do
15 | * descriptions should be true, e.g. oneIoTa models brightness as a value between 0 and 100. This inaccurately models a light that can be on, off or half-brightness only
16 | * semantic specifications should be written using W3C semantic tools, specifically Linked Data, e.g. the definition of temperature in Celsius should be a Hyperlink, not "C" or "celsius" or "org.something.temperatureunit.celsius" or some other magic word (e.g. like IPSO)
17 |
18 | IOTDB's belief is that if a semantic spec is written correctly, it should be possible to write other specs (e.g. oneIoTa, Iotivity, Bluetooth profiles, &c) using the terms of this spec; it will act as a Rosetta Stone between different IoT worlds.
19 | For example, consider FIWARE's data for Observed Weather. IOTDB takes the approach that we use the data as-is, and create a "model" that describes it JSON-LD
20 |
21 | {
22 | "temperature": 9.2,
23 | "source": "http://www.aemet.es",
24 | "windDirection": "Este",
25 | "address": {
26 | "addressLocality": "Valladolid",
27 | "addressCountry": "ES"
28 | },
29 | "dateObserved": "2016-03-14T16:00:00",
30 | "pressure": 930,
31 | "windSpeed": 7,
32 | "type": "WeatherObserved",
33 | "relativeHumidity": 0.47,
34 | "precipitation": 0,
35 | "pressureTendency": -1.3
36 | }
37 |
38 | IOTDB would describe the temperature and humidity something like (pseudocode ahead):
39 |
40 | @id #temperature
41 | schema:name "temperature"
42 | schema:description: "observed temperature"
43 | iot:purpose iot-purpose:temperature
44 | iot:type iot:type.number
45 | iot:unit iot-unit:temperature.si.celsius
46 | iot:sensor true
47 | iot:actuator false
48 |
49 | @id #humidity
50 | schema:name "humidity"
51 | schema:description: "observed humidity"
52 | iot:purpose iot-purpose:humidity
53 | iot:type iot:type.number
54 | iot:unit iot-unit:math.fraction.unit
55 | iot:minimum 0
56 | iot:maximum 1
57 | iot:sensor true
58 | iot:actuator false
59 |
60 | IOTDB's models would also allow the windDirection of Este to be mapped to 90 degrees or some other more appropriate universal semantic terminology. Because we have a semantic vocabulary, we can easily do things like "give me the temperature in Fahrenheit" even though it's measured in Celsius; or "turn the light to 60% brightness" even though the underlying device works from 0 to 1.
61 |
62 | IOTDB has four semantic vocabularies:
63 |
64 | * iot: - core vocabulary
65 | * iot-purpose: - the "purpose" of the data of thing, e.g. measuring temperature, changing the channel, and so forth. This vocabulary was developed interoperating with actual Things (links below)
66 | * iot-facet: - what things do, e.g. are they switches, are they part of the HVAC system, and so forth
67 | * iot-unit: - units of measure, but things like QUDT are probably better if in the SI world
68 |
69 | Of particular interest to Schema.org is the iot-purpose: vocabulary, which describes what is being sensed or actuated. For example:
70 |
71 | * iot-purpose:color - as an actuator, set the color (e.g. like a Philips Hue); as a sensor, what the color actually is
72 | * iot-purpose:frequency - sensed / actuate frequency
73 | * iot-purpose:on - is the device on or off; turn it on (or off)
74 | * iot-purpose:open - is the door, or shutter, or whatever open or close; open or close it
75 | * iot-purpose:volume - the current volume, change the volume
76 |
77 |
--------------------------------------------------------------------------------
/docs/thing.md:
--------------------------------------------------------------------------------
1 | # Thing
2 |
3 | The Module [iotdb-thing](https://github.com/dpjanes/iotdb-thing) is
4 | the API for implementing a Thing.
5 | It is based around the concept of [bands](bands.md) and
6 | understands how to _semantically_ manipulate the `istate` and `ostate`
7 | bands using the Thing's Model in the `model` band.
8 |
9 | # Creation
10 |
11 | For the most part, Thing objects will be created for you and you just
12 | manipulate them as per below.
13 |
14 | ## IOTDB
15 |
16 | In this example, `things` will be populated with the various
17 | WeMo things as they are found.
18 |
19 | const iotdb = require("iotdb")
20 | iotdb.use("homestar-wemo")
21 |
22 | iotdb.connect("WeMoSocket")
23 | iotdb.connect("WeMoInsight")
24 |
25 | const things = iotdb.things()
26 |
27 |
28 | ## Standalone
29 |
30 | You can just create Thing objects from band data:
31 |
32 | const thing_maker = require("iotdb-thing").thing;
33 | const thing_1 = thing_maker.make()
34 | const thing_2 = thing_maker.make({
35 | "model": …,
36 | "meta": …,
37 | "istate": …,
38 | "ostate": …,
39 | "connection": …,
40 | });
41 |
42 | # Working with Data
43 |
44 | ## Bands
45 |
46 | ### ostate
47 |
48 | The **ostate** is used to manipulate a thing - it's the **output state**.
49 |
50 | get the ostate
51 |
52 | const ostate_1 = thing_1.band("ostate");
53 |
54 | see the current values
55 |
56 | const d = ostate_1.state();
57 |
58 | set a value semantically
59 |
60 | const promise = ostate_1.set(":on", true);
61 |
62 | set a value non-semantically
63 |
64 | const promise = ostate_1.set("power", true);
65 |
66 | change a whole bunch of values (non-semantic). Note that
67 | `update` is always non-semantic, it's dealing the raw underlying data.
68 |
69 | const promise = ostate_1.update({
70 | "power": true,
71 | "level": 50,
72 | })
73 |
74 | ### istate
75 |
76 | The **istate** is used to current the current readings from a thing - it's the **input state**.
77 |
78 | Get the istate object
79 |
80 | const istate_1 = thing_1.band("istate");
81 |
82 | See the current values
83 |
84 | const d = istate_1.state();
85 |
86 | Get a particular value semantically. `first` and `list`
87 | guarentee a non-array or an array respectively, `get`
88 | just returns what is there
89 |
90 | const is_on_get = istate_1.get(":on")
91 | const is_on_first = istate_1.first(":on")
92 | const is_on_list = istate_1.list(":on")
93 |
94 | Get a particular value non-semantically
95 |
96 | const is_on_get = istate_1.get("powered")
97 | const is_on_first = istate_1.first("powered")
98 | const is_on_list = istate_1.list("powered")
99 |
100 | Listen for a change semantically
101 |
102 | istate_1.on(":on", function(_thing, _band, _new_value) {
103 | });
104 |
105 | Listen for a change non-semantically
106 |
107 | istate_1.on("powered", function(_thing, _band, _new_value) {
108 | });
109 |
110 | ## Paramaterized Data
111 |
112 | Because we have a strong idea of data types, you can parameterize
113 | values being passed into things; and you can coerce output values.
114 |
115 | ### Helper functions parametization
116 |
117 | ostate_1.set("level", 50, iotdb.as.percent());
118 | ostate_1.set("level", .5, iotdb.as.unit());
119 | ostate_1.set("temperature", 22, iotdb.as.celsius());
120 |
121 | ### Coercing output value
122 |
123 | istate_1.get("temperature", iotdb.as.celsius());
124 |
125 | ### Getting type definitions
126 |
127 | This will return a semantic description describing this
128 | particular **attribute** of the Thing.
129 |
130 | thing_1.attribute("temperature")
131 |
132 | or with a coercion
133 |
134 | thing_1.attribute("temperature", iotdb.as.celsius());
135 |
136 |
--------------------------------------------------------------------------------
/exit.js:
--------------------------------------------------------------------------------
1 | /*
2 | * iotdb.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2013-12-01
7 | *
8 | * NodeJS IOTDB control
9 | *
10 | * This is also the 'main' for the package
11 | *
12 | * Copyright [2013-2016] [David P. Janes]
13 | *
14 | * Licensed under the Apache License, Version 2.0 (the "License");
15 | * you may not use this file except in compliance with the License.
16 | * You may obtain a copy of the License at
17 | *
18 | * http://www.apache.org/licenses/LICENSE-2.0
19 | *
20 | * Unless required by applicable law or agreed to in writing, software
21 | * distributed under the License is distributed on an "AS IS" BASIS,
22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 | * See the License for the specific language governing permissions and
24 | * limitations under the License.
25 | */
26 |
27 | "use strict";
28 |
29 | const _ = require("iotdb-helpers");
30 |
31 | const events = require('events');
32 | const util = require('util');
33 | const path = require('path');
34 | const fs = require('fs');
35 |
36 | const logger = _.logger.make({
37 | name: 'iotdb',
38 | module: 'exit',
39 | });
40 |
41 | let _shutting_down = false;
42 | let _process = process;
43 |
44 | const setup = manager => {
45 | const _shutdown = () => {
46 | _shutting_down = true;
47 |
48 | const time_wait = manager.disconnect();
49 |
50 | if (time_wait === 0) {
51 | console.log("### calling _process.exit(0) - good-bye!");
52 | _process.exit(0);
53 | } else {
54 | logger.info({
55 | method: "_exit_cleanup",
56 | exiting_in: time_wait / 1000.0
57 | }, "delaying exit");
58 |
59 | setTimeout(() => _process.exit(0), time_wait);
60 | }
61 | };
62 |
63 | _process.on('SIGINT', _shutdown);
64 | };
65 |
66 | /**
67 | * API
68 | */
69 | exports.setup = setup;
70 | exports.shutting_down = function () {
71 | return _shutting_down;
72 | };
73 |
74 | exports.shims = {
75 | setProcess: f => {
76 | _process = f;
77 | _shutting_down = false;
78 | },
79 | getProcess: () => _process,
80 | setShuttingDown: v => _shutting_down = v,
81 | }
82 |
--------------------------------------------------------------------------------
/helpers.js:
--------------------------------------------------------------------------------
1 | /*
2 | * helpers.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2013-12-01
7 | *
8 | * Nodejs IOTDB control
9 | *
10 | * Copyright [2013-2016] [David P. Janes]
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 | "use strict";
26 |
27 | const _ = require("iotdb-helpers");
28 |
29 | const local_modules = [
30 | require('./helpers/is'),
31 | require('./helpers/version'),
32 | require('./helpers/bridge'),
33 | require('./helpers/id'),
34 | ];
35 | local_modules.map(local_module => {
36 | _.mapObject(local_module, (local_value, local_name) => {
37 | _[local_name] = _.d.compose.shallow(local_value, _[local_name]);
38 | });
39 | });
40 |
41 | module.exports = _;
42 |
--------------------------------------------------------------------------------
/helpers/bridge.js:
--------------------------------------------------------------------------------
1 | /*
2 | * bridge.js
3 | *
4 | * David Janes
5 | * IOT.org
6 | * 2015-01-31
7 | *
8 | * Copyright [2013-2016] [David P. Janes]
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | "use strict";
24 |
25 | const _ = require('iotdb-helpers');
26 |
27 | const events = require('events');
28 | const util = require('util');
29 |
30 | const logger = _.logger.make({
31 | name: 'iotdb',
32 | module: 'helpers/bridge',
33 | });
34 |
35 | /**
36 | * A Bridge wrapper does all the work IOTDB would
37 | * do so you can use the Bridge without bringing
38 | * in the rest of IOTDB.
39 | *
40 | * In practice, it's much easier to use IOTDB
41 | * but sometimes this is helpful, especially if
42 | * you just want to use the moduels stand-alone
43 | */
44 | const make = (binding, initd) => {
45 | const self = Object.assign({}, events.EventEmitter.prototype);
46 | const thing_manager = require("../thing_manager");
47 |
48 | const bridge_exemplar = new binding.bridge(_.defaults(initd, binding.initd, {}));
49 |
50 | bridge_exemplar.discovered = (bridge_instance) => {
51 | if (binding.matchd && !_.d.is.superset(bridge_instance.meta(), binding.matchd)) {
52 | self.emit("ignored", bridge_instance);
53 | return;
54 | }
55 |
56 | // to bring along data stored here - horrible side effect, revisit
57 | bridge_instance.binding = binding;
58 |
59 | const thing = thing_manager.make_thing({
60 | model: binding.model,
61 | meta: bridge_instance.meta(),
62 | });
63 | thing_manager.bind_thing_to_bridge(thing, bridge_instance, binding);
64 |
65 | self.emit("thing", thing);
66 |
67 | // deal with pulls
68 | const model_pulled = bridge_instance.pulled;
69 | bridge_instance.pulled = function (pulld) {
70 | model_pulled(pulld);
71 |
72 | if (pulld) {
73 | self.emit("istate", bridge_instance, pulld);
74 | } else if (bridge_instance.reachable()) {
75 | self.emit("meta", bridge_instance);
76 | } else {
77 | self.emit("meta", bridge_instance);
78 | self.emit("disconnected", bridge_instance);
79 | }
80 | };
81 |
82 | // connect and announce
83 | bridge_instance.connect(_.defaults(binding.connectd, {}));
84 |
85 | self.emit("bridge", bridge_instance);
86 | };
87 |
88 | process.nextTick(() => bridge_exemplar.discover());
89 |
90 | return self;
91 | };
92 |
93 | /**
94 | * Finds a Model by model_id in a list of bindings, then wraps it
95 | */
96 | const wrap = (model_id, bindings, initd) => bindings
97 | .filter(binding => binding.model)
98 | .filter(binding => binding.bridge)
99 | .filter(binding => _.ld.first(binding.model, "iot:model-id") === _.id.to_dash_case(model_id))
100 | .map(binding => make(binding, initd))
101 | .find(wrapper => true);
102 |
103 | /**
104 | * API
105 | */
106 | exports.bridge = {
107 | make: make,
108 | wrap: wrap,
109 | };
110 |
--------------------------------------------------------------------------------
/helpers/id.js:
--------------------------------------------------------------------------------
1 | /*
2 | * id.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2014-02-03
7 | *
8 | * Things related to identifiers
9 | *
10 | * Copyright [2013-2016] [David P. Janes]
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 | "use strict";
26 |
27 | const crypto = require('crypto');
28 |
29 | const _safe = function (component) {
30 | return encodeURIComponent(component).replace('%', '$');
31 | };
32 |
33 | /**
34 | */
35 | const machine_id = () => {
36 | const iotdb = require("../iotdb");
37 | const settings = iotdb.settings();
38 | // return settings.get("/homestar/runner/keys/homestar/key", settings.get("/machine_id", ""));
39 | return settings.get("/machine_id", "");
40 | }
41 |
42 | /**
43 | * Unique thing
44 | */
45 | const _thing_urn_unique = function () {
46 | const parts = ["urn", "iotdb", "thing"];
47 | for (let ai in arguments) {
48 | parts.push(_safe(arguments[ai]));
49 | }
50 |
51 | return parts.join(":");
52 | };
53 |
54 | /**
55 | * Unique thing, but hashing required of last com
56 | */
57 | const _thing_urn_unique_hash = function () {
58 | const parts = ["urn", "iotdb", "thing"];
59 | for (let ai = 0; ai < arguments.length - 1; ai++) {
60 | parts.push(_safe(arguments[ai]));
61 | }
62 |
63 | const hasher = crypto.createHash('md5');
64 | if (arguments.length) {
65 | hasher.update("" + arguments[arguments.length - 1]);
66 | }
67 | parts.push(hasher.digest("hex"));
68 |
69 | return parts.join(":");
70 | };
71 |
72 | /**
73 | * Unique on this machine
74 | */
75 | const _thing_urn_machine = function () {
76 | const hasher = crypto.createHash('md5');
77 | hasher.update(machine_id());
78 |
79 | const parts = ["urn", "iotdb", "thing"];
80 | for (let ai in arguments) {
81 | parts.push(_safe(arguments[ai]));
82 | hasher.update("" + arguments[ai]);
83 | }
84 |
85 | parts.push(hasher.digest("hex"));
86 |
87 | return parts.join(":");
88 | };
89 |
90 | exports.id = {
91 | machine_id: machine_id,
92 | thing_urn: {
93 | unique: _thing_urn_unique,
94 | unique_hash: _thing_urn_unique_hash,
95 | machine_unique: _thing_urn_machine,
96 | },
97 | };
98 |
--------------------------------------------------------------------------------
/helpers/is.js:
--------------------------------------------------------------------------------
1 | /*
2 | * is.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2014-04-15
7 | *
8 | * Test types
9 | *
10 | * Copyright [2013-2016] [David P. Janes]
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 | "use strict";
26 |
27 | const _ = require("iotdb-helpers");
28 |
29 | exports.is = {
30 | Thing: (o) => o && o._isThing,
31 | ThingSet: (o) => o && o._isThingSet,
32 | ThingArray: (o) => o && o._isThingSet,
33 | Transport: (o) => o && o._isTransport,
34 | Transporter: (o) => o && o._isTransport,
35 | Bridge: (o) => o && o._isBridge,
36 | FindKey: (o) => _.is.String(o) || _.is.Dictionary(o),
37 | };
38 |
--------------------------------------------------------------------------------
/helpers/version.js:
--------------------------------------------------------------------------------
1 | /*
2 | * version.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2016-02-13
7 | *
8 | * Copyright [2013-2016] [David P. Janes]
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | "use strict";
24 |
25 | const semver = require('semver');
26 | const _ = require("iotdb-helpers");
27 |
28 | let _version = process.versions.node;
29 |
30 | const _die = function (error, paramd) {
31 | if (!error) {
32 | return;
33 | }
34 |
35 | console.log("#######################");
36 | console.log("## " + _.error.message(error));
37 | console.log("## ");
38 | console.log("## Expected Version: " + paramd.satisfies);
39 | console.log("## Got Version: " + paramd.version);
40 | console.log("## Cause: " + paramd.cause);
41 | console.log("## ");
42 | console.log("#######################");
43 |
44 | throw error;
45 | };
46 |
47 | const _check = function (paramd, done) {
48 | if (!semver.satisfies(paramd.version, paramd.satisfies)) {
49 | return done(new Error("Version not satisfied: need " + paramd.satisfies + " got: " + paramd.version), paramd);
50 | }
51 |
52 | return done(null, paramd);
53 | };
54 |
55 | const check_node = function (done) {
56 | _check({
57 | message: "Bad Node.JS Version",
58 | version: _version,
59 | satisfies: ">=6.0.0",
60 | cause: "Older Node.JS installed. Upgrade your version of Node.JS to something more modern",
61 | }, done || _die);
62 | };
63 |
64 | exports.version = {
65 | check: {
66 | node: check_node,
67 | },
68 | };
69 | exports.shims = {
70 | version: v => {
71 | if (v) {
72 | _version = v;
73 | } else {
74 | _version = process.versions.node;
75 | }
76 | },
77 | };
78 |
--------------------------------------------------------------------------------
/iotdb.js:
--------------------------------------------------------------------------------
1 | /*
2 | * iotdb.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2013-12-01
7 | *
8 | * NodeJS IOTDB control
9 | *
10 | * This is also the 'main' for the package
11 | *
12 | * Copyright [2013-2016] [David P. Janes]
13 | *
14 | * Licensed under the Apache License, Version 2.0 (the "License");
15 | * you may not use this file except in compliance with the License.
16 | * You may obtain a copy of the License at
17 | *
18 | * http://www.apache.org/licenses/LICENSE-2.0
19 | *
20 | * Unless required by applicable law or agreed to in writing, software
21 | * distributed under the License is distributed on an "AS IS" BASIS,
22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 | * See the License for the specific language governing permissions and
24 | * limitations under the License.
25 | */
26 |
27 | "use strict";
28 |
29 | const iotdb_thing = require("iotdb-thing");
30 | const thing_manager = require('./thing_manager');
31 | const exit = require('./exit');
32 | const _ = require('./helpers');
33 |
34 | /**
35 | * Singleton
36 | */
37 | let _instance;
38 |
39 | const iot = () => {
40 | if (!_instance) {
41 | _instance = thing_manager.make();
42 | exit.setup(_instance);
43 | }
44 |
45 | return _instance;
46 | };
47 |
48 | const connect = (model, initd, metad) => {
49 | return iot().connect(model, initd, metad);
50 | }
51 |
52 | const things = () => {
53 | return iot().things();
54 | }
55 |
56 | /*
57 | * API
58 | */
59 | exports.shutting_down = exit.shutting_down;
60 |
61 | exports._ = _;
62 | exports.logger = _.logger.logger;
63 |
64 | const bridge = require('./bridge');
65 | exports.Bridge = bridge.Bridge;
66 |
67 | const settings = require('./settings');
68 | exports.settings = settings.instance;
69 | exports.Settings = settings.Settings;
70 | exports.keystore = () => exports.settings();
71 |
72 | const modules = require('./modules');
73 | exports.modules = modules.instance;
74 | exports.use = (module_name, module) => exports.modules().use(module_name, module);
75 |
76 | const runner_timestamp = _.timestamp.make();
77 | exports.controller_meta = () => {
78 | return {
79 | "iot:runner.timestamp": runner_timestamp,
80 | "iot:runner.id": _.id.machine_id(),
81 | }
82 | };
83 |
84 | // users
85 | exports.users = require('./users');
86 |
87 | // primary API
88 | exports.iot = iot;
89 | exports.connect = connect;
90 | exports.things = things;
91 | exports.make_thing_id = require("./thing_manager").make_thing_id;
92 |
93 | // coercsion
94 | exports.as = iotdb_thing.as;
95 |
96 | exports.reset = () => {
97 | if (_instance) {
98 | _instance.disconnect();
99 | _instance = null;
100 | }
101 |
102 | modules.reset();
103 | settings.reset()
104 | }
105 |
106 | // testing only
107 | exports.shims = {
108 | _settings: null,
109 | reset: () => _instance = null,
110 | settings: k => {
111 | if (k) {
112 | exports.shims._settings = exports.settings;
113 | exports.settings = k;
114 | } else {
115 | exports.settings = exports.shims._settings
116 | }
117 | },
118 | }
119 |
120 | // Windows compatibility
121 | require("./windows").setup();
122 |
123 | // debugging
124 | exports.__filename = __filename;
125 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "author": "David P. Janes (https://iotdb.org)",
3 | "bugs": {
4 | "url": "https://github.com/dpjanes/node-iotdb/issues"
5 | },
6 | "dependencies": {
7 | "iotdb-helpers": "~3.0.29",
8 | "iotdb-thing": "~3.0.9",
9 | "semver": "~5.3.0"
10 | },
11 | "description": "IOTDB.org",
12 | "devDependencies": {
13 | "grunt": "~1.0.1",
14 | "grunt-contrib-jshint": "~1.1.0",
15 | "grunt-contrib-nodeunit": "~1.0.0",
16 | "grunt-contrib-uglify": "~2.3.0",
17 | "grunt-contrib-watch": "~1.0.0",
18 | "grunt-jsbeautifier": "~0.2.13",
19 | "jshint-stylish": "~2.2.1",
20 | "load-grunt-tasks": "~3.5.2",
21 | "request": "~2.81.0"
22 | },
23 | "homepage": "https://github.com/dpjanes/node-iotdb",
24 | "keywords": [
25 | "IOTDB",
26 | "IOT",
27 | "Internet",
28 | "Things",
29 | "Hardware",
30 | "Raspberry",
31 | "Pi",
32 | "Arduino",
33 | "Firmata"
34 | ],
35 | "license": "Apache-2.0",
36 | "main": "iotdb.js",
37 | "name": "iotdb",
38 | "repository": {
39 | "type": "git",
40 | "url": "https://github.com/dpjanes/node-iotdb"
41 | },
42 | "scripts": {
43 | "cover": "istanbul cover _mocha",
44 | "test": "grunt"
45 | },
46 | "version": "3.0.12"
47 | }
--------------------------------------------------------------------------------
/samples/test-denon-band.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test-denon-band.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2016-07-22
7 | *
8 | * Copyright [2013-2016] [David P. Janes]
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | "use strict";
24 |
25 | const iotdb = require("../iotdb")
26 | const _ = iotdb._;
27 |
28 | iotdb.use("homestar-denon-avr");
29 |
30 | const things = iotdb.connect("DenonAVR");
31 |
32 | const bands = [
33 | "iot-purpose:band.bluray",
34 | "iot-purpose:band.game",
35 | "iot-purpose:band.cable",
36 | "iot-purpose:band.dvd",
37 | ]
38 |
39 | things.on('istate', function (thing) {
40 | console.log("+ istate\n ", thing.thing_id(), "\n ", thing.state("istate"));
41 | });
42 | things.on("meta", function (thing) {
43 | console.log("+ meta\n ", thing.thing_id(), thing.state("meta"));
44 | });
45 | things.on("thing", function (thing) {
46 | console.log("+ thing\n ", thing.thing_id(), thing.state("meta"), things._sid);
47 |
48 | let count = 0;
49 | setInterval(() => {
50 | thing.set(":band", bands[count++ % bands.length], 2000)
51 | .then((ud) => {
52 | console.log("+", "update", ud);
53 | })
54 | .catch(error => {
55 | console.log("#", _.error.message(error));
56 | });
57 | }, 1000);
58 | });
59 |
--------------------------------------------------------------------------------
/samples/test-denon-volume.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test-denon-volume.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2016-07-22
7 | *
8 | * Copyright [2013-2016] [David P. Janes]
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | "use strict";
24 |
25 | const iotdb = require("../iotdb")
26 |
27 | iotdb.use("homestar-denon-avr");
28 |
29 | const things = iotdb.connect("DenonAVR");
30 |
31 | things.on('istate', function (thing) {
32 | console.log("+ istate\n ", thing.thing_id(), "\n ", thing.state("istate"));
33 | });
34 | things.on("meta", function (thing) {
35 | console.log("+ meta\n ", thing.thing_id(), thing.state("meta"));
36 | });
37 | things.on("thing", function (thing) {
38 | console.log("+ thing\n ", thing.thing_id(), thing.state("meta"), things._sid);
39 | });
40 |
41 | let count = 0;
42 | setInterval(() => things.set(":volume", (count += 10) % 100, iotdb.as.percent()), 1000);
43 |
--------------------------------------------------------------------------------
/samples/test-earthquake.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test-earthquake.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2016-06-28
7 | *
8 | * Copyright [2013-2016] [David P. Janes]
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | "use strict";
24 |
25 | const iotdb = require("../iotdb")
26 |
27 | iotdb.use("homestar-feed");
28 |
29 | const things = iotdb.connect('USGSEarthquake');
30 | things.on('istate', function (thing) {
31 | console.log("+ istate\n ", thing.thing_id(), "\n ", thing.state("istate"));
32 | });
33 | things.on("meta", function (thing) {
34 | console.log("+ meta\n ", thing.thing_id(), thing.state("meta"));
35 | });
36 | things.on("thing", function (thing) {
37 | console.log("+ thing\n ", thing.thing_id(), thing.state("meta"));
38 | });
39 |
40 |
--------------------------------------------------------------------------------
/samples/test-hue.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test-hue.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2016-07-30
7 | *
8 | * Copyright [2013-2016] [David P. Janes]
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | "use strict";
24 |
25 | const iotdb = require("../iotdb")
26 |
27 | iotdb.use("homestar-hue");
28 |
29 | const things = iotdb.connect("HueLight");
30 |
31 | things.on('istate', function (thing) {
32 | console.log("+ istate\n ", thing.thing_id(), "\n ", thing.state("istate"));
33 | });
34 | things.on('ostate', function (thing) {
35 | console.log("+ ostate\n ", thing.thing_id(), "\n ", thing.state("ostate"));
36 | });
37 | things.on("meta", function (thing) {
38 | console.log("+ meta\n ", thing.thing_id(), thing.state("meta"));
39 | });
40 | things.on("thing", function (thing) {
41 | console.log("+ thing\n ", thing.thing_id(), thing.state("meta"), things._sid);
42 | });
43 |
44 | let count = 0;
45 | // setInterval(() => things.set(":brightness", (count += 10) % 100), 1000);
46 | // setInterval(() => things.set(":on", count++ % 2, 1000));
47 | things.set(":color", "red")
48 |
--------------------------------------------------------------------------------
/samples/test-lifx.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test-lifx.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2016-07-01
7 | *
8 | * Copyright [2013-2016] [David P. Janes]
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | "use strict";
24 |
25 | const iotdb = require("../iotdb")
26 |
27 | iotdb.use("homestar-lifx");
28 |
29 | const things = iotdb.connect("LIFXWhite");
30 |
31 | things.on('istate', function (thing) {
32 | console.log("+ istate\n ", thing.thing_id(), "\n ", thing.state("istate"));
33 | });
34 | things.on("meta", function (thing) {
35 | console.log("+ meta\n ", thing.thing_id(), thing.state("meta"));
36 | });
37 | things.on("thing", function (thing) {
38 | console.log("+ thing\n ", thing.thing_id(), thing.state("meta"), things._sid);
39 | });
40 |
41 | let count = 0;
42 | setInterval(() => things.set(":brightness", (count += 10) % 100), 1000);
43 |
--------------------------------------------------------------------------------
/samples/test-multiple.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test-multiple.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2016-06-28
7 | *
8 | * Copyright [2013-2016] [David P. Janes]
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | "use strict";
24 |
25 | const iotdb = require("../iotdb")
26 |
27 | iotdb.use("homestar-wemo");
28 | iotdb.use("homestar-feed");
29 |
30 | const things = iotdb
31 | .connect('USGSEarthquake')
32 | .with_name('WeMo Switch')
33 | .connect('WeMoSocket')
34 |
35 | things.on('istate', function (thing) {
36 | console.log("+ state\n ", thing.thing_id(), "\n ", thing.state("istate"));
37 | });
38 | things.on("meta", function (thing) {
39 | console.log("+ meta\n ", thing.thing_id(), thing.state("meta"));
40 | });
41 | things.on("thing", function (thing) {
42 | console.log("+ thing\n ", thing.thing_id(), thing.state("meta"), things._sid);
43 | });
44 |
45 | let count = 0;
46 | setInterval(() => things.set(":on", count++ % 2), 1000);
47 |
--------------------------------------------------------------------------------
/samples/test-plug.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test-plug.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2016-06-28
7 | *
8 | * Copyright [2013-2016] [David P. Janes]
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | "use strict";
24 |
25 | const iotdb = require("../iotdb")
26 |
27 | iotdb.use("homestar-wemo");
28 | iotdb.use("homestar-smartthings");
29 |
30 | const things = iotdb.connect()
31 | .with_facet("iot-facet:plug")
32 |
33 | things.on('istate', function (thing) {
34 | console.log("+ istate\n ", thing.thing_id(), "\n ", thing.state("istate"));
35 | });
36 | things.on("meta", function (thing) {
37 | console.log("+ meta\n ", thing.thing_id(), thing.state("meta"));
38 | });
39 | things.on("thing", function (thing) {
40 | console.log("+ thing\n ", thing.thing_id(), thing.state("meta"), things._sid);
41 | });
42 |
43 | let count = 0;
44 | setInterval(() => things.set(":on", count++ % 2), 2000);
45 |
--------------------------------------------------------------------------------
/samples/test-smartthings.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test-smartthings.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2016-06-28
7 | *
8 | * Copyright [2013-2016] [David P. Janes]
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | "use strict";
24 |
25 | const iotdb = require("../iotdb")
26 | iotdb.use("homestar-smartthings");
27 |
28 | const things = iotdb.connect()
29 |
30 | things.on('istate', function (thing) {
31 | console.log("+ istate\n ", thing._tid, thing.thing_id(), "\n ", thing.state("istate"));
32 | });
33 | things.on("meta", function (thing) {
34 | console.log("+ meta\n ", thing._tid, thing.thing_id(), thing.state("meta"));
35 | });
36 | things.on("thing", function (thing) {
37 | console.log("+ thing\n ", thing._tid, thing.thing_id(), thing.state("meta"), things._sid);
38 | });
39 |
40 | let count = 0;
41 | setInterval(() => things.set(":on", count++ % 2), 2000);
42 |
--------------------------------------------------------------------------------
/samples/test-wemo.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test-plug.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2016-06-29
7 | *
8 | * Copyright [2013-2016] [David P. Janes]
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | "use strict";
24 |
25 | const iotdb = require("../iotdb")
26 |
27 | iotdb.use("homestar-wemo");
28 |
29 | const things = iotdb.connect("WeMoSocket");
30 |
31 | things.on('istate', function (thing) {
32 | console.log("+ istate\n ", thing.thing_id(), "\n ", thing.state("istate"));
33 | });
34 | things.on("meta", function (thing) {
35 | console.log("+ meta\n ", thing.thing_id(), thing.state("meta"));
36 | });
37 | things.on("thing", function (thing) {
38 | console.log("+ thing\n ", thing.thing_id(), thing.state("meta"), things._sid);
39 | });
40 |
41 | let count = 0;
42 | setInterval(() => things.set(":on", count++ % 2), 2000);
43 |
--------------------------------------------------------------------------------
/settings.js:
--------------------------------------------------------------------------------
1 | /*
2 | * settings.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2014-02-14
7 | * "Valentines's Day"
8 | *
9 | * Copyright [2013-2016] [David P. Janes]
10 | *
11 | * Licensed under the Apache License, Version 2.0 (the "License");
12 | * you may not use this file except in compliance with the License.
13 | * You may obtain a copy of the License at
14 | *
15 | * http://www.apache.org/licenses/LICENSE-2.0
16 | *
17 | * Unless required by applicable law or agreed to in writing, software
18 | * distributed under the License is distributed on an "AS IS" BASIS,
19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 | * See the License for the specific language governing permissions and
21 | * limitations under the License.
22 | */
23 |
24 | "use strict";
25 |
26 | const _ = require('./helpers');
27 |
28 | const events = require('events');
29 | const fs = require('fs');
30 | const path = require('path');
31 |
32 | const logger = _.logger.make({
33 | name: 'iotdb',
34 | module: 'settings',
35 | });
36 |
37 | let _writeFileSync = fs.writeFileSync;
38 |
39 | /**
40 | * Return every folder from CWD to / that has a ".iotdb" folder in it
41 | */
42 | const _paths = function () {
43 | const paths = [];
44 | let current_folder = process.cwd();
45 |
46 | while (true) {
47 | const iotdb_folder = path.join(current_folder, ".iotdb");
48 |
49 | try {
50 | const stbuf = fs.statSync(iotdb_folder);
51 | if (stbuf.isDirectory()) {
52 | paths.push(iotdb_folder);
53 | }
54 | } catch (x) {}
55 |
56 | const next_folder = path.normalize(path.join(current_folder, ".."));
57 | if (next_folder === current_folder) {
58 | break;
59 | }
60 |
61 | current_folder = next_folder;
62 | }
63 |
64 | return paths;
65 | };
66 |
67 | const make = (initd) => {
68 | const self = Object.assign({}, events.EventEmitter.prototype);
69 |
70 | const _initd = _.d.compose.shallow(initd, {
71 | root: "/",
72 | settings: "keystore.json",
73 | path: _paths(),
74 | })
75 | self.d = {}
76 |
77 | const _normalize_key = function (key) {
78 | if (!key.match(/^\//)) {
79 | key = _initd.root.replace('/*$', '') + '/' + key;
80 | }
81 |
82 | return "/" + key.replace(/^\/*/, '');
83 | };
84 |
85 | const _load = function () {
86 | const filenames = _.cfg.find(_initd.path, _initd.settings);
87 |
88 | // IDK why the following does not work
89 | // _.cfg.load.json(filenames, docd => self.d = _.d.compose.deep(self.d, docd.doc))
90 | _.cfg.load.json(filenames, docd => {
91 | self.d = _.d.compose.deep(self.d, docd.doc)
92 | });
93 |
94 | self.emit("loaded");
95 | };
96 |
97 | self.get = (key, otherwise) => _.d.get(self.d, _normalize_key(key), otherwise);
98 |
99 | self.set = (key, value) => {
100 | key = _normalize_key(key);
101 |
102 | _.d.set(self.d, key, value);
103 |
104 | self.emit("changed", key);
105 | };
106 |
107 | /*
108 | */
109 | let _saved = null;
110 |
111 | self.save = (key, value) => {
112 | self.set(key, value);
113 |
114 | const _save_path = ".iotdb/keystore.json";
115 |
116 | if (!_saved) {
117 | _saved = {};
118 | _.cfg.load.json([_save_path], docd => _saved = _.d.compose.deep(_saved, docd.doc));
119 | }
120 |
121 | _.d.set(_saved, _normalize_key(key), value);
122 |
123 | process.nextTick(() => {
124 | if (!_saved) {
125 | return;
126 | }
127 |
128 | _writeFileSync(_save_path, JSON.stringify(_saved, null, 2));
129 | _saved = null;
130 | });
131 | };
132 |
133 | self.setMaxListeners(0);
134 | _load()
135 |
136 | return self;
137 | };
138 |
139 | let _settings;
140 |
141 | const instance = () => {
142 | if (!_settings) {
143 | _settings = make();
144 | }
145 |
146 | return _settings;
147 | };
148 |
149 | const reset = () => {
150 | _settings = null;
151 | };
152 |
153 | /*
154 | * API
155 | */
156 | exports.make = make;
157 | exports.instance = instance;
158 | exports.reset = reset;
159 | exports.shims = {
160 | paths: _paths,
161 | writeFileSync: f => _writeFileSync = f || fs.writeFileSync,
162 | };
163 |
--------------------------------------------------------------------------------
/test/data/abstract-clock.jsonld:
--------------------------------------------------------------------------------
1 | {
2 | "@context": {
3 | "@base": "http://localhost:9000/dpjanes/models/abstract-clock",
4 | "iot": "https://iotdb.org/pub/iot#",
5 | "iot-attribute": "https://iotdb.org/pub/iot-attribute#",
6 | "iot-js": "https://iotdb.org/pub/iot-js#",
7 | "iot:format": {
8 | "@type": "@id"
9 | },
10 | "iot:type": {
11 | "@type": "@id"
12 | },
13 | "iot:model": {
14 | "@type": "@id"
15 | },
16 | "iot:purpose": {
17 | "@type": "@id"
18 | }
19 | },
20 | "@id": "",
21 | "@type": "iot:Model",
22 | "iot:attribute": {
23 | "@id": "#when-instant",
24 | "@type": "iot:Attribute",
25 | "iot:format": "iot:datetime",
26 | "iot:type": "iot:string",
27 | "iot:purpose": "iot-attribute:when-instant"
28 | },
29 | "iot:name": "abstract-clock"
30 | }
31 |
--------------------------------------------------------------------------------
/test/data/abstract-stove-oven.jsonld:
--------------------------------------------------------------------------------
1 | {
2 | "@context": {
3 | "@base": "http://localhost:9000/dpjanes/models/abstract-stove-oven",
4 | "iot": "https://iotdb.org/pub/iot#",
5 | "iot-attribute": "https://iotdb.org/pub/iot-attribute#",
6 | "iot-iotdb": "https://iotdb.org/pub/iot-iotdb#",
7 | "iot-js": "https://iotdb.org/pub/iot-js#",
8 | "iot:type": {
9 | "@type": "@id"
10 | },
11 | "iot-unit": "https://iotdb.org/pub/iot-unit#",
12 | "iot:model": {
13 | "@type": "@id"
14 | },
15 | "iot:purpose": {
16 | "@type": "@id"
17 | },
18 | "iot:unit": {
19 | "@type": "@id"
20 | }
21 | },
22 | "@id": "",
23 | "@type": "iot:Model",
24 | "iot-iotdb:model-validator": "function (paramd) {\n \"use strict\";\n for (var code in paramd.codes) {\n var value = paramd.stated[code];\n \n if (code == \"temperature_f\") {\n if (value < 150) {\n paramd.thingd[\"temperature_f\"] = 0;\n paramd.thingd[\"temperature_c\"] = 0;\n } else {\n paramd.thingd[\"temperature_c\"] = Math.round(paramd.libs.temperature.f2c(value))\n }\n } else if (code == \"temperature_c\") {\n if (value < paramd.libs.temperature.f2c(150)) {\n paramd.thingd[\"temperature_f\"] = 0;\n paramd.thingd[\"temperature_c\"] = 0;\n } else {\n paramd.thingd[\"temperature_f\"] = Math.round(paramd.libs.temperature.c2f(value));\n }\n }\n }\n }",
25 | "iot:attribute": [
26 | {
27 | "@id": "#on",
28 | "@type": "iot:Attribute",
29 | "iot:type": "iot:boolean",
30 | "iot:purpose": "iot-attribute:on"
31 | },
32 | {
33 | "@id": "#temperature_f",
34 | "@type": "iot:Attribute",
35 | "iot:maximum": 500,
36 | "iot:minimum": 0,
37 | "iot:type": "iot:integer",
38 | "iot:purpose": "iot-attribute:temperature",
39 | "iot:unit": "iot-unit:temperature.si.fahrenheit"
40 | },
41 | {
42 | "@id": "#temperature_c",
43 | "@type": "iot:Attribute",
44 | "iot:maximum": 260,
45 | "iot:minimum": 0,
46 | "iot:type": "iot:integer",
47 | "iot:purpose": "iot-attribute:temperature",
48 | "iot:unit": "iot-unit:temperature.si.celsius"
49 | },
50 | {
51 | "@id": "#reading_c",
52 | "@type": "iot:Attribute",
53 | "iot:type": "iot:integer",
54 | "iot:purpose": "iot-attribute:reading",
55 | "iot:unit": "iot-unit:temperature.si.celsius"
56 | },
57 | {
58 | "@id": "#reading_f",
59 | "@type": "iot:Attribute",
60 | "iot:type": "iot:integer",
61 | "iot:purpose": "iot-attribute:reading",
62 | "iot:unit": "iot-unit:temperature.si.fahrenheit"
63 | }
64 | ],
65 | "iot:name": "abstract-stove-oven"
66 | }
67 |
--------------------------------------------------------------------------------
/test/data/cfg1/.d:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dpjanes/node-iotdb/b6f3c26d654245b3493898a1bfd61d6c19aee227/test/data/cfg1/.d
--------------------------------------------------------------------------------
/test/data/cfg1/.d.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dpjanes/node-iotdb/b6f3c26d654245b3493898a1bfd61d6c19aee227/test/data/cfg1/.d.js
--------------------------------------------------------------------------------
/test/data/cfg1/.d.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dpjanes/node-iotdb/b6f3c26d654245b3493898a1bfd61d6c19aee227/test/data/cfg1/.d.json
--------------------------------------------------------------------------------
/test/data/cfg1/a.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dpjanes/node-iotdb/b6f3c26d654245b3493898a1bfd61d6c19aee227/test/data/cfg1/a.js
--------------------------------------------------------------------------------
/test/data/cfg1/a.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "a.json"
3 | }
4 |
5 |
--------------------------------------------------------------------------------
/test/data/cfg1/b.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dpjanes/node-iotdb/b6f3c26d654245b3493898a1bfd61d6c19aee227/test/data/cfg1/b.js
--------------------------------------------------------------------------------
/test/data/cfg1/c.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "c.json",
3 | "data": [ 1, 2, 3 ]
4 | }
5 |
6 |
--------------------------------------------------------------------------------
/test/data/cfg2/a.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dpjanes/node-iotdb/b6f3c26d654245b3493898a1bfd61d6c19aee227/test/data/cfg2/a.json
--------------------------------------------------------------------------------
/test/data/cfg2/b.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dpjanes/node-iotdb/b6f3c26d654245b3493898a1bfd61d6c19aee227/test/data/cfg2/b.js
--------------------------------------------------------------------------------
/test/data/cfg2/e.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dpjanes/node-iotdb/b6f3c26d654245b3493898a1bfd61d6c19aee227/test/data/cfg2/e.js
--------------------------------------------------------------------------------
/test/data/cfg2/f.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dpjanes/node-iotdb/b6f3c26d654245b3493898a1bfd61d6c19aee227/test/data/cfg2/f.json
--------------------------------------------------------------------------------
/test/data/cfg3/sub1/file1.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dpjanes/node-iotdb/b6f3c26d654245b3493898a1bfd61d6c19aee227/test/data/cfg3/sub1/file1.txt
--------------------------------------------------------------------------------
/test/data/cfg3/sub2/file2.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dpjanes/node-iotdb/b6f3c26d654245b3493898a1bfd61d6c19aee227/test/data/cfg3/sub2/file2.txt
--------------------------------------------------------------------------------
/test/instrument/attribute.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Duplicate
3 | */
4 | var d = require('../../attribute')
5 | for (var key in d) {
6 | exports[key] = d[key];
7 | }
8 |
9 | /**
10 | * Instrument
11 | */
12 | exports.make_null = function (purpose, code, name) {
13 | return exports.make(purpose, code, name).property("iot:type", "iot:type.null");
14 | };
15 | exports.make_boolean = function (purpose, code, name) {
16 | return exports.make(purpose, code, name).property("iot:type", "iot:type.boolean");
17 | };
18 | exports.make_integer = function (purpose, code, name) {
19 | return exports.make(purpose, code, name).property("iot:type", "iot:type.integer");
20 | };
21 | exports.make_number = function (purpose, code, name) {
22 | return exports.make(purpose, code, name).property("iot:type", "iot:type.number");
23 | };
24 |
25 | exports.make_unit = function (purpose, code, name) {
26 | return exports
27 | .make(purpose, code, name)
28 | .property("iot:type", "iot:type.number")
29 | .unit("iot-unit:math.fraction.unit")
30 | .minimum(0)
31 | .maximum(1);
32 | };
33 |
34 | exports.make_percent = function (purpose, code, name) {
35 | return exports
36 | .make(purpose, code, name)
37 | .property("iot:type", "iot:type.number")
38 | .unit("iot-unit:math.fraction.percent")
39 | .minimum(0)
40 | .maximum(100);
41 | };
42 | exports.make_string = function (purpose, code, name) {
43 | return exports.make(purpose, code, name).property("iot:type", "iot:type.string");
44 | };
45 |
46 | exports.make_iri = function (purpose, code, name) {
47 | return exports.make(purpose, code, name)
48 | .property("iot:type", "iot:type.string")
49 | .format(":format.iri");
50 | };
51 |
52 | exports.make_datetime = function (purpose, code, name) {
53 | return exports.make(purpose, code, name)
54 | .property("iot:type", "iot:type.string")
55 | .format("iot:format.datetime");
56 | };
57 |
58 | exports.make_date = function (purpose, code, name) {
59 | return exports.make(purpose, code, name)
60 | .property("iot:type", "iot:type.string")
61 | .format("iot:format.date");
62 | };
63 |
64 | exports.make_time = function (purpose, code, name) {
65 | return exports.make(purpose, code, name)
66 | .property("iot:type", "iot:type.string")
67 | .format("iot:format.time");
68 | };
69 |
70 | exports.make_color = function (purpose, code, name) {
71 | return exports.make(purpose, code, name)
72 | .property("iot:type", "iot:type.string")
73 | .format("iot:format.color");
74 | };
75 |
--------------------------------------------------------------------------------
/test/instrument/homestar-broken/index.js:
--------------------------------------------------------------------------------
1 | "use strict"
2 |
3 | blow up
4 |
--------------------------------------------------------------------------------
/test/instrument/homestar-broken/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "author": "David P. Janes (https://iotdb.org)",
3 | "bugs": {
4 | "url": "https://github.com/dpjanes/homestar-broken/issues"
5 | },
6 | "dependencies": {
7 | "iotdb": ">=0.6.3"
8 | },
9 | "description": "HomeStar / IOTDB Bridge for Test",
10 | "devDependencies": {
11 | "grunt": "~0.4.5",
12 | "grunt-contrib-jshint": "~0.10.0",
13 | "grunt-contrib-nodeunit": "~0.2.0",
14 | "grunt-contrib-uglify": "~0.5.0",
15 | "grunt-contrib-watch": "~0.5.0",
16 | "grunt-jsbeautifier": "^0.2.7",
17 | "jshint-stylish": "~0.1.3",
18 | "load-grunt-tasks": "~0.2.0",
19 | "request": "^2.36.0"
20 | },
21 | "homepage": "https://homestar.io",
22 | "homestar": {},
23 | "license": "Apache-2.0",
24 | "main": "index.js",
25 | "name": "homestar-broken",
26 | "private": false,
27 | "repository": {
28 | "type": "git",
29 | "url": "https://github.com/dpjanes/homestar-broken"
30 | },
31 | "scripts": {
32 | "broken": "grunt"
33 | },
34 | "version": "0.0.0"
35 | }
36 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "curly": true,
3 | "eqeqeq": true,
4 | "immed": true,
5 | "latedef": "nofunc",
6 | "newcap": false,
7 | "noarg": true,
8 | "sub": true,
9 | "undef": true,
10 | "unused": "var",
11 | "boss": true,
12 | "eqnull": true,
13 | "node": true,
14 | "-W086": true
15 | }
16 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/DIST.sh:
--------------------------------------------------------------------------------
1 | #
2 | # DIST.sh
3 | #
4 | # David Janes
5 | # IOTDB
6 | # 2016-01-06
7 | #
8 |
9 | exit 0
10 | PACKAGE=homestar-test
11 | DIST_ROOT=/var/tmp/.dist.$$
12 |
13 | if [ ! -d "$DIST_ROOT" ]
14 | then
15 | mkdir "$DIST_ROOT"
16 | fi
17 |
18 | echo "=================="
19 | echo "NPM Packge: $PACKAGE"
20 | echo "=================="
21 | (
22 | NPM_DST="$DIST_ROOT/$PACKAGE"
23 | echo "NPM_DST=$NPM_DST"
24 |
25 | if [ -d ${NPM_DST} ]
26 | then
27 | rm -rf "${NPM_DST}"
28 | fi
29 | mkdir "${NPM_DST}" || exit 1
30 |
31 | update-package --increment-version --package "$PACKAGE" --homestar || exit 1
32 |
33 | tar cf - \
34 | --exclude "node_modules" \
35 | README.md LICENSE \
36 | homestar.json package.json \
37 | TestBridge.js index.js \
38 | models/*.js models/*.json \
39 | |
40 | ( cd "${NPM_DST}" && tar xvf - && npm publish ) || exit 1
41 | git commit -m "new release" package.json || exit 1
42 | git push || exit 1
43 |
44 | echo "end"
45 | )
46 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/Gruntfile.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = function (grunt) {
4 | // Show elapsed time at the end
5 | // require('time-grunt')(grunt);
6 | // Load all grunt tasks
7 | require('load-grunt-tasks')(grunt);
8 |
9 | // Project configuration.
10 | grunt.initConfig({
11 | nodeunit: {
12 | files: []
13 | },
14 | jshint: {
15 | options: {
16 | jshintrc: '.jshintrc',
17 | reporter: require('jshint-stylish')
18 | },
19 | gruntfile: {
20 | src: 'Gruntfile.js'
21 | },
22 | lib: {
23 | src: [
24 | '*.js', 'models/*.js', 'samples/*.js'
25 | ]
26 | },
27 | test: {
28 | src: []
29 | }
30 | },
31 | watch: {
32 | gruntfile: {
33 | files: '<%= jshint.gruntfile.src %>',
34 | tasks: ['jshint:gruntfile']
35 | },
36 | lib: {
37 | files: '<%= jshint.lib.src %>',
38 | tasks: ['jshint:lib', 'nodeunit']
39 | },
40 | test: {
41 | files: '<%= jshint.test.src %>',
42 | tasks: ['jshint:test', 'nodeunit']
43 | }
44 | },
45 | jsbeautifier: {
46 | files: [
47 | '*.js', 'models/*.js', 'samples/*.js'
48 | ],
49 | options: {
50 | js: {
51 | jslint_happy: true,
52 | indentChar: ' ',
53 | indentSize: 4
54 | }
55 | },
56 | }
57 | });
58 |
59 | // Default task.
60 | // grunt.registerTask('default', ['jsbeautifier', 'jshint', 'nodeunit']);
61 | grunt.registerTask('default', ['jsbeautifier', 'jshint']);
62 |
63 | };
64 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/README.md:
--------------------------------------------------------------------------------
1 | # homestar-test
2 | IOTDB / Home☆Star Module for [Test]().
3 |
4 |
5 |
6 | # Installation
7 |
8 | [Install Home☆Star first](https://homestar.io/about/install).
9 |
10 | Then:
11 |
12 | $ homestar install homestar-test
13 |
14 | # Testing
15 |
16 | ## IOTDB
17 |
18 | Turn on Test.
19 |
20 | $ node
21 | >>> iotdb = require('iotdb')
22 | >>> things = iotdb.connect("Test")
23 | >>> things.set(":on", true);
24 |
25 | ## [IoTQL](https://github.com/dpjanes/iotdb-iotql)
26 |
27 | Change to HDMI1
28 |
29 | $ homestar install iotql
30 | $ homestar iotql
31 | > SET state:on = true WHERE meta:model-id = "test";
32 |
33 | ## Home☆Star
34 |
35 | Do:
36 |
37 | $ homestar runner browser=1
38 |
39 | You may have to refresh the page, as it may take a little while for your Things to be discovered. If your TV is not on it won't show up.
40 |
41 | # Models
42 | ## Test
43 |
44 | See [Test.iotql](https://github.com/dpjanes/homestar-test/blob/master/models/Test.iotql)
45 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/homestar.json:
--------------------------------------------------------------------------------
1 | {
2 | "module": true
3 | }
4 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * index.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2016-01-06
7 | *
8 | * Copyright [2013-2015] [David P. Janes]
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | "use strict";
24 |
25 | exports.Bridge = require('./TestBridge').Bridge;
26 | exports.bindings = [
27 | require('./models/Test').binding,
28 | require('./models/TestMatch').binding,
29 | require('./models/TestNoDiscover').binding,
30 | require('./models/TestMissingBridge').binding,
31 | require('./models/TestMissingModel').binding,
32 | ];
33 |
34 | // exports.iotdb = require("iotdb");
35 | exports.wrap = function(name, initd) {
36 | return exports.iotdb.make_wrap(name, exports.bindings, initd);
37 | };
38 |
39 | exports.setup = function() {
40 | };
41 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/models/Test.iotql:
--------------------------------------------------------------------------------
1 | --
2 | -- compile to JSON with 'iotql-model Test.iotql'
3 | --
4 | CREATE MODEL Test WITH
5 | schema:name = "Test",
6 | schema:description = "Test"
7 | ATTRIBUTE on WITH
8 | schema:name = "on",
9 | iot:purpose = iot-purpose:on,
10 | iot:type = iot:type.boolean,
11 | iot:write = true,
12 | iot:read = true,
13 | iot:actuator = true,
14 | iot:sensor = true
15 | ;
16 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/models/Test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Test.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-01-06
7 | */
8 |
9 | exports.binding = {
10 | bridge: require('../TestBridge').Bridge,
11 | model: require('./test.json'),
12 | };
13 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/models/TestMatch.js:
--------------------------------------------------------------------------------
1 | /*
2 | * TestMatch.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-07-18
7 | */
8 |
9 | const model = require('./test.json');
10 | model["iot:model-id"] = "test-match";
11 |
12 | exports.binding = {
13 | bridge: require('../TestBridge').Bridge,
14 | model: model,
15 | matchd: {
16 | "iot:thing-number": 101,
17 | },
18 | };
19 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/models/TestMissingBridge.js:
--------------------------------------------------------------------------------
1 | /*
2 | * TestMissingBridge.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-01-06
7 | */
8 |
9 | exports.binding = {
10 | bridge: null,
11 | model: require('./Test.json'),
12 | };
13 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/models/TestMissingModel.js:
--------------------------------------------------------------------------------
1 | /*
2 | * TestMissingModel.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-01-06
7 | */
8 |
9 | exports.binding = {
10 | bridge: require('../TestBridge').Bridge,
11 | model: null,
12 | };
13 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/models/TestNoDiscover.js:
--------------------------------------------------------------------------------
1 | /*
2 | * TestNoDiscover.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-01-06
7 | */
8 |
9 | exports.binding = {
10 | model_code: "TestNoDiscover",
11 | discover: false,
12 | bridge: require('../TestBridge').Bridge,
13 | model: require('./Test.json'),
14 | };
15 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/models/test.json:
--------------------------------------------------------------------------------
1 | {
2 | "@context": {
3 | "@base": "file:///test",
4 | "@vocab": "file:///test#",
5 | "iot": "https://iotdb.org/pub/iot#",
6 | "iot-purpose": "https://iotdb.org/pub/iot-purpose#",
7 | "iot:purpose": {
8 | "@id": "https://iotdb.org/pub/iot#purpose",
9 | "@type": "@id"
10 | },
11 | "iot:type": {
12 | "@id": "https://iotdb.org/pub/iot#type",
13 | "@type": "@id"
14 | },
15 | "schema": "http://schema.org/"
16 | },
17 | "@id": "",
18 | "@type": "iot:Model",
19 | "iot:attribute": [
20 | {
21 | "@id": "#on",
22 | "@type": "iot:Attribute",
23 | "iot:actuator": false,
24 | "iot:purpose": "iot-purpose:on",
25 | "iot:read": true,
26 | "iot:sensor": true,
27 | "iot:type": "iot:type.boolean",
28 | "iot:write": false,
29 | "schema:name": "on"
30 | }
31 | ],
32 | "iot:model-id": "test",
33 | "schema:description": "Test",
34 | "schema:name": "Test"
35 | }
36 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "author": "David P. Janes (https://iotdb.org)",
3 | "bugs": {
4 | "url": "https://github.com/dpjanes/homestar-test/issues"
5 | },
6 | "dependencies": {
7 | "iotdb": ">=0.6.3"
8 | },
9 | "description": "HomeStar / IOTDB Bridge for Test",
10 | "devDependencies": {
11 | "grunt": "~0.4.5",
12 | "grunt-contrib-jshint": "~0.10.0",
13 | "grunt-contrib-nodeunit": "~0.2.0",
14 | "grunt-contrib-uglify": "~0.5.0",
15 | "grunt-contrib-watch": "~0.5.0",
16 | "grunt-jsbeautifier": "^0.2.7",
17 | "jshint-stylish": "~0.1.3",
18 | "load-grunt-tasks": "~0.2.0",
19 | "request": "^2.36.0"
20 | },
21 | "homepage": "https://homestar.io",
22 | "homestar": {},
23 | "license": "Apache-2.0",
24 | "main": "index.js",
25 | "name": "homestar-test",
26 | "private": false,
27 | "repository": {
28 | "type": "git",
29 | "url": "https://github.com/dpjanes/homestar-test"
30 | },
31 | "scripts": {
32 | "test": "grunt"
33 | },
34 | "version": "0.0.0"
35 | }
36 |
--------------------------------------------------------------------------------
/test/instrument/homestar-test/samples/iotdb_template.js:
--------------------------------------------------------------------------------
1 | /*
2 | * How to use this module in IOTDB / HomeStar
3 | * This is the best way to do this
4 | * Note: to work, this package must have been installed by 'homestar install'
5 | */
6 |
7 | "use strict";
8 |
9 | var iotdb = require('iotdb');
10 | var iot = iotdb.iot();
11 |
12 | var things = iot.connect('TestSomething');
13 | things.on("state", function(thing) {
14 | console.log("+", "state", thing.thing_id(), "\n ", thing.state("istate"));
15 | });
16 | things.on("meta", function(thing) {
17 | console.log("+", "meta", thing.thing_id(), "\n ", thing.state("meta"));
18 | });
19 | things.on("thing", function(thing) {
20 | console.log("+", "discovered", thing.thing_id(), "\n ", thing.state("meta"));
21 | });
22 |
23 |
24 |
--------------------------------------------------------------------------------
/test/instrument/iotdb.js:
--------------------------------------------------------------------------------
1 | /*
2 | * iotdb.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-01-06
7 | */
8 |
9 | "use strict";
10 |
11 | const path = require("path");
12 |
13 | const iotdb = require("../../iotdb");
14 | const settings = require("../../settings");
15 |
16 | let _settings;
17 | iotdb.shims.settings(() => {
18 | if (!_settings) {
19 | _settings = settings.make();
20 | _settings.d = {
21 | "modules": {
22 | "homestar-test": path.join(__dirname, "./homestar-test"),
23 | "homestar-broken": path.join(__dirname, "./homestar-broken"),
24 | }
25 | };
26 | }
27 |
28 | return _settings;
29 | });
30 |
--------------------------------------------------------------------------------
/test/instrument/model_maker.js:
--------------------------------------------------------------------------------
1 | var attribute = require("../../attribute");
2 | var constants = require("../../constants");
3 | var _ = require("../../helpers");
4 |
5 | /**
6 | * Duplicate
7 | */
8 | var d = require('../../model_maker')
9 | for (var key in d) {
10 | exports[key] = d[key];
11 | }
12 |
13 | var ModelMaker = exports.ModelMaker;
14 |
15 | /**
16 | * Instrument
17 | */
18 | ModelMaker.prototype.i = function (code, attribute) {
19 | var name = _.ld.first(attribute, constants.schema_name);
20 |
21 | if (arguments.length === 1) {
22 | attribute = arguments[0];
23 | code = attribute.code();
24 | }
25 |
26 | return this.attribute(
27 | _.d.clone.deep(attribute)
28 | .code(code)
29 | .name(name || code)
30 | .reading()
31 | );
32 | };
33 |
34 | ModelMaker.prototype.o = function (code, attribute) {
35 | var name = _.ld.first(attribute, constants.schema_name);
36 |
37 | if (arguments.length === 1) {
38 | attribute = arguments[0];
39 | code = attribute.code();
40 | }
41 |
42 | return this.attribute(
43 | _.d.clone.deep(attribute)
44 | .code(code)
45 | .name(name || code)
46 | .control()
47 | );
48 | };
49 |
50 | ModelMaker.prototype.io = function (out_code, in_code, attribute) {
51 | if (arguments.length === 1) {
52 | attribute = arguments[0];
53 | out_code = attribute.code();
54 | in_code = out_code;
55 | } else if (arguments.length === 2) {
56 | attribute = arguments[1];
57 | in_code = out_code;
58 | }
59 |
60 | var name = _.ld.first(attribute, constants.schema_name);
61 |
62 | if (out_code === in_code) {
63 | this.attribute(
64 | _.d.clone.deep(attribute)
65 | .code(in_code)
66 | .name(name || in_code)
67 | .reading()
68 | .control()
69 | );
70 | } else {
71 | this.attribute(
72 | _.d.clone.deep(attribute)
73 | .code(in_code)
74 | .name(name || in_code)
75 | .reading()
76 | );
77 | this.attribute(
78 | _.d.clone.deep(attribute)
79 | .code(out_code)
80 | .name(name || out_code)
81 | .control()
82 | );
83 | }
84 |
85 | return this;
86 | };
87 |
--------------------------------------------------------------------------------
/test/instrument/settings/.iotdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dpjanes/node-iotdb/b6f3c26d654245b3493898a1bfd61d6c19aee227/test/instrument/settings/.iotdb
--------------------------------------------------------------------------------
/test/test_bridge.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_bridge.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-02-06
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var bridge = require("../bridge");
15 |
16 | describe('test_bridge', function() {
17 | describe('underlying', function() {
18 | it('constructor', function() {
19 | var b = new bridge.Bridge();
20 |
21 | assert.ok(!b.native);
22 | assert.ok(_.is.Dictionary(b.initd));
23 | assert.ok(_.is.Empty(b.initd));
24 | assert.ok(_.is.Dictionary(b.connectd));
25 |
26 | assert.ok(_.is.Bridge(b));
27 | });
28 | it('data_in', function() {
29 | var paramd = {
30 | rawd: {
31 | a: 1
32 | },
33 | cookd: {
34 | b: 2
35 | },
36 | };
37 |
38 | var b = new bridge.Bridge();
39 | b.connectd.data_in(paramd);
40 |
41 | assert.strictEqual(paramd.cookd.a, 1);
42 | assert.strictEqual(paramd.cookd.b, 2);
43 | assert.strictEqual(paramd.rawd.a, 1);
44 | assert.strictEqual(paramd.rawd.b, undefined);
45 | });
46 | it('data_out', function() {
47 | var paramd = {
48 | rawd: {
49 | a: 1
50 | },
51 | cookd: {
52 | b: 2
53 | },
54 | };
55 |
56 | var b = new bridge.Bridge();
57 | b.connectd.data_out(paramd);
58 |
59 | assert.strictEqual(paramd.rawd.a, 1);
60 | assert.strictEqual(paramd.rawd.b, 2);
61 | assert.strictEqual(paramd.cookd.a, undefined);
62 | assert.strictEqual(paramd.cookd.b, 2);
63 | });
64 | /*
65 | it('name', function() {
66 | var b = new bridge.Bridge();
67 | assert.strictEqual(b.name(), "");
68 | });
69 | */
70 | it('discover', function() {
71 | var b = new bridge.Bridge();
72 | b.discover();
73 | });
74 | it('connect no arguments', function() {
75 | var b = new bridge.Bridge();
76 | assert.throws(function() {
77 | b.connect();
78 | }, Error);
79 | });
80 | it('connect dictionary', function() {
81 | var b = new bridge.Bridge();
82 | b.connect({});
83 | });
84 | it('disconnect', function() {
85 | var b = new bridge.Bridge();
86 | b.disconnect();
87 | });
88 | it('push no arguments', function() {
89 | var b = new bridge.Bridge();
90 | assert.throws(function() {
91 | b.push();
92 | }, Error);
93 | });
94 | it('push dictionary', function() {
95 | var b = new bridge.Bridge();
96 | assert.throws(function() {
97 | b.push({});
98 | }, Error);
99 | });
100 | it('push dictionary + function', function(done) {
101 | var b = new bridge.Bridge();
102 | b.push({}, done);
103 | });
104 | it('pull', function() {
105 | var b = new bridge.Bridge();
106 | b.pull();
107 | });
108 | it('meta', function() {
109 | var b = new bridge.Bridge();
110 | var meta = b.meta();
111 | assert.ok(_.is.Dictionary(meta));
112 | assert.ok(_.is.Empty(meta));
113 | });
114 | it('reachable', function() {
115 | var b = new bridge.Bridge();
116 | var reachable = b.reachable();
117 | assert.ok(reachable);
118 | });
119 | it('configure no arguments', function() {
120 | var b = new bridge.Bridge();
121 | assert.throws(function() {
122 | b.configure();
123 | }, Error);
124 | });
125 | it('configure dictionary', function() {
126 | var b = new bridge.Bridge();
127 | assert.throws(function() {
128 | b.configure({});
129 | }, Error);
130 | });
131 | it('configure express-like object', function() {
132 | var b = new bridge.Bridge();
133 | b.configure({
134 | put: _.noop,
135 | get: _.noop,
136 | });
137 | });
138 | it('discovered', function() {
139 | var b = new bridge.Bridge();
140 | assert.throws(function() {
141 | b.discovered();
142 | }, Error);
143 | });
144 | it('pulled', function() {
145 | var b = new bridge.Bridge();
146 | assert.throws(function() {
147 | b.pulled();
148 | }, Error);
149 | });
150 | });
151 | });
152 |
--------------------------------------------------------------------------------
/test/test_connect_bands.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_connect_bands.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-07-15
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var iotdb = require("../iotdb");
15 | var thing_manager = require("../thing_manager");
16 |
17 | require('./instrument/iotdb');
18 |
19 | var _make_thing = function(callback) {
20 | var t = thing_manager.make();
21 | t.reset();
22 |
23 | var ts = t.connect("Test", {}, {
24 | "schema:name": "The Thing Name",
25 | "schema:description": "My Thing",
26 | "iot:zone": [ "Glasgow Place", "Second Floor", "Bedroom" ],
27 | "iot:facet": [ "iot-facet:switch", "iot-facet:lighting", "iot-facet:something" ],
28 | "iot:thing-number": 32,
29 | });
30 | ts.on("thing", function() {
31 | callback(ts);
32 | });
33 | };
34 |
35 | describe('test_connect_bands', function() {
36 | /*
37 | it('creates thing', function(done) {
38 | _make_thing(function(ts) {
39 | assert.strictEqual(ts.count(), 1);
40 | done();
41 | });
42 | });
43 | */
44 | it('has correct thing-id', function(done) {
45 | _make_thing(function(ts) {
46 | const thing = ts.any();
47 | const id = thing.thing_id();
48 | assert.strictEqual(id, "urn:iotdb:thing:Test:0FAF0A6A-C1AD-413D-8C1B-2EEE3CBA9F0D:10:test");
49 |
50 | done();
51 | });
52 | });
53 | /*
54 | it('has correct model-id', function(done) {
55 | _make_thing(function(ts) {
56 | const thing = ts.any();
57 | const id = thing.model_id();
58 | assert.strictEqual(id, "test");
59 |
60 | done();
61 | });
62 | });
63 | it('has correct model', function(done) {
64 | _make_thing(function(ts) {
65 | const thing = ts.any();
66 | const model = thing.band("model");
67 | const state = model.state();
68 |
69 | assert.ok(_.d.is.superset(state, {
70 | 'schema:name': 'Test',
71 | 'schema:description': 'Test',
72 | 'iot:model-id': 'test',
73 | }));
74 |
75 | done();
76 | });
77 | });
78 | it('has correct meta', function(done) {
79 | _make_thing(function(ts) {
80 | const thing = ts.any();
81 | const meta = thing.band("meta");
82 | const state = meta.state();
83 |
84 | assert.ok(_.d.is.superset(state, {
85 | 'schema:name': 'The Thing Name',
86 | 'schema:description': 'My Thing',
87 | 'iot:model-id': 'test',
88 | 'iot:zone': [ 'Glasgow Place', 'Second Floor', 'Bedroom' ],
89 | 'iot:facet': [
90 | 'iot-facet:switch',
91 | 'iot-facet:lighting',
92 | 'iot-facet:something' ],
93 | 'iot:thing-number': 32
94 | }));
95 |
96 | done();
97 | });
98 | });
99 | */
100 | });
101 |
--------------------------------------------------------------------------------
/test/test_d_transform.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_meta.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2015-03-25
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var ind_1 = {
15 | boolean: true,
16 | integer: 1,
17 | number: 4.4,
18 | string: "Hello, World",
19 | array: [ 1, 2, 3, 4 ],
20 | dictionary: {
21 | a: "b",
22 | }
23 | };
24 |
25 | /* --- tests --- */
26 | describe('test_d_transform:', function(){
27 | it('no transform', function(){
28 | var outd = _.d.transform(ind_1);
29 | assert.ok(_.is.Equal(outd, ind_1));
30 | });
31 | it('uppercase keys', function(){
32 | var outd = _.d.transform(ind_1, {
33 | key: function(key) {
34 | return key.toUpperCase();
35 | },
36 | });
37 | var expectd = { BOOLEAN: true,
38 | INTEGER: 1,
39 | NUMBER: 4.4,
40 | STRING: 'Hello, World',
41 | ARRAY: [ 1, 2, 3, 4 ],
42 | DICTIONARY: { A: 'b' } };
43 | assert.ok(_.is.Equal(outd, expectd));
44 | });
45 | it('keys beginning with a or d', function(){
46 | var outd = _.d.transform(ind_1, {
47 | key: function(key) {
48 | if (key.match(/^[ad]/)) {
49 | return key;
50 | } else {
51 | return undefined;
52 | }
53 | },
54 | });
55 | var expectd = { array: [ 1, 2, 3, 4 ], dictionary: { a: 'b' } };
56 | assert.ok(_.is.Equal(outd, expectd));
57 | });
58 | it('uppercase values', function(){
59 | var outd = _.d.transform(ind_1, {
60 | value: function(value) {
61 | if (_.isString(value)) {
62 | return value.toUpperCase();
63 | } else {
64 | return value;
65 | }
66 | },
67 | });
68 | var expectd = { boolean: true,
69 | integer: 1,
70 | number: 4.4,
71 | string: 'HELLO, WORLD',
72 | array: [ 1, 2, 3, 4 ],
73 | dictionary: { a: 'B' } }
74 | assert.ok(_.is.Equal(outd, expectd));
75 | });
76 | })
77 |
--------------------------------------------------------------------------------
/test/test_exit.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_exit.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-07-13
7 | */
8 |
9 | "use strict";
10 |
11 | const assert = require("assert")
12 | const events = require("events")
13 |
14 | const exit = require("../exit")
15 |
16 | const my_process = () => {
17 | const self = Object.assign({}, events.EventEmitter.prototype);
18 |
19 | self.exit = () => {
20 | self.emit("_EXIT");
21 | };
22 |
23 | self._after = () => {
24 | self.removeAllListeners();
25 | };
26 |
27 | return self;
28 | };
29 |
30 | describe('test_exit', function() {
31 | beforeEach('before', function() {
32 | exit.shims.setProcess(my_process())
33 | });
34 | afterEach('after', function() {
35 | exit.shims.getProcess()._after();
36 | exit.shims.setProcess(process);
37 | });
38 |
39 | describe('setup', function() {
40 | it('with manager', function() {
41 | exit.setup({
42 | disconnect: () => 0,
43 | });
44 | });
45 | });
46 | describe('SIGINT', function() {
47 | it('no delay', function(done) {
48 | let _disconnected = false;
49 |
50 | assert(!exit.shutting_down());
51 | exit.setup({
52 | disconnect: () => {
53 | _disconnected = true;
54 | return 0;
55 | }
56 | });
57 | const _process = exit.shims.getProcess();
58 |
59 | _process.on("_EXIT", () => {
60 | assert(_disconnected);
61 | assert(exit.shutting_down());
62 | done();
63 | });
64 | _process.emit("SIGINT");
65 | });
66 | it('100ms delay', function(done) {
67 | let _disconnected = false;
68 |
69 | assert(!exit.shutting_down());
70 | exit.setup({
71 | disconnect: () => {
72 | _disconnected = true;
73 | return 100;
74 | }
75 | });
76 | const _process = exit.shims.getProcess();
77 |
78 | let _now = new Date().getTime();
79 | _process.on("_EXIT", () => {
80 | assert(_disconnected);
81 | assert(exit.shutting_down());
82 | assert((new Date().getTime() - _now) >= 100);
83 | done();
84 | });
85 | _process.emit("SIGINT");
86 | });
87 | });
88 | });
89 |
--------------------------------------------------------------------------------
/test/test_hash.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_hash.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-01-01
7 | * "The Frickin Future"
8 | */
9 |
10 | "use strict";
11 |
12 | var assert = require("assert")
13 | var _ = require("../helpers")
14 |
15 | describe('test_hash', function() {
16 | describe('md5', function() {
17 | it('empty', function() {
18 | var value = "";
19 | var result = _.hash.md5(value);
20 | var expect = 'd41d8cd98f00b204e9800998ecf8427e';
21 |
22 | assert.strictEqual(result, expect);
23 | });
24 | it('string', function() {
25 | var value = "now is the time for all";
26 | var result = _.hash.md5(value);
27 | var expect = '9748a1abafb2a097bef146f489ab4cd3';
28 |
29 | assert.strictEqual(result, expect);
30 | });
31 | it('complex', function() {
32 | var value = [ "now is the time", "for all" ];
33 | var result = _.hash.md5(value);
34 | var expect = '0bedbd5a12866adaac42deb6b5efc869';
35 |
36 | assert.strictEqual(result, expect);
37 | });
38 | });
39 | describe('sha1', function() {
40 | it('empty', function() {
41 | var value = "";
42 | var result = _.hash.sha1(value);
43 | var expect = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';
44 |
45 | assert.strictEqual(result, expect);
46 | });
47 | it('string', function() {
48 | var value = "now is the time for all";
49 | var result = _.hash.sha1(value);
50 | var expect = '090a137e8c4ec8dc57699f20a13933cbd7620531';
51 |
52 | assert.strictEqual(result, expect);
53 | });
54 | it('complex', function() {
55 | var value = [ "now is the time", "for all" ];
56 | var result = _.hash.sha1(value);
57 | var expect = 'dd247543bd3d9bf8e3d50a6100cfda0b1ba7d8c3';
58 |
59 | assert.strictEqual(result, expect);
60 | });
61 | });
62 | describe('sha256', function() {
63 | it('empty', function() {
64 | var value = "";
65 | var result = _.hash.sha256(value);
66 | var expect = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
67 |
68 | assert.strictEqual(result, expect);
69 | });
70 | it('string', function() {
71 | var value = "now is the time for all";
72 | var result = _.hash.sha256(value);
73 | var expect = 'b52f56d3e60905f4dc70b62f2c78fe7b16f018238c80616ee4f1398f7a1dc96e';
74 |
75 | assert.strictEqual(result, expect);
76 | });
77 | it('complex', function() {
78 | var value = [ "now is the time", "for all" ];
79 | var result = _.hash.sha256(value);
80 | var expect = 'b2e43c30f1ffc388debf6de6563f0a55ca84951fe47951b49b13425626f0d3ed';
81 |
82 | assert.strictEqual(result, expect);
83 | });
84 | });
85 | describe('sha512', function() {
86 | it('empty', function() {
87 | var value = "";
88 | var result = _.hash.sha512(value);
89 | var expect = 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e';
90 |
91 | assert.strictEqual(result, expect);
92 | });
93 | it('string', function() {
94 | var value = "now is the time for all";
95 | var result = _.hash.sha512(value);
96 | var expect = '440f5ee19f4b316c403744673d9c1ad76e1de573a8c7fbde992542b96a65f8ccbfa0b81f86e792a8d2f0eeb9ac23d7d74b9f0e0559e753e9775a8e76199f78d7';
97 |
98 | assert.strictEqual(result, expect);
99 | });
100 | it('complex', function() {
101 | var value = [ "now is the time", "for all" ];
102 | var result = _.hash.sha512(value);
103 | var expect = 'b24102b0ab662614b59060a262ecf1aa4be4486aefe04279e2b2c9c6c9323ef5c1622355a6205a4850d7b9fc2dce102a8c0a1173143b570e5dbab96f16c22c7b';
104 |
105 | assert.strictEqual(result, expect);
106 | });
107 | });
108 | describe('short', function() {
109 | it('empty', function() {
110 | var value = "";
111 | var result = _.hash.short(value);
112 | var expect = '1B2M2Y8A';
113 |
114 | assert.strictEqual(result, expect);
115 | });
116 | it('string', function() {
117 | var value = "now is the time for all";
118 | var result = _.hash.short(value);
119 | var expect = 'l0ihq6-y';
120 |
121 | assert.strictEqual(result, expect);
122 | });
123 | it('complex', function() {
124 | var value = [ "now is the time", "for all" ];
125 | var result = _.hash.short(value);
126 | var expect = 'qOpBe4vs';
127 |
128 | assert.strictEqual(result, expect);
129 | });
130 | });
131 | });
132 |
133 |
--------------------------------------------------------------------------------
/test/test_helpers_identifier.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_helpers_identifier.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2014-01-16
7 | *
8 | * Test indentifier_* functions in helpers
9 | */
10 |
11 | "use strict";
12 |
13 | var assert = require("assert")
14 | var _ = require("../helpers")
15 |
16 | var inputs = [
17 | "UUID",
18 | "MyCamelCaseString",
19 | "my-camel-case-string",
20 | "My_Camel_Case_String",
21 | "AModel",
22 | "A-Model",
23 | "a-model",
24 | "a__model",
25 | "TestID",
26 | "Test_ID",
27 | "Test-ID",
28 | "Good10Good",
29 | "FirmataDHT11"
30 | ]
31 | /* --- tests --- */
32 | describe('test_helpers_identifier:', function(){
33 | it('CamelCase', function(){
34 | var expects = [ 'Uuid',
35 | 'MyCamelCaseString',
36 | 'MyCamelCaseString',
37 | 'MyCamelCaseString',
38 | 'AModel',
39 | 'AModel',
40 | 'AModel',
41 | 'AModel',
42 | 'TestId',
43 | 'TestId',
44 | 'TestId' ,
45 | 'Good10Good',
46 | 'FirmataDht11'
47 | ];
48 | var gots = []
49 | for (var ii in inputs) {
50 | gots.push(_.id.to_camel_case(inputs[ii]))
51 | }
52 | assert.ok(_.is.Equal(expects, gots))
53 | });
54 | it('underscore_case', function(){
55 | var expects = [ 'uuid',
56 | 'my_camel_case_string',
57 | 'my_camel_case_string',
58 | 'my_camel_case_string',
59 | 'a_model',
60 | 'a_model',
61 | 'a_model',
62 | 'a_model',
63 | 'test_id',
64 | 'test_id',
65 | 'test_id' ,
66 | 'good10_good',
67 | 'firmata_dht11'
68 | ];
69 | var gots = []
70 | for (var ii in inputs) {
71 | gots.push(_.id.to_underscore_case(inputs[ii]))
72 | }
73 | assert.ok(_.is.Equal(expects, gots))
74 | });
75 | it('dash-case', function(){
76 | var expects = [ 'uuid',
77 | 'my-camel-case-string',
78 | 'my-camel-case-string',
79 | 'my-camel-case-string',
80 | 'a-model',
81 | 'a-model',
82 | 'a-model',
83 | 'a-model',
84 | 'test-id',
85 | 'test-id',
86 | 'test-id',
87 | 'good10-good',
88 | 'firmata-dht11'
89 | ];
90 | var gots = []
91 | for (var ii in inputs) {
92 | gots.push(_.id.to_dash_case(inputs[ii]))
93 | }
94 | assert.ok(_.is.Equal(expects, gots))
95 |
96 | });
97 | it('illegals', function(){
98 | var bads = [
99 | // illegal characters
100 | " ",
101 | "a thing",
102 | "a$thing",
103 | "a#thing",
104 |
105 | // must have at least one character
106 | "",
107 |
108 | // cannot start with a number, underscore or dash
109 | "1BadString",
110 | "_BadString",
111 | "-BadString",
112 |
113 | // cannot be other objects
114 | true,
115 | false,
116 | 0,
117 | 1,
118 | 3.14,
119 | [],
120 | {}
121 | ]
122 | var fs = [
123 | _.id.to_camel_case,
124 | _.id.to_underscore_case,
125 | _.id.to_dash_case
126 | ]
127 | for (var fi in fs) {
128 | var f = fs[fi];
129 |
130 | for (var bi in bads) {
131 | var b = bads[bi];
132 | assert.throws(function() {
133 | f(b);
134 | }, Error)
135 | }
136 | }
137 | });
138 | })
139 |
--------------------------------------------------------------------------------
/test/test_id.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_id.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2015-12-29
7 | * "45th anniversary of Apollo 13 explosion"
8 | */
9 |
10 | "use strict";
11 |
12 | var assert = require("assert")
13 | var _ = require("../helpers")
14 |
15 | /* --- tests --- */
16 | describe('test_id', function(){
17 | describe('slugify', function(){
18 | it('blank', function() {
19 | var src = "";
20 | var expected = "";
21 | var slugged = _.id.slugify(src);
22 | assert.equal(expected, slugged);
23 | });
24 | it('lower', function() {
25 | var src = "abcdefghijklmnopqrstuvwxyz";
26 | var expected = "abcdefghijklmnopqrstuvwxyz";
27 | var slugged = _.id.slugify(src);
28 | assert.equal(expected, slugged);
29 | });
30 | it('upper', function() {
31 | var src = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
32 | var expected = "abcdefghijklmnopqrstuvwxyz";
33 | var slugged = _.id.slugify(src);
34 | assert.equal(expected, slugged);
35 | });
36 | it('numbers', function() {
37 | var src = "01234567890";
38 | var expected = "01234567890";
39 | var slugged = _.id.slugify(src);
40 | assert.equal(expected, slugged);
41 | });
42 | it('other', function() {
43 | var src = "!@#$%^&*()_+-=";
44 | var expected = "_";
45 | var slugged = _.id.slugify(src);
46 | assert.equal(expected, slugged);
47 | });
48 | it('phrase', function() {
49 | var src = "Now Is The Time For All Good Men 0 1 2";
50 | var expected = "now_is_the_time_for_all_good_men_0_1_2";
51 | var slugged = _.id.slugify(src);
52 | assert.equal(expected, slugged);
53 | });
54 | });
55 | describe('identifier', function(){
56 | it('WeMoSwitch', function() {
57 | var src = "WeMoSwitch";
58 | assert.equal(_.id.to_camel_case(src), "WeMoSwitch");
59 | assert.equal(_.id.to_dash_case(src), "we-mo-switch");
60 | assert.equal(_.id.to_underscore_case(src), "we_mo_switch");
61 | });
62 | it('RESTLight', function() {
63 | var src = "RESTLight";
64 | assert.equal(_.id.to_camel_case(src), "RestLight");
65 | assert.equal(_.id.to_dash_case(src), "rest-light");
66 | assert.equal(_.id.to_underscore_case(src), "rest_light");
67 | });
68 | it('C99', function() {
69 | var src = "C99";
70 | assert.equal(_.id.to_camel_case(src), "C99");
71 | assert.equal(_.id.to_dash_case(src), "c99");
72 | assert.equal(_.id.to_underscore_case(src), "c99");
73 | });
74 | it('COAP99', function() {
75 | var src = "COAP99";
76 | assert.equal(_.id.to_camel_case(src), "Coap99");
77 | assert.equal(_.id.to_dash_case(src), "coap99");
78 | assert.equal(_.id.to_underscore_case(src), "coap99");
79 | });
80 | it('COAP99Light', function() {
81 | var src = "COAP99Light";
82 | assert.equal(_.id.to_camel_case(src), "Coap99Light");
83 | assert.equal(_.id.to_dash_case(src), "coap99-light");
84 | assert.equal(_.id.to_underscore_case(src), "coap99_light");
85 | });
86 | });
87 | });
88 |
--------------------------------------------------------------------------------
/test/test_id_thing_urn.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_id_thing_urn.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-01-16
7 | * "Augustus becomes the first Roman Emperor (27 BC)"
8 | */
9 |
10 | "use strict";
11 |
12 | var assert = require("assert")
13 | const iotdb = require("../iotdb");
14 | const _ = require("../helpers");
15 |
16 | describe('test_id_thing_urn', function(){
17 | beforeEach(function() {
18 | iotdb.shims.settings(() => ({
19 | get: ( key, otherwise ) => {
20 | if (key === "/machine_id") {
21 | return "UNIQUE-MACHINE-ID";
22 | } else if (key === "/homestar/runner/keys/homestar/key") {
23 | return "HOMESTAR-ID";
24 | } else {
25 | return otherwise;
26 | }
27 | }
28 | }));
29 | });
30 | afterEach(function() {
31 | iotdb.shims.settings();
32 | });
33 | it('machine_id', function(){
34 | var response = _.id.machine_id();
35 | var expected = "UNIQUE-MACHINE-ID";
36 |
37 | assert.strictEqual(response, expected);
38 | });
39 | describe('test_urn', function(){
40 | describe('unique', function(){
41 | it('empty request', function(done){
42 | var response = _.id.thing_urn.unique();
43 | var expected = "urn:iotdb:thing";
44 |
45 | assert.strictEqual(response, expected);
46 | done();
47 | });
48 | it('three string + number', function(done){
49 | var response = _.id.thing_urn.unique("MyThing", "Something", "Else", 42);
50 | var expected = "urn:iotdb:thing:MyThing:Something:Else:42";
51 |
52 | assert.strictEqual(response, expected);
53 | done();
54 | });
55 | });
56 | describe('unique_hash', function(){
57 | it('empty request', function(done){
58 | var response = _.id.thing_urn.unique_hash();
59 | var expected = "urn:iotdb:thing:d41d8cd98f00b204e9800998ecf8427e";
60 |
61 | assert.strictEqual(response, expected);
62 | done();
63 | });
64 | it('three string + number', function(done){
65 | var response = _.id.thing_urn.unique_hash("MyThing", "Something", "Else", 42);
66 | var expected = "urn:iotdb:thing:MyThing:Something:Else:a1d0c6e83f027327d8461063f4ac58a6";
67 |
68 | assert.strictEqual(response, expected);
69 | done();
70 | });
71 | it('three strings', function(done){
72 | var response = _.id.thing_urn.unique_hash("MyThing", "Something", "Else");
73 | var expected = "urn:iotdb:thing:MyThing:Something:6a0053231db40a4539b8f783a719a54a";
74 |
75 | assert.strictEqual(response, expected);
76 | done();
77 | });
78 | });
79 | describe('machine_unique', function(){
80 | it('empty request', function(done){
81 | var response = _.id.thing_urn.machine_unique();
82 | var expected = 'urn:iotdb:thing:98975ddc296ccc277a7f1d99545fa48e'
83 | assert.strictEqual(response, expected);
84 | done();
85 | });
86 | it('three string + number', function(done){
87 | var response = _.id.thing_urn.machine_unique("MyThing", "Something", "Else", 42);
88 | var expected = 'urn:iotdb:thing:MyThing:Something:Else:42:41b4c34e7f7ce88dbc5e05eb1a4f5a3c'
89 |
90 | assert.strictEqual(response, expected);
91 | done();
92 | });
93 | it('three strings', function(done){
94 | var response = _.id.thing_urn.machine_unique("MyThing", "Something", "Else");
95 | var expected = 'urn:iotdb:thing:MyThing:Something:Else:24dc5487031655485b33176ec15a57aa'
96 |
97 | assert.strictEqual(response, expected);
98 | done();
99 | });
100 | });
101 | });
102 | });
103 |
--------------------------------------------------------------------------------
/test/test_id_user.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_id_user.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2015-04-13
7 | * "45th anniversary of Apollo 13 explosion"
8 | */
9 |
10 | "use strict";
11 |
12 | var assert = require("assert")
13 | var _ = require("../helpers")
14 |
15 | /* --- tests --- */
16 | describe('test_id_user:', function(){
17 | it('user - http', function(){
18 | var expect = "urn:iotdb:user:a7886bb5b04908d8dac45c7eee0476a2";
19 | var urls = [
20 | "http://twitter.com/dpjanes",
21 | "http://TWITTER.com/dpjanes",
22 | "http://TWITTER.COM/dpjanes",
23 | ];
24 | for (var ui in urls) {
25 | var url = urls[ui];
26 | assert.strictEqual(_.id.user_urn(url), expect);
27 | }
28 | });
29 | it('user - http:80', function(){
30 | var expect = "urn:iotdb:user:a7886bb5b04908d8dac45c7eee0476a2";
31 | var urls = [
32 | "http://twitter.com:80/dpjanes",
33 | "http://TWITTER.com:80/dpjanes",
34 | "http://TWITTER.COM:80/dpjanes",
35 | ];
36 | for (var ui in urls) {
37 | var url = urls[ui];
38 | assert.strictEqual(_.id.user_urn(url), expect);
39 | }
40 | });
41 | it('user - http:8080', function(){
42 | var expect = 'urn:iotdb:user:15590253c645062ee3815097ab4413c6';
43 | var urls = [
44 | "http://twitter.com:8080/dpjanes",
45 | "http://TWITTER.com:8080/dpjanes",
46 | "http://TWITTER.COM:8080/dpjanes",
47 | ];
48 | for (var ui in urls) {
49 | var url = urls[ui];
50 | assert.strictEqual(_.id.user_urn(url), expect);
51 | }
52 | });
53 | it('user - https', function(){
54 | var expect = "urn:iotdb:user:aa65797af2ad590e069f40bf28fe66b3";
55 | var urls = [
56 | "https://homestar.org/abcdef0123456789",
57 | "https://HOMESTAR.org/abcdef0123456789",
58 | "https://HOMESTAR.ORG/abcdef0123456789",
59 | ];
60 | for (var ui in urls) {
61 | var url = urls[ui];
62 | assert.strictEqual(_.id.user_urn(url), expect);
63 | }
64 | });
65 | it('user - https:443', function(){
66 | var expect = "urn:iotdb:user:aa65797af2ad590e069f40bf28fe66b3";
67 | var urls = [
68 | "https://homestar.org:443/abcdef0123456789",
69 | "https://HOMESTAR.org:443/abcdef0123456789",
70 | "https://HOMESTAR.ORG:443/abcdef0123456789",
71 | ];
72 | for (var ui in urls) {
73 | var url = urls[ui];
74 | assert.strictEqual(_.id.user_urn(url), expect);
75 | }
76 | });
77 | it('user - https:44380', function(){
78 | var expect = 'urn:iotdb:user:ad2ec15826dd009fcd9bfe538fdbc305';
79 | var urls = [
80 | "https://homestar.org:44380/abcdef0123456789",
81 | "https://HOMESTAR.org:44380/abcdef0123456789",
82 | "https://HOMESTAR.ORG:44380/abcdef0123456789",
83 | ];
84 | for (var ui in urls) {
85 | var url = urls[ui];
86 | assert.strictEqual(_.id.user_urn(url), expect);
87 | }
88 | });
89 | })
90 |
--------------------------------------------------------------------------------
/test/test_iotdb.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_iotdb.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-02-03
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var iotdb = require("../iotdb");
15 |
16 | require('./instrument/iotdb');
17 |
18 | describe('test_iotdb', function() {
19 | describe('constructor', function() {
20 | it('global', function() {
21 | assert.ok(iotdb.iot());
22 | });
23 | it('global returns same object', function() {
24 | assert.strictEqual(iotdb.iot(), iotdb.iot());
25 | });
26 | });
27 | });
28 |
--------------------------------------------------------------------------------
/test/test_iotdb_connect.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_iotdb_connect.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-02-03
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var iotdb = require("../iotdb");
15 |
16 | require('./instrument/iotdb');
17 |
18 | describe('test_connect', function() {
19 | describe('connect', function() {
20 | describe('globals', function() {
21 | it('no arguments', function() {
22 | iotdb.shims.reset();
23 | iotdb.instance = null;
24 | var things = iotdb.connect();
25 |
26 | assert.strictEqual(things.count(), 0);
27 | });
28 | it('valid model code argument', function(done) {
29 | iotdb.shims.reset();
30 | iotdb.instance = null;
31 | var things = iotdb.connect("Test");
32 |
33 | things.on("thing", function() {
34 | assert.strictEqual(things.count(), 1);
35 | done();
36 | });
37 | });
38 | it('invalid model code argument', function() {
39 | iotdb.shims.reset();
40 | iotdb.instance = null;
41 | var things = iotdb.connect("NotATest");
42 |
43 | assert.strictEqual(things.count(), 0);
44 | });
45 | });
46 | describe('clean setup', function() {
47 | it('no arguments', function() {
48 | iotdb.shims.reset();
49 | var iot = iotdb.iot()
50 | var things = iot.connect();
51 |
52 | assert.strictEqual(things.count(), 0);
53 | });
54 | it('valid model code argument', function(done) {
55 | iotdb.shims.reset();
56 | var iot = iotdb.iot()
57 | var things = iot.connect("Test");
58 | console.log(things);
59 |
60 | things.on("thing", function() {
61 | assert.strictEqual(things.count(), 1);
62 | done();
63 | });
64 | });
65 | it('invalid model code argument', function() {
66 | iotdb.shims.reset();
67 | var iot = iotdb.iot()
68 | var things = iot.connect("NotATest");
69 |
70 | assert.strictEqual(things.count(), 0);
71 | });
72 | });
73 | });
74 | });
75 |
--------------------------------------------------------------------------------
/test/test_iotdb_id.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_iotdb_id.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-07-15
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var iotdb = require("../iotdb");
15 | var settings = require("../settings");
16 |
17 | describe('test_iotdb_id', function() {
18 | describe('returns /machine_id', function() {
19 | let ok;
20 | beforeEach(function() {
21 | iotdb.shims.settings(() => ({
22 | get: ( key, otherwise ) => {
23 | if (key === "/machine_id") {
24 | return "first";
25 | } else {
26 | return otherwise;
27 | }
28 | }
29 | }));
30 | });
31 | afterEach(function() {
32 | iotdb.shims.settings();
33 | });
34 | it('returns first', function() {
35 | const metad = iotdb.controller_meta()
36 | assert.strictEqual(metad["iot:runner.id"], "first");
37 | });
38 | });
39 | /*
40 | describe('returns second', function() {
41 | let ok;
42 | beforeEach(function() {
43 | ok = iotdb.shims.settings(() => ({
44 | get: ( key, otherwise ) => {
45 | if (key === "/homestar/runner/keys/homestar/key") {
46 | return otherwise;
47 | } else if (key === "/machine_id") {
48 | return "second";
49 | } else {
50 | return otherwise;
51 | }
52 | }
53 | }));
54 | });
55 | afterEach(function() {
56 | iotdb.shims.settings(ok);
57 | });
58 | it('returns second', function() {
59 | const metad = iotdb.controller_meta()
60 | assert.strictEqual(metad["iot:runner.id"], "second");
61 | });
62 | });
63 | */
64 | it('has timestamp', function() {
65 | const metad = iotdb.controller_meta()
66 | const timestamp = metad["iot:runner.timestamp"];
67 |
68 | assert.ok(timestamp <= _.timestamp.make());
69 | assert.ok(_.is.Timestamp(timestamp));
70 | });
71 | });
72 |
--------------------------------------------------------------------------------
/test/test_iotdb_things.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_iotdb_things.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-02-03
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var iotdb = require("../iotdb");
15 |
16 | require('./instrument/iotdb');
17 |
18 | describe('test_iotdb_things', function() {
19 | describe('things', function() {
20 | describe('global', function() {
21 | it('no arguments', function() {
22 | iotdb.shims.reset();
23 | var things = iotdb.things();
24 |
25 | assert.strictEqual(things.count(), 0);
26 | });
27 | /*
28 | it('valid model code argument', function() {
29 | iotdb.instance = null;
30 | var things = iotdb.things("Test");
31 |
32 | assert.strictEqual(things.count(), 0);
33 | });
34 | it('invalid model code argument', function() {
35 | iotdb.instance = null;
36 | var things = iotdb.things("NotATest");
37 |
38 | assert.strictEqual(things.count(), 0);
39 | });
40 | */
41 | });
42 | describe('clean setup', function() {
43 | it('no arguments', function() {
44 | iotdb.shims.reset();
45 | var iot = iotdb.iot()
46 | var things = iot.things();
47 |
48 | assert.strictEqual(things.count(), 0);
49 | });
50 | /*
51 | it('valid model code argument', function() {
52 | var iot = iotdb.iot()
53 | var things = iot.things("Test");
54 |
55 | assert.strictEqual(things.count(), 0);
56 | });
57 | it('invalid model code argument', function() {
58 | var iot = iotdb.iot()
59 | var things = iot.things("NotATest");
60 |
61 | assert.strictEqual(things.count(), 0);
62 | });
63 | */
64 | });
65 | describe('setup with Thing existing', function() {
66 | it('connected', function(done) {
67 | iotdb.shims.reset();
68 | var iot = iotdb.iot()
69 |
70 | var ts = iot.connect("Test");
71 | ts.on("thing", function() {
72 | assert.strictEqual(iot.things().count(), 1);
73 | // assert.strictEqual(iot.things("Test").count(), 1);
74 | // assert.strictEqual(iot.things("NotATest").count(), 0);
75 | done();
76 | });
77 | });
78 | it('invalid', function(done) {
79 | iotdb.shims.reset();
80 | var iot = iotdb.iot()
81 |
82 | var ts = iot.connect("NotATest");
83 | setTimeout(function() {
84 | assert.strictEqual(iot.things().count(), 0);
85 | // assert.strictEqual(iot.things("Test").count(), 0);
86 | // assert.strictEqual(iot.things("NotATest").count(), 0);
87 | done();
88 | }, 250);
89 | });
90 | });
91 | });
92 | });
93 |
--------------------------------------------------------------------------------
/test/test_ld.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_ld.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2015-04-24
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | /* --- tests --- */
15 | describe('test_ld', function() {
16 | });
17 |
--------------------------------------------------------------------------------
/test/test_ld_extend.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_ld_extend.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-02-01
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | /* --- tests --- */
15 | describe('test_ld_extend', function() {
16 | describe('expand', function() {
17 | describe('string', function() {
18 | it('simple with iot namespace', function() {
19 | var src = "iot:value";
20 | var expanded = _.ld.expand(src);
21 | var expected = "https://iotdb.org/pub/iot#value"
22 |
23 | assert.strictEqual(expanded, expected);
24 | });
25 | it('no namespace', function() {
26 | var src = "value";
27 | var expanded = _.ld.expand(src);
28 | var expected = "value";
29 |
30 | assert.strictEqual(expanded, expected);
31 | });
32 | it('no namespace but with colon', function() {
33 | var src = ":value";
34 | var expanded = _.ld.expand(src);
35 | var expected = ":value";
36 |
37 | assert.strictEqual(expanded, expected);
38 | });
39 | it('no namespace, string default', function() {
40 | var src = "value";
41 | var expanded = _.ld.expand(src, "iot:");
42 | var expected = "https://iotdb.org/pub/iot#value"
43 |
44 | assert.strictEqual(expanded, expected);
45 | });
46 | it('no namespace but with colon, string default', function() {
47 | var src = ":value";
48 | var expanded = _.ld.expand(src, "iot:");
49 | var expected = "https://iotdb.org/pub/iot#value"
50 |
51 | assert.strictEqual(expanded, expected);
52 | });
53 | it('with namespace, string default (expect to be ignorned)', function() {
54 | var src = "iot-unit:value";
55 | var expanded = _.ld.expand(src, "iot:");
56 | var expected = "https://iotdb.org/pub/iot-unit#value"
57 |
58 | assert.strictEqual(expanded, expected);
59 | });
60 | });
61 | });
62 | });
63 |
--------------------------------------------------------------------------------
/test/test_ld_first.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_ld_first.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-01-02
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | /* --- tests --- */
15 | describe('test_ld', function() {
16 | describe('first', function() {
17 | describe('no dictionary', function() {
18 | it('undefined', function() {
19 | var d = undefined;
20 | var key = "something";
21 | var expect = "otherwise";
22 | var otherwise = "otherwise";
23 | var result = _.ld.first(d, key, otherwise);
24 |
25 | assert.strictEqual(result, expect);
26 | });
27 | it('null', function() {
28 | var d = null;
29 | var key = "something";
30 | var expect = "otherwise";
31 | var otherwise = "otherwise";
32 | var result = _.ld.first(d, key, otherwise);
33 |
34 | assert.strictEqual(result, expect);
35 | });
36 | it('number', function() {
37 | var d = 1;
38 | var key = "something";
39 | var expect = "otherwise";
40 | var otherwise = "otherwise";
41 |
42 | assert.throws(function() {
43 | _.ld.first(d, key, otherwise);
44 | }, Error);
45 | });
46 | });
47 | describe('missing', function() {
48 | it('missing', function() {
49 | var d = {};
50 | var key = "something";
51 | var expect = undefined;
52 | var otherwise = undefined;
53 | var result = _.ld.first(d, key, otherwise);
54 |
55 | assert.strictEqual(result, expect);
56 | });
57 | it('missing with null default', function() {
58 | var d = {};
59 | var key = "something";
60 | var expect = null;
61 | var otherwise = null;
62 | var result = _.ld.first(d, key, otherwise);
63 |
64 | assert.strictEqual(result, expect);
65 | });
66 | it('missing with string default', function() {
67 | var d = {};
68 | var key = "something";
69 | var expect = "else";
70 | var otherwise = "else";
71 | var result = _.ld.first(d, key, otherwise);
72 |
73 | assert.strictEqual(result, expect);
74 | });
75 | });
76 | describe('single value', function() {
77 | it('string', function() {
78 | var d = {
79 | something: "a",
80 | };
81 | var key = "something";
82 | var expect = "a";
83 | var otherwise = null;
84 | var result = _.ld.first(d, key, otherwise);
85 |
86 | assert.strictEqual(result, expect);
87 | });
88 | it('number', function() {
89 | var d = {
90 | something: 123,
91 | };
92 | var key = "something";
93 | var expect = 123;
94 | var otherwise = null;
95 | var result = _.ld.first(d, key, otherwise);
96 |
97 | assert.strictEqual(result, expect);
98 | });
99 | it('dictionary', function() {
100 | var d = {
101 | something: { a: 1 },
102 | };
103 | var key = "something";
104 | var expect = { a: 1 };
105 | var otherwise = null;
106 | var result = _.ld.first(d, key, otherwise);
107 |
108 | assert.ok(_.is.Equal(result, expect));
109 | });
110 | });
111 | describe('multi value', function() {
112 | it('string', function() {
113 | var d = {
114 | something: [ "a", "b", ],
115 | };
116 | var key = "something";
117 | var expect = "a";
118 | var otherwise = null;
119 | var result = _.ld.first(d, key, otherwise);
120 |
121 | assert.strictEqual(result, expect);
122 | });
123 | it('number', function() {
124 | var d = {
125 | something: [ 123, 456 ],
126 | };
127 | var key = "something";
128 | var expect = 123;
129 | var otherwise = null;
130 | var result = _.ld.first(d, key, otherwise);
131 |
132 | assert.strictEqual(result, expect);
133 | });
134 | });
135 | });
136 | })
137 |
--------------------------------------------------------------------------------
/test/test_net.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_net.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-01-01
7 | * "The Frickin Future"
8 | */
9 |
10 | "use strict";
11 |
12 | var assert = require("assert")
13 | var _ = require("../helpers")
14 |
15 | describe('test_net', function() {
16 | describe('ipv4', function() {
17 | it('default', function() {
18 | var result = _.net.ipv4();
19 | var expect_rex = /^\d{1,3}[.]\d{1,3}[.]\d{1,3}[.]\d{1,3}$/;
20 |
21 | assert.ok(result.match(expect_rex));
22 | });
23 | });
24 | describe('ipv6', function() {
25 | it('default', function() {
26 | var result = _.net.ipv6();
27 | var expect_rex = /^[a-z0-9:]*$/;
28 |
29 | assert.ok(result.match(expect_rex));
30 | });
31 | });
32 | describe('mac', function() {
33 | it('default', function() {
34 | var result = _.net.mac();
35 | var expect_rex = /^([a-f0-9][a-f0-9]:){5}([a-f0-9][a-f0-9])$/;
36 |
37 | assert.ok(result.match(expect_rex));
38 | });
39 | });
40 | });
41 |
--------------------------------------------------------------------------------
/test/test_queue.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_queue.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-01-17
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | describe('test_queue', function() {
15 | describe('constructor', function() {
16 | it('no arguments', function() {
17 | var queue = new _.q.Queue();
18 |
19 | assert.strictEqual(queue.name, "unnamed-queue");
20 | assert.strictEqual(queue.qn, 1);
21 | });
22 | it('with name', function() {
23 | var queue = new _.q.Queue("my-queue");
24 |
25 | assert.strictEqual(queue.name, "my-queue");
26 | assert.strictEqual(queue.qn, 1);
27 | });
28 | it('with name and paramd', function() {
29 | var queue = new _.q.Queue("my-queue", {
30 | qn: 4,
31 | });
32 |
33 | assert.strictEqual(queue.name, "my-queue");
34 | assert.strictEqual(queue.qn, 4);
35 | });
36 | });
37 | describe('add', function() {
38 | it('simple', function(done) {
39 | var queue = new _.q.Queue();
40 | queue.add({
41 | run: function(_queue, _qitem) {
42 | _queue.finished(_qitem);
43 | done();
44 | },
45 | });
46 | });
47 | it('simple with coda', function(done) {
48 | var queue = new _.q.Queue();
49 | queue.add({
50 | run: function(_queue, _qitem) {
51 | _queue.finished(_qitem);
52 | },
53 | coda: function() {
54 | done();
55 | },
56 | });
57 | });
58 | it('simple with coda and exception', function(done) {
59 | var queue = new _.q.Queue();
60 | queue.add({
61 | run: function(_queue, _qitem) {
62 | throw new Error("coda should still get called");
63 | },
64 | coda: function() {
65 | done();
66 | },
67 | });
68 | });
69 | it('multiples', function(done) {
70 | var queue = new _.q.Queue();
71 | var ran_first = false;
72 | var ran_second = false;
73 | queue.add({
74 | run: function(_queue, _qitem) {
75 | assert.ok(!ran_first);
76 | assert.ok(!ran_second);
77 |
78 | ran_first = true;
79 | _queue.finished(_qitem);
80 | },
81 | });
82 | queue.add({
83 | run: function(_queue, _qitem) {
84 | assert.ok(ran_first);
85 | assert.ok(!ran_second);
86 |
87 | ran_second = true;
88 | _queue.finished(_qitem);
89 | },
90 | coda: function() {
91 | assert.ok(ran_first);
92 | assert.ok(ran_second);
93 |
94 | done();
95 | },
96 | });
97 | });
98 | it('multiples with same id', function(done) {
99 | var queue = new _.q.Queue();
100 | queue.pause();
101 |
102 | var ran_first = false;
103 | var ran_first_coda = false;
104 | var ran_second = false;
105 | queue.add({
106 | id: "shared",
107 | run: function(_queue, _qitem) {
108 | // this will actually never run
109 | assert.ok(false);
110 |
111 | ran_first = true;
112 | _queue.finished(_qitem);
113 | },
114 | coda: function() {
115 | // but this will when it's bumped
116 | ran_first_coda = true;
117 | },
118 | });
119 | queue.add({
120 | id: "shared",
121 | run: function(_queue, _qitem) {
122 | assert.ok(!ran_first);
123 | assert.ok(ran_first_coda);
124 | assert.ok(!ran_second);
125 |
126 | ran_second = true;
127 | _queue.finished(_qitem);
128 | },
129 | coda: function() {
130 | assert.ok(!ran_first);
131 | assert.ok(ran_first_coda);
132 | assert.ok(ran_second);
133 |
134 | done();
135 | },
136 | });
137 |
138 | queue.resume();
139 | });
140 |
141 | });
142 | })
143 |
--------------------------------------------------------------------------------
/test/test_reset.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_reset.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-09-08
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var iotdb = require("../iotdb");
15 | var modules = require("../modules");
16 | var settings = require("../settings");
17 | var thing_manager = require("../thing_manager");
18 | var bridge = require("../bridge");
19 |
20 | require('./instrument/iotdb');
21 |
22 | describe('test_reset', function() {
23 | describe('iotdb', function() {
24 | it("exists", function() {
25 | iotdb.reset();
26 | });
27 | it("it will create a new object", function() {
28 | const iot_1 = iotdb.iot();
29 | iot_1.__A = 1
30 |
31 | iotdb.reset();
32 |
33 | const iot_2 = iotdb.iot();
34 |
35 | assert.ok(iot_1.__A);
36 | assert.ok(!iot_2.__A);
37 | });
38 | it("edge case if statement", function() {
39 | iotdb.reset();
40 | iotdb.reset();
41 | });
42 | });
43 | describe("modules", function() {
44 | it("exists", function() {
45 | modules.reset();
46 | });
47 | it("it will create new object", function() {
48 | const m_1 = modules.instance();
49 | m_1.__A = 1;
50 |
51 | modules.reset();
52 |
53 | const m_2 = modules.instance();
54 |
55 | assert.ok(m_1.__A);
56 | assert.ok(!m_2.__A);
57 |
58 | });
59 | });
60 | describe("bridge", function() {
61 | it("exists", function() {
62 | const b = new bridge.Bridge();
63 | b.reset();
64 | });
65 | });
66 | describe("thing_manager", function() {
67 | it("exists", function() {
68 | const tm = thing_manager.make();
69 | tm.reset();
70 | });
71 |
72 | it("actually resets", function(done) {
73 | const tm = thing_manager.make();
74 | tm.connect("Test");
75 | tm.on("thing", function() {
76 | assert.ok(tm.things().count());
77 | tm.reset();
78 | assert.strictEqual(tm.things().count(), 0);
79 | done();
80 | });
81 | });
82 |
83 | it("resets bridge", function(done) {
84 | const tm = thing_manager.make();
85 | tm.connect("Test");
86 | tm.on("thing", function() {
87 | assert.ok(tm.things().count());
88 | const thing = tm.things().any();
89 | assert.ok(thing);
90 | assert.ok(thing.__bridge);
91 |
92 | const bridge = thing.__bridge;
93 | assert.ok(bridge);
94 |
95 | bridge._reset_reset();
96 | assert.strictEqual(bridge._reset_count(), 0);
97 |
98 | tm.reset();
99 | assert.ok(bridge.__reset);
100 | assert.strictEqual(bridge._reset_count(), 2); // exemplar + instance
101 |
102 | done();
103 | });
104 | });
105 | });
106 | describe("settings", function() {
107 | it("exists", function() {
108 | settings.reset();
109 | });
110 | it("it will create new object", function() {
111 | const s_1 = settings.instance();
112 | s_1.__A = 1;
113 |
114 | settings.reset();
115 |
116 | const s_2 = settings.instance();
117 |
118 | assert.ok(s_1.__A);
119 | assert.ok(!s_2.__A);
120 |
121 | });
122 | it("nothing sticks around", function() {
123 | const s_1 = settings.instance();
124 | s_1.set("/a/b", 1);
125 |
126 | settings.reset();
127 |
128 | const s_2 = settings.instance();
129 |
130 | assert.ok(s_1.get("/a/b"));
131 | assert.ok(!s_2.get("/a/b"));
132 |
133 | });
134 | });
135 | });
136 |
--------------------------------------------------------------------------------
/test/test_settings.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_settings.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-06-19
7 | */
8 |
9 | "use strict";
10 |
11 | const assert = require("assert")
12 | const fs = require('fs');
13 | const path = require('path');
14 |
15 | const iotdb = require("../iotdb");
16 | const _ = require("../helpers");
17 | const settings = require("../settings");
18 |
19 | describe('test_settings', function() {
20 | describe('paths', function() {
21 | let cwd;
22 | beforeEach(function() {
23 | cwd = process.cwd();
24 | process.chdir(path.join(__dirname, "instrument", "settings"));
25 | });
26 | afterEach(function() {
27 | process.chdir(cwd);
28 | });
29 | it('paths', function() {
30 | const paths = settings.shims.paths();
31 | assert.ok(_.is.Array(paths));
32 |
33 | paths
34 | .map(path => fs.statSync(path))
35 | .forEach(stbuf => assert.ok(stbuf.isDirectory()));
36 | });
37 | });
38 | describe('set', function() {
39 | it('initial state', function() {
40 | const s = settings.make();
41 | s.d = {};
42 |
43 | assert.deepEqual(s.get("/value", null), null);
44 | });
45 | it('changes value', function() {
46 | const s = settings.make();
47 | s.d = {};
48 |
49 | s.set("/value", 123);
50 |
51 | assert.deepEqual(s.get("/value", null), 123);
52 | });
53 | it('deep value', function() {
54 | const s = settings.make();
55 | s.d = {};
56 |
57 | s.set("/deep/value", 456);
58 |
59 | assert.deepEqual(s.get("/deep/value", null), 456);
60 | assert.deepEqual(s.get("/deep", null), { value: 456 });
61 | });
62 | it('emits', function() {
63 | const s = settings.make();
64 | s.d = {};
65 |
66 | s.set("/value", 123);
67 | s.on("changed", key => {
68 | assert.deepEqual(key, "/value");
69 | });
70 | });
71 | });
72 | describe('instance', function() {
73 | beforeEach(function() {
74 | iotdb.shims.settings(settings.instance);
75 | });
76 | afterEach(function() {
77 | iotdb.shims.settings();
78 | });
79 |
80 | it('module', function() {
81 | const s1 = settings.instance();
82 | const s2 = settings.instance();
83 |
84 | assert.ok(s1);
85 | assert.strictEqual(s1, s2);
86 | });
87 | it('iotdb', function() {
88 | const s1 = iotdb.settings();
89 | const s2 = settings.instance();
90 |
91 | assert.ok(s1);
92 | assert.strictEqual(s1, s2);
93 | });
94 | it('iotdb / legacy', function() {
95 | const s1 = iotdb.keystore();
96 | const s2 = settings.instance();
97 |
98 | assert.ok(s1);
99 | assert.strictEqual(s1, s2);
100 | });
101 | });
102 | });
103 | // iotdb.shims.settings(() => {
104 |
--------------------------------------------------------------------------------
/test/test_settings_set.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_settings_set.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-09-08
7 | */
8 |
9 | "use strict";
10 |
11 | const assert = require("assert")
12 | const fs = require('fs');
13 | const path = require('path');
14 |
15 | const iotdb = require("../iotdb");
16 | const _ = require("../helpers");
17 | const settings = require("../settings");
18 |
19 | describe('test_settings', function() {
20 | describe('save', function() {
21 | let _filename = null;
22 | let _data = null;
23 | let _cwd = null;
24 |
25 | beforeEach(function() {
26 | _cwd = process.cwd();
27 | process.chdir(path.join(__dirname, "instrument", "settings"));
28 |
29 | settings.shims.writeFileSync((filename, data) => {
30 | _filename = filename;
31 | _data = data;
32 | });
33 | });
34 | afterEach(function() {
35 | process.chdir(_cwd);
36 | settings.shims.writeFileSync();
37 | _filename = null;
38 | _data = null;
39 | });
40 |
41 | it("exists", function(done) {
42 | settings.reset();
43 | const s = settings.instance();
44 | s.save("save", "b");
45 | process.nextTick(() => done());
46 | })
47 | it("correct value", function(done) {
48 | settings.reset();
49 | const s = settings.instance();
50 | assert.ok(!s.get("save"));
51 |
52 | s.save("save", "b");
53 | process.nextTick(() => {
54 | assert.deepEqual(JSON.parse(_data), { "save": "b" });
55 | done();
56 | });
57 | })
58 | it("staged on next tick", function(done) {
59 | settings.reset();
60 | const s = settings.instance();
61 | assert.ok(!s.get("save"));
62 |
63 | s.save("save", "b");
64 | s.save("bla", "c");
65 | process.nextTick(() => {
66 | assert.deepEqual(JSON.parse(_data), { "save": "b", "bla": "c" });
67 | done();
68 | });
69 | })
70 | });
71 | });
72 |
--------------------------------------------------------------------------------
/test/test_temperature.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_d_temperature.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2015-12-31
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 |
15 | /* --- tests --- */
16 | /*
17 | describe('test_temperature', function(){
18 | describe('c->f', function(){
19 | it('-40', function() {
20 | var c = -40;
21 | var f = -40;
22 | var r = _.temperature.c2f(c);
23 | assert.strictEqual(f, r);
24 | });
25 | it('0', function() {
26 | var c = 0;
27 | var f = 32;
28 | var r = _.temperature.c2f(c);
29 | assert.strictEqual(f, r);
30 | });
31 | it('20', function() {
32 | var c = 20;
33 | var f = 68;
34 | var r = _.temperature.c2f(c);
35 | assert.strictEqual(f, r);
36 | });
37 | it('100', function() {
38 | var c = 100;
39 | var f = 212;
40 | var r = _.temperature.c2f(c);
41 | assert.strictEqual(f, r);
42 | });
43 | });
44 | describe('f->c', function(){
45 | it('-40', function() {
46 | var c = -40;
47 | var f = -40;
48 | var r = _.temperature.f2c(f);
49 | assert.strictEqual(c, r);
50 | });
51 | it('32', function() {
52 | var c = 0;
53 | var f = 32;
54 | var r = _.temperature.f2c(f);
55 | assert.strictEqual(c, r);
56 | });
57 | it('68', function() {
58 | var c = 20;
59 | var f = 68;
60 | var r = _.temperature.f2c(f);
61 | assert.strictEqual(c, r);
62 | });
63 | it('212', function() {
64 | var c = 100;
65 | var f = 212;
66 | var r = _.temperature.f2c(f);
67 | assert.strictEqual(c, r);
68 | });
69 | });
70 | })
71 | */
72 |
--------------------------------------------------------------------------------
/test/test_thing_set_connect.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_thing_set_connect.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-07-15
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var iotdb = require("../iotdb");
15 | var thing_manager = require("../thing_manager");
16 | var thing_set = require("../thing_set");
17 |
18 | require('./instrument/iotdb');
19 |
20 | describe("test_thing_set_connect", function() {
21 | describe("creation", function() {
22 | it("from empty thing_set", function(done) {
23 | const ts_1 = thing_set.make();
24 | assert.ok(ts_1.empty());
25 |
26 | const ts_2 = ts_1.connect("Test", {}, { "schema:name": "A", });
27 | ts_2.on("thing", function() {
28 | assert.ok(ts_2.count(), 1);
29 | done();
30 | });
31 | });
32 | it("from non-empty thing_set", function(done) {
33 | var tm = thing_manager.make();
34 | tm.reset();
35 |
36 | var ts_1 = tm.connect("Test", { number: 1 }, { "schema:name": "A" });
37 | ts_1.once("thing", function(thing) {
38 | const ts_2 = ts_1.connect("Test", { number: 2}, { "schema:name": "B", });
39 | ts_2.on("thing", function() {
40 | assert.ok(ts_2.count(), 2);
41 | done();
42 | });
43 | });
44 | });
45 | });
46 | });
47 |
--------------------------------------------------------------------------------
/test/test_thing_set_search_dynamic.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_thing_set_search_dynamic.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-07-15
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var iotdb = require("../iotdb");
15 | var thing_manager = require("../thing_manager");
16 | var thing_set = require("../thing_set");
17 |
18 | require('./instrument/iotdb');
19 |
20 | describe("test_thing_set_search_dynamic", function() {
21 | describe("creation", function() {
22 | it("thing can be found after made", function(done) {
23 | const tm = thing_manager.make();
24 | const ts = thing_set.make(tm);
25 | assert.ok(ts.empty());
26 |
27 | ts.connect("Test", {}, { "schema:name": "A", });
28 | ts.on("thing", function() {
29 | const ss = ts.search({
30 | "meta:schema:name": "A",
31 | });
32 |
33 | assert.strictEqual(ss.count(), 1);
34 | done();
35 | });
36 | });
37 | it("thing gets added after creation", function(done) {
38 | const tm = thing_manager.make();
39 | const ts = thing_set.make(tm);
40 | assert.ok(ts.empty());
41 |
42 | const ss = ts.search({
43 | "meta:schema:name": "A",
44 | });
45 |
46 | ts.connect("Test", {}, { "schema:name": "A", });
47 | ss.on("thing", function() {
48 | assert.strictEqual(ss.count(), 1);
49 | done();
50 | });
51 | });
52 | });
53 | describe("meta changes", function() {
54 | it("thing gets added after name change", function(done) {
55 | const tm = thing_manager.make();
56 | const ts = thing_set.make(tm);
57 | assert.ok(ts.empty());
58 |
59 | const ss = ts.search({
60 | "meta:schema:name": "B",
61 | });
62 |
63 | console.log("ss._sid", ss._sid);
64 | console.log("ts._sid", ts._sid);
65 |
66 | console.log("HERE:A.1");
67 | const zs = ts.connect("Test", {}, { "schema:name": "A", });
68 | ts.on("thing", function(thing) {
69 | assert.strictEqual(ss.count(), 0);
70 | console.log("HERE:B.1", thing.name());
71 | thing.update("meta", { "schema:name": "B" });
72 | console.log("HERE:B.2", thing.name());
73 |
74 | ss.on("thing", function() {
75 | console.log("DONE");
76 | assert.strictEqual(ss.count(), 1);
77 | done();
78 | });
79 | });
80 | });
81 | it("thing gets removed after name change", function(done) {
82 | const tm = thing_manager.make();
83 | const ts = thing_set.make(tm);
84 | assert.ok(ts.empty());
85 |
86 | const ss = ts.search({
87 | "meta:schema:name": "A",
88 | });
89 |
90 | console.log("BEFORE CONNECT");
91 | ts.connect("Test", {}, { "schema:name": "A", });
92 | console.log("AFTER CONNECT");
93 | ss.on("thing", function(thing) {
94 | console.log("IN", thing.thing_id());
95 | assert.strictEqual(ss.count(), 1);
96 | console.log("HERE:SET META", ss._sid);
97 | thing.update("meta", { "schema:name": "B" });
98 |
99 | ss.on("removed", function() {
100 | assert.strictEqual(ss.count(), 0);
101 | done();
102 | });
103 | });
104 | });
105 | });
106 | });
107 |
--------------------------------------------------------------------------------
/test/test_thing_set_values.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_thing_set_values.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-09-08
7 | */
8 |
9 | "use strict";
10 |
11 | const assert = require("assert")
12 | const _ = require("../helpers")
13 |
14 | const iotdb = require("../iotdb");
15 | const thing_manager = require("../thing_manager");
16 | const thing_set = require("../thing_set");
17 |
18 | require('./instrument/iotdb');
19 |
20 | const _make_a_thing = function(callback) {
21 | const t = thing_manager.make();
22 | t.reset();
23 |
24 | const ts = t.connect("Test", {}, {
25 | "schema:name": "The Thing Name",
26 | "schema:description": "My Thing",
27 | "iot:thing-number": 32,
28 | });
29 | ts.on("thing", function() {
30 | callback(ts.any());
31 | });
32 | };
33 |
34 | describe("test_thing_set_values", function() {
35 | describe("connection", function() {
36 | it("has controller values", function(done) {
37 | _make_a_thing(function(thing) {
38 | const connection = thing.state("connection");
39 | const controller = iotdb.controller_meta();
40 |
41 | assert.ok(_.d.is.superset(connection, controller));
42 | done();
43 | });
44 | });
45 | it("has iot:reachable", function(done) {
46 | _make_a_thing(function(thing) {
47 | const connection = thing.state("connection");
48 |
49 | assert.ok(connection["iot:reachable"])
50 | done();
51 | });
52 | });
53 | });
54 | });
55 |
--------------------------------------------------------------------------------
/test/test_thing_set_with_facets.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_thing_set_with_facet.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-07-18
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var iotdb = require("../iotdb");
15 | var thing_manager = require("../thing_manager");
16 |
17 | require('./instrument/iotdb');
18 |
19 | var _make_thing = function(callback) {
20 | var t = thing_manager.make();
21 | t.reset();
22 |
23 | var ts = t.connect("Test", {}, {
24 | "schema:name": "The Thing Name",
25 | "schema:description": "My Thing",
26 | "iot:zone": [ "Glasgow Place", "Second Floor", "Bedroom" ],
27 | "iot:facet": [ "iot-facet:switch", "iot-facet:lighting", "iot-facet:something" ],
28 | "iot:thing-number": 32,
29 | });
30 | ts.on("thing", function() {
31 | callback(ts);
32 | });
33 | };
34 |
35 | describe("test_thing_set_facets", function() {
36 | describe("facets", function(done) {
37 | it("inital facetss", function(done) {
38 | _make_thing(function(ts) {
39 | const thing = ts.any();
40 | const band = thing.band("meta");
41 | const facets = band.get("iot:facet");
42 |
43 | assert.deepEqual(facets, [ "iot-facet:switch", "iot-facet:lighting", "iot-facet:something" ]);
44 | done();
45 | });
46 | });
47 | it("sets the facetss", function(done) {
48 | _make_thing(function(ts) {
49 | const thing = ts.any();
50 | ts.facets([ "a", "b", "c" ]);
51 |
52 | const band = thing.band("meta");
53 | const facets = band.get("iot:facet");
54 |
55 | assert.deepEqual(facets, [ "a", "b", "c" ]);
56 | done();
57 | });
58 | });
59 | });
60 | describe("with_facet", function(done) {
61 | it("matching", function(done) {
62 | _make_thing(function(ts) {
63 | var ms = ts.with_facet("iot-facet:lighting");
64 |
65 | assert.strictEqual(ms.count(), 1);
66 | done();
67 | });
68 | });
69 | it("matching with array", function(done) {
70 | _make_thing(function(ts) {
71 | var ms = ts.with_facet([ "iot-facet:lighting", "iot-facet:lighting", "iot-facet:something"]);
72 |
73 | assert.strictEqual(ms.count(), 1);
74 | done();
75 | });
76 | });
77 | it("matching with array with some non matching items", function(done) {
78 | _make_thing(function(ts) {
79 | var ms = ts.with_facet([ "iot-facet:something", "d", "e"]);
80 |
81 | assert.strictEqual(ms.count(), 1);
82 | done();
83 | });
84 | });
85 | it("not matching", function(done) {
86 | _make_thing(function(ts) {
87 | var ms = ts.with_facet("e");
88 |
89 | assert.strictEqual(ms.count(), 0);
90 | assert.ok(ms.empty());
91 | done();
92 | });
93 | });
94 | it("not matching with array", function(done) {
95 | _make_thing(function(ts) {
96 | var ms = ts.with_facet([ "e", "f", "g" ]);
97 |
98 | assert.strictEqual(ms.count(), 0);
99 | assert.ok(ms.empty());
100 | done();
101 | });
102 | });
103 | });
104 | });
105 |
--------------------------------------------------------------------------------
/test/test_thing_set_with_name.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_thing_set_with_name.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-07-17
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var iotdb = require("../iotdb");
15 | var thing_manager = require("../thing_manager");
16 |
17 | require('./instrument/iotdb');
18 |
19 | var _make_thing = function(callback) {
20 | var t = thing_manager.make();
21 | t.reset();
22 |
23 | var ts = t.connect("Test", {}, {
24 | "schema:name": "The Thing Name",
25 | "schema:description": "My Thing",
26 | "iot:zone": [ "Glasgow Place", "Second Floor", "Bedroom" ],
27 | "iot:facet": [ "iot-facet:switch", "iot-facet:lighting", "iot-facet:something" ],
28 | "iot:thing-number": 32,
29 | });
30 | ts.name("New Name");
31 | ts.on("thing", function() {
32 | callback(ts);
33 | });
34 | };
35 |
36 | describe('test_thing_set_with_name', function() {
37 | describe('name', function(done) {
38 | it('sets the tags', function(done) {
39 | _make_thing(function(ts) {
40 | const thing = ts.any();
41 | const name = thing.name();
42 |
43 | assert.deepEqual(name, "New Name");
44 | done();
45 | });
46 | });
47 | });
48 | describe('with_name', function(done) {
49 | it('matching', function(done) {
50 | _make_thing(function(ts) {
51 | var ms = ts.with_name("New Name");
52 |
53 | assert.strictEqual(ms.count(), 1);
54 | done();
55 | });
56 | });
57 | it('matching with array with some non matching items', function(done) {
58 | _make_thing(function(ts) {
59 | var ms = ts.with_name([ "New Name", "d", "e"]);
60 |
61 | assert.strictEqual(ms.count(), 1);
62 | done();
63 | });
64 | });
65 | it('not matching', function(done) {
66 | _make_thing(function(ts) {
67 | var ms = ts.with_name("e");
68 |
69 | assert.strictEqual(ms.count(), 0);
70 | assert.ok(ms.empty());
71 | done();
72 | });
73 | });
74 | it('not matching with array', function(done) {
75 | _make_thing(function(ts) {
76 | var ms = ts.with_name([ "e", "f", "g" ]);
77 |
78 | assert.strictEqual(ms.count(), 0);
79 | assert.ok(ms.empty());
80 | done();
81 | });
82 | });
83 | });
84 | });
85 |
--------------------------------------------------------------------------------
/test/test_thing_set_with_tag.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_thing_set_with_tag.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-01-06
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var iotdb = require("../iotdb");
15 | var thing_manager = require("../thing_manager");
16 |
17 | require('./instrument/iotdb');
18 |
19 | var _make_thing = function(callback) {
20 | var t = thing_manager.make();
21 | t.reset();
22 |
23 | var ts = t.connect("Test", {}, {
24 | "schema:name": "The Thing Name",
25 | "schema:description": "My Thing",
26 | "iot:zone": [ "Glasgow Place", "Second Floor", "Bedroom" ],
27 | "iot:facet": [ "iot-facet:switch", "iot-facet:lighting", "iot-facet:something" ],
28 | "iot:thing-number": 32,
29 | });
30 | ts.tag([ "a", "b", "c" ]);
31 | ts.on("thing", function() {
32 | callback(ts);
33 | });
34 | };
35 |
36 | describe('test_thing_set_tag', function() {
37 | describe('tag', function(done) {
38 | it('sets the tags', function(done) {
39 | _make_thing(function(ts) {
40 | const thing = ts.any();
41 | const band = thing.band("transient");
42 | const state = band.state();
43 |
44 | assert.deepEqual(state, { tag: [ 'a', 'b', 'c' ] });
45 | done();
46 | });
47 | });
48 | });
49 | describe('with_tag', function(done) {
50 | it('matching', function(done) {
51 | _make_thing(function(ts) {
52 | var ms = ts.with_tag("a");
53 |
54 | assert.strictEqual(ms.count(), 1);
55 | done();
56 | });
57 | });
58 | it('matching with array', function(done) {
59 | _make_thing(function(ts) {
60 | var ms = ts.with_tag([ "a", "b", "c"]);
61 |
62 | assert.strictEqual(ms.count(), 1);
63 | done();
64 | });
65 | });
66 | it('matching with array with some non matching items', function(done) {
67 | _make_thing(function(ts) {
68 | var ms = ts.with_tag([ "c", "d", "e"]);
69 |
70 | assert.strictEqual(ms.count(), 1);
71 | done();
72 | });
73 | });
74 | it('not matching', function(done) {
75 | _make_thing(function(ts) {
76 | var ms = ts.with_tag("e");
77 |
78 | assert.strictEqual(ms.count(), 0);
79 | assert.ok(ms.empty());
80 | done();
81 | });
82 | });
83 | it('not matching with array', function(done) {
84 | _make_thing(function(ts) {
85 | var ms = ts.with_tag([ "e", "f", "g" ]);
86 |
87 | assert.strictEqual(ms.count(), 0);
88 | assert.ok(ms.empty());
89 | done();
90 | });
91 | });
92 | });
93 | });
94 |
--------------------------------------------------------------------------------
/test/test_thing_set_with_zones.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_thing_set_with_zone.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-07-18
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var iotdb = require("../iotdb");
15 | var thing_manager = require("../thing_manager");
16 |
17 | require('./instrument/iotdb');
18 |
19 | var _make_thing = function(callback) {
20 | var t = thing_manager.make();
21 | t.reset();
22 |
23 | var ts = t.connect("Test", {}, {
24 | "schema:name": "The Thing Name",
25 | "schema:description": "My Thing",
26 | "iot:zone": [ "Glasgow Place", "Second Floor", "Bedroom" ],
27 | "iot:facet": [ "iot-facet:switch", "iot-facet:lighting", "iot-facet:something" ],
28 | "iot:thing-number": 32,
29 | });
30 | ts.on("thing", function() {
31 | callback(ts);
32 | });
33 | };
34 |
35 | describe("test_thing_set_zones", function() {
36 | describe("zones", function(done) {
37 | it("inital zoness", function(done) {
38 | _make_thing(function(ts) {
39 | const thing = ts.any();
40 | const band = thing.band("meta");
41 | const zones = band.get("iot:zone");
42 |
43 | assert.deepEqual(zones, [ "Glasgow Place", "Second Floor", "Bedroom" ]);
44 | done();
45 | });
46 | });
47 | it("sets the zoness", function(done) {
48 | _make_thing(function(ts) {
49 | const thing = ts.any();
50 | ts.zones([ "a", "b", "c" ]);
51 |
52 | const band = thing.band("meta");
53 | const zones = band.get("iot:zone");
54 |
55 | assert.deepEqual(zones, [ "a", "b", "c" ]);
56 | done();
57 | });
58 | });
59 | });
60 | describe("with_zone", function(done) {
61 | it("matching", function(done) {
62 | _make_thing(function(ts) {
63 | var ms = ts.with_zone("Glasgow Place");
64 |
65 | assert.strictEqual(ms.count(), 1);
66 | done();
67 | });
68 | });
69 | it("matching with array", function(done) {
70 | _make_thing(function(ts) {
71 | var ms = ts.with_zone([ "Glasgow Place", "Second Floor", "Bedroom"]);
72 |
73 | assert.strictEqual(ms.count(), 1);
74 | done();
75 | });
76 | });
77 | it("matching with array with some non matching items", function(done) {
78 | _make_thing(function(ts) {
79 | var ms = ts.with_zone([ "Bedroom", "d", "e"]);
80 |
81 | assert.strictEqual(ms.count(), 1);
82 | done();
83 | });
84 | });
85 | it("not matching", function(done) {
86 | _make_thing(function(ts) {
87 | var ms = ts.with_zone("e");
88 |
89 | assert.strictEqual(ms.count(), 0);
90 | assert.ok(ms.empty());
91 | done();
92 | });
93 | });
94 | it("not matching with array", function(done) {
95 | _make_thing(function(ts) {
96 | var ms = ts.with_zone([ "e", "f", "g" ]);
97 |
98 | assert.strictEqual(ms.count(), 0);
99 | assert.ok(ms.empty());
100 | done();
101 | });
102 | });
103 | });
104 | });
105 |
--------------------------------------------------------------------------------
/test/test_users.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_users.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-02-06
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var iotdb = require("../iotdb");
15 |
16 | describe('test_users', function() {
17 | it('default owner', function() {
18 | assert.strictEqual(iotdb.users.owner(), null);
19 | });
20 | it('default authorize', function(done) {
21 | iotdb.users.authorize({}, function(error, authorized) {
22 | assert.strictEqual(error, null);
23 | assert.strictEqual(authorized, true);
24 | done();
25 | });
26 | });
27 | });
28 |
--------------------------------------------------------------------------------
/test/test_version.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_version.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-02-06
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 |
13 | var version = require("../helpers/version");
14 | var _ = require("../helpers");
15 |
16 | describe('test_version', function() {
17 | describe('current version', function() {
18 | it('should be ok!', function(done) {
19 | version.version.check.node();
20 | done();
21 | });
22 | it('should do callback', function(done) {
23 | version.version.check.node((error, paramd) => {
24 | assert.ok(!error);
25 | assert.ok(paramd);
26 | assert.strictEqual(paramd.version, process.versions.node);
27 | assert.ok(paramd.satisfies);
28 | done();
29 | });
30 | });
31 | });
32 | describe('out of date version', function() {
33 | beforeEach(function() {
34 | version.shims.version("0.12.3");
35 | });
36 | afterEach(function() {
37 | version.shims.version();
38 | });
39 | it('should fail', function() {
40 | assert.throws(() => {
41 | version.version.check.node();
42 | });
43 | });
44 | it('should do callback', function(done) {
45 | version.version.check.node((error, paramd) => {
46 | assert.ok(error);
47 | assert.ok(paramd);
48 | assert.strictEqual(paramd.version, "0.12.3");
49 | assert.ok(paramd.satisfies);
50 | done();
51 | });
52 | });
53 | });
54 | });
55 |
--------------------------------------------------------------------------------
/test/test_windows.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_windows.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2016-02-06
7 | */
8 |
9 | "use strict";
10 |
11 | var assert = require("assert")
12 | var _ = require("../helpers")
13 |
14 | var windows = require('../windows');
15 |
16 | var setup = function(HOME, USERPROFILE, callback) {
17 | var old_HOME = process.env.HOME;
18 | var old_USERPROFILE = process.env.USERPROFILE;
19 |
20 | if (!HOME) {
21 | delete process.env.HOME;
22 | } else {
23 | process.env.HOME = HOME;
24 | }
25 |
26 | if (!USERPROFILE) {
27 | delete process.env.USERPROFILE;
28 | } else {
29 | process.env.USERPROFILE = USERPROFILE;
30 | }
31 |
32 | windows.setup();
33 | callback();
34 |
35 | process.env.HOME = old_HOME;
36 | process.env.USERPROFILE = old_USERPROFILE;
37 |
38 | }
39 |
40 | describe('test_windows', function() {
41 | it('!HOME !USERPROFILE', function(done) {
42 | // no change
43 | var HOME = undefined;
44 | var USERPROFILE = undefined;
45 | setup(HOME, USERPROFILE, function() {
46 | assert.strictEqual(HOME, process.env.HOME);
47 | done();
48 | });
49 | });
50 | it('HOME !USERPROFILE', function(done) {
51 | // no change
52 | var HOME = undefined;
53 | var USERPROFILE = undefined;
54 | setup(HOME, USERPROFILE, function() {
55 | assert.strictEqual(HOME, process.env.HOME);
56 | done();
57 | });
58 | });
59 | it('!HOME USERPROFILE', function(done) {
60 | // change!!!
61 | var HOME = undefined;
62 | var USERPROFILE = "/user/robert";
63 | setup(HOME, USERPROFILE, function() {
64 | assert.strictEqual(USERPROFILE, process.env.HOME);
65 | done();
66 | });
67 | });
68 | it('HOME USERPROFILE', function(done) {
69 | // no change
70 | var HOME = "/user/david";
71 | var USERPROFILE = "/user/robert";
72 | setup(HOME, USERPROFILE, function() {
73 | assert.strictEqual(HOME, process.env.HOME);
74 | done();
75 | });
76 | });
77 | });
78 |
--------------------------------------------------------------------------------
/test/to-be-deleted/test_attribute_bounds.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_attribute_bounds.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2013-12-28
7 | *
8 | * Test attribute conversions preferences
9 | */
10 |
11 | "use strict";
12 |
13 | var assert = require("assert")
14 | var iotdb = require("../iotdb")
15 | var attribute = require("./instrument/attribute")
16 | var _ = require("../helpers")
17 | var constants = require("../constants")
18 |
19 | var wrap_validate = function(a, value) {
20 | var paramd = {
21 | value: value
22 | }
23 | a.validate(paramd)
24 | return paramd.value
25 | }
26 |
27 | /* --- tests --- */
28 | describe('test_attribute_bounds:', function(){
29 | describe('underlying', function(){
30 | it('test bounds', function(){
31 | var a = new attribute.Attribute();
32 | assert.strictEqual(1.5, a._bounded(-1, 1.5, 5.5))
33 | assert.strictEqual(1.5, a._bounded(0, 1.5, 5.5))
34 | assert.strictEqual(1.5, a._bounded(1.5, 1.5, 5.5))
35 | assert.strictEqual(2.5, a._bounded(2.5, 1.5, 5.5))
36 | assert.strictEqual(5.5, a._bounded(5.5, 1.5, 5.5))
37 | assert.strictEqual(5.5, a._bounded(6, 1.5, 5.5))
38 | assert.strictEqual(5.5, a._bounded(99, 1.5, 5.5))
39 | });
40 | });
41 | describe('boolean', function(){
42 | it('test bounds', function(){
43 | var a = attribute.make_boolean("value").reading()
44 | .minimum(10)
45 | .maximum(20)
46 | // no effect
47 | assert.strictEqual(true, wrap_validate(a, true));
48 | assert.strictEqual(false, wrap_validate(a, false));
49 | });
50 | });
51 | describe('integer', function(){
52 | it('test bounds', function(){
53 | var a = attribute.make_integer("value").reading()
54 | .minimum(10)
55 | .maximum(20)
56 | assert.strictEqual(10, wrap_validate(a, 0));
57 | assert.strictEqual(10, wrap_validate(a, 9));
58 | assert.strictEqual(10, wrap_validate(a, 10));
59 | assert.strictEqual(15, wrap_validate(a, 15));
60 | assert.strictEqual(20, wrap_validate(a, 20));
61 | assert.strictEqual(20, wrap_validate(a, 25));
62 | });
63 | });
64 | describe('number', function(){
65 | it('test bounds', function(){
66 | var a = attribute.make_number("value").reading()
67 | .minimum(1.0)
68 | .maximum(2.0)
69 | assert.strictEqual(1.0, wrap_validate(a, 0));
70 | assert.strictEqual(1.0, wrap_validate(a, .9));
71 | assert.strictEqual(1.0, wrap_validate(a, 1.0));
72 | assert.strictEqual(1.5, wrap_validate(a, 1.5));
73 | assert.strictEqual(2.0, wrap_validate(a, 2.0));
74 | assert.strictEqual(2.0, wrap_validate(a, 2.5));
75 | });
76 | });
77 | describe('string', function(){
78 | it('test bounds', function(){
79 | var a = attribute.make_string("value").reading()
80 | .minimum(1.0)
81 | .maximum(2.0)
82 | assert.strictEqual("", wrap_validate(a, ""));
83 | assert.strictEqual("now is the time", wrap_validate(a, "now is the time"));
84 | });
85 | });
86 | })
87 |
--------------------------------------------------------------------------------
/test/to-be-deleted/test_attribute_datetime.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_attribute_datetime.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2014-02-14
7 | *
8 | * Test datetime with attributes
9 | */
10 |
11 | "use strict";
12 |
13 | var assert = require("assert")
14 | var iotdb = require("../iotdb")
15 | var attribute = require("./instrument/attribute")
16 | var model = require("../model")
17 | var _ = require("../helpers")
18 | var constants = require("../constants")
19 |
20 | var wrap_validate = function(a, value, paramd) {
21 | if (paramd === undefined) {
22 | paramd = {}
23 | }
24 | paramd['value'] = value
25 |
26 | a.validate(paramd)
27 | return paramd.value
28 | }
29 |
30 | /* --- tests --- */
31 | describe('test_attribute_format:', function(){
32 | describe('format', function(){
33 | it('bad datetime - no otherwise', function(){
34 | var a = attribute.make_string("value").reading()
35 | .format("datetime")
36 |
37 | var x = wrap_validate(a, "a")
38 | assert.ok(x === undefined)
39 | });
40 | it('bad datetime - default otherwise', function(){
41 | var a = attribute.make_string("value").reading()
42 | .format("datetime")
43 |
44 | var x = wrap_validate(a, "a", {
45 | use_otherwise: true
46 | })
47 | assert.ok(x !== undefined)
48 | });
49 | it('bad datetime - specified otherwise', function(){
50 | var a = attribute.make_string("value").reading()
51 | .format("datetime")
52 |
53 | var x = wrap_validate(a, "a", {
54 | use_otherwise: true,
55 | otherwise_datetime: "2014-02-14T05:00:00.000Z"
56 | })
57 | assert.ok(x === "2014-02-14T05:00:00.000Z")
58 | });
59 | });
60 | describe('in Thing', function(){
61 | it('valid values', function(){
62 | var T = model.make_model('T')
63 | .attribute(
64 | attribute.make_string("when").format("datetime").reading()
65 | )
66 | .make();
67 | var t = new T();
68 | t._clear_ostate = function() {};
69 | assert.ok(t.state("ostate")['when'] === null)
70 |
71 | t.set('when', "2014-02-14T05:00:00.000Z")
72 | assert.ok(t.state("ostate")['when'] === "2014-02-14T05:00:00.000Z")
73 |
74 | var d = new Date(2014, 2, 14, 5, 0, 0, 0)
75 | t.set('when', d)
76 | assert.ok(t.state("ostate")['when'] === d.toISOString())
77 |
78 | t.set('when', null)
79 | assert.ok(t.state("ostate")['when'] === null)
80 |
81 | var d = new Date()
82 | t.set('when', d)
83 | assert.ok(t.state("ostate")['when'] === d.toISOString())
84 | });
85 |
86 | })
87 | })
88 |
--------------------------------------------------------------------------------
/test/to-be-deleted/test_attribute_format.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_attribute_format.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2013-12-31
7 | *
8 | * Test formatting code
9 | */
10 |
11 | "use strict";
12 |
13 | var assert = require("assert")
14 | var iotdb = require("../iotdb")
15 | var attribute = require("./instrument/attribute")
16 | var _ = require("../helpers")
17 | var constants = require("../constants")
18 |
19 | var wrap_validate = function(a, value, paramd) {
20 | if (paramd === undefined) {
21 | paramd = {}
22 | }
23 | paramd['value'] = value
24 |
25 | a.validate(paramd)
26 | return paramd.value
27 | }
28 |
29 | /* --- tests --- */
30 | describe('test_attribute_format:', function(){
31 | describe('format', function(){
32 | it('RGB - bad', function(){
33 | var a = attribute.make_string("value").reading()
34 | .format("color")
35 |
36 | assert.strictEqual(undefined, wrap_validate(a, ''));
37 | assert.strictEqual(undefined, wrap_validate(a, '', {}));
38 | assert.strictEqual('#000000', wrap_validate(a, '', {
39 | use_otherwise : true
40 | }));
41 | assert.strictEqual('#123456', wrap_validate(a, '', {
42 | use_otherwise : true,
43 | otherwise_rgb : '#123456'
44 | }));
45 | });
46 | it('RGB - good', function(){
47 | var a = attribute.make_string("value").reading()
48 | .format("color")
49 |
50 | assert.strictEqual("#000000", wrap_validate(a, '#000000'));
51 | assert.strictEqual("#FF00FF", wrap_validate(a, '#FF00FF'));
52 | });
53 | it('datetime', function(){
54 | var a = attribute.make_string("value").reading()
55 | .format("datetime")
56 |
57 | assert.strictEqual(undefined, wrap_validate(a, ''));
58 | assert.strictEqual('not a date', wrap_validate(a, '', {
59 | use_otherwise : true,
60 | otherwise_datetime : "not a date"
61 | }));
62 |
63 | /* test default otherwise being about now */
64 | {
65 | var vdate$ = wrap_validate(a, '', {
66 | use_otherwise : true
67 | })
68 | var vs = Date.parse(vdate$);
69 | var ns = new Date().getTime()
70 | assert.ok(Math.abs(vs - ns) < 5 * 1000)
71 | }
72 |
73 | /* test Date conversion */
74 | assert.strictEqual('2012-01-14T00:00:00.000Z', wrap_validate(a, new Date('2012-01-14')));
75 | });
76 | });
77 | })
78 |
--------------------------------------------------------------------------------
/test/to-be-deleted/test_attribute_io.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_attribute_io.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2013-12-28
7 | *
8 | * Test attribute conversions preferences
9 | */
10 |
11 | "use strict";
12 |
13 | var assert = require("assert")
14 | var iotdb = require("../iotdb")
15 | var attribute = require("./instrument/attribute")
16 | var _ = require("../helpers")
17 | var model = require("../model");
18 | var definitions = require("./instrument/definitions");
19 |
20 | require('./instrument/attribute');
21 | require('./instrument/model_maker');
22 |
23 | var BooleanModel = model.make_model('BooleanModel')
24 | .io("value", definitions.attribute.boolean)
25 | .make();
26 |
27 | var IntegerModel = model.make_model('IntegerModel')
28 | .io("value", definitions.attribute.integer)
29 | .make();
30 |
31 | /* --- tests --- */
32 | describe('test_attribute_io:', function(){
33 | describe('boolean', function(){
34 | it('initial underlying', function(){
35 | var m = new BooleanModel();
36 | var as = m.attributes();
37 | assert.strictEqual(as.length, 1);
38 |
39 | var a = as[0];
40 | assert.strictEqual(a._ivalue, null);
41 | assert.strictEqual(a._ovalue, null);
42 |
43 | /* get - returns ivalue or ovalue */
44 | assert.strictEqual(m.get("value"), null);
45 |
46 | /* state */
47 | assert.ok(_.d.is.subset({ value: null }, m.state("ostate")));
48 | assert.ok(_.d.is.subset({ value: null }, m.state("istate")));
49 | });
50 | it('set vs. underlying', function(){
51 | var m = new BooleanModel();
52 | m._clear_ostate = function() {};
53 | var as = m.attributes();
54 | var a = as[0];
55 |
56 | /* changes ovalue */
57 | m.set("value", true);
58 | assert.strictEqual(a._ivalue, null);
59 | assert.strictEqual(a._ovalue, true);
60 |
61 | /* get - returns ivalue or ovalue */
62 | assert.strictEqual(m.get("value"), true);
63 |
64 | /* state */
65 | assert.ok(_.d.is.subset({ value: true }, m.state("ostate")));
66 | assert.ok(_.d.is.subset({ value: null }, m.state("istate")));
67 | });
68 | /* NO MORE TRANSACTIONS
69 | it('set/push=true vs. underlying', function(){
70 | var m = new BooleanModel();
71 | var as = m.attributes();
72 | var a = as[0];
73 |
74 | // changes ovalue
75 | m.start({ push: true }).set("value", true).end();
76 |
77 | assert.strictEqual(a._ivalue, null);
78 | assert.strictEqual(a._ovalue, true);
79 |
80 | // get - returns ivalue or ovalue
81 | assert.strictEqual(m.get("value"), true);
82 |
83 | // state
84 | assert.ok(_.is.Equal({ value: true }, m.state("ostate")));
85 | assert.ok(_.is.Equal({ value: null }, m.state("istate")));
86 | });
87 | */
88 | /* NO MORE TRANSACTIONS
89 | it('set/push=false vs. underlying', function(){
90 | var m = new BooleanModel();
91 | var as = m.attributes();
92 | var a = as[0];
93 |
94 | // changes ivalue
95 | m.start({ push: false }).set("value", true).end();
96 |
97 | assert.strictEqual(a._ivalue, true);
98 | assert.strictEqual(a._ovalue, null);
99 |
100 | // get - returns ivalue or ovalue
101 | assert.strictEqual(m.get("value"), true);
102 |
103 | // state
104 | assert.ok(_.is.Equal({ value: true }, m.state("istate")))
105 | assert.ok(_.is.Equal({ value: null }, m.state("ostate")))
106 | });
107 | */
108 | });
109 | describe('integer', function(){
110 | it('multivalue - initial underlying', function(){
111 | var m = new IntegerModel();
112 | var as = m.attributes();
113 | assert.strictEqual(as.length, 1);
114 |
115 | var a = as[0];
116 | assert.strictEqual(a._ivalue, null);
117 | assert.strictEqual(a._ovalue, null);
118 |
119 | /* get - returns ivalue or ovalue */
120 | assert.strictEqual(m.get("value"), null);
121 |
122 | /* state */
123 | assert.ok(_.is.Equal({ value: null, "@timestamp": _.timestamp.epoch(), }, m.state("ostate")));
124 | assert.ok(_.is.Equal({ value: null, "@timestamp": _.timestamp.epoch(), }, m.state("istate")));
125 | });
126 | /* NO MORE TRANSACTIONS
127 | it('multivalue - ivalue and ovalue priority', function(){
128 | var m = new IntegerModel();
129 | var as = m.attributes();
130 | assert.strictEqual(as.length, 1);
131 |
132 | // ovalue, then ivalue
133 | m.start({ push: true }).set("value", 1).end();
134 | m.start({ push: false }).set("value", 2).end();
135 |
136 | // get - returns ivalue before ovalue
137 | assert.strictEqual(m.get("value"), 2);
138 |
139 | // state
140 | assert.ok(_.is.Equal({ value: 2 }, m.state("istate")));
141 | assert.ok(_.is.Equal({ value: 1 }, m.state("ostate")));
142 | });
143 | */
144 | });
145 | })
146 |
--------------------------------------------------------------------------------
/test/to-be-deleted/test_attribute_list.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_attribute_list.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2015-06-28
7 | *
8 | * Test attribtues with lists
9 | */
10 |
11 | "use strict";
12 |
13 | var assert = require("assert")
14 | var iotdb = require("../iotdb")
15 | var attribute = require("./instrument/attribute")
16 | var model = require("../model")
17 | var _ = require("../helpers")
18 | var constants = require("../constants")
19 |
20 | /* --- tests --- */
21 | describe('test_attribute_rgb:', function(){
22 | describe('validate string/list conversions', function(){
23 | it('', function(){
24 | var a = attribute.make_string("value").list();
25 |
26 | var x = a.validate_value(null)
27 | assert.ok(_.isEqual(x, []))
28 |
29 | var x = a.validate_value("")
30 | assert.ok(_.isEqual(x, [ "" ]))
31 |
32 | var x = a.validate_value("a")
33 | assert.ok(_.isEqual(x, [ "a" ]))
34 |
35 | var x = a.validate_value(1)
36 | assert.ok(_.isEqual(x, [ "1" ]))
37 |
38 | var x = a.validate_value([ 1 ])
39 | assert.ok(_.isEqual(x, [ "1" ]))
40 |
41 | var x = a.validate_value([ 1, 3, 5 ])
42 | assert.ok(_.isEqual(x, [ "1", "3", "5" ]))
43 |
44 | var x = a.validate_value([ "1", 3, "5", 1 ])
45 | assert.ok(_.isEqual(x, [ "1", "3", "5", "1" ]))
46 |
47 | var x = a.validate_value([ "1 3 5" ])
48 | assert.ok(_.isEqual(x, [ "1 3 5" ]))
49 |
50 | var x = a.validate_value("1 3 5")
51 | assert.ok(_.isEqual(x, [ "1 3 5" ]))
52 | });
53 | });
54 | describe('validate data/list conversions', function(){
55 | it('', function(){
56 | var a = attribute.make_datetime("value").list();
57 |
58 | var x = a.validate_value(null)
59 | assert.ok(_.isEqual(x, []))
60 |
61 | // because undefined
62 | var x = a.validate_value("")
63 | assert.ok(_.isEqual(x, []))
64 |
65 | var now_dt = new Date();
66 | var now_iso = now_dt.toISOString();
67 |
68 | var x = a.validate_value(now_dt)
69 | assert.ok(_.isEqual(x, [ now_iso, ]))
70 |
71 | var x = a.validate_value([ now_dt, now_dt ])
72 | assert.ok(_.isEqual(x, [ now_iso, now_iso, ]))
73 | });
74 | });
75 | describe('model', function(){
76 | it('Model string/list', function(){
77 | var AModel = model.make_model('A')
78 | .attribute(
79 | attribute
80 | .make_string('value')
81 | .list()
82 | )
83 | .make();
84 |
85 | var a = new AModel();
86 | a._clear_ostate = function() {};
87 |
88 | a.set('value', null)
89 | var x = a.state("ostate").value;
90 | assert.ok(_.isEqual(x, []))
91 |
92 | a.set('value', "")
93 | var x = a.state("ostate").value;
94 | assert.ok(_.isEqual(x, [ "" ]))
95 |
96 | a.set('value', "a")
97 | var x = a.state("ostate").value;
98 | assert.ok(_.isEqual(x, [ "a" ]))
99 |
100 | a.set('value', 1)
101 | var x = a.state("ostate").value;
102 | assert.ok(_.isEqual(x, [ "1" ]))
103 |
104 | a.set('value', [ 1 ])
105 | var x = a.state("ostate").value;
106 | assert.ok(_.isEqual(x, [ "1" ]))
107 |
108 | a.set('value', [ 1, 3, 5 ])
109 | var x = a.state("ostate").value;
110 | assert.ok(_.isEqual(x, [ "1", "3", "5" ]))
111 |
112 | a.set('value', [ "1", 3, "5", 1 ])
113 | var x = a.state("ostate").value;
114 | assert.ok(_.isEqual(x, [ "1", "3", "5", "1" ]))
115 |
116 | a.set('value', [ "1 3 5" ])
117 | var x = a.state("ostate").value;
118 | assert.ok(_.isEqual(x, [ "1 3 5" ]))
119 |
120 | a.set('value', "1 3 5")
121 | var x = a.state("ostate").value;
122 | assert.ok(_.isEqual(x, [ "1 3 5" ]))
123 | });
124 | });
125 | })
126 |
--------------------------------------------------------------------------------
/test/to-be-deleted/test_attribute_preference.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_attribute_preference.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2013-12-28
7 | *
8 | * Test attribute conversions preferences
9 | */
10 |
11 | "use strict";
12 |
13 | var assert = require("assert")
14 | var iotdb = require("../iotdb")
15 | var attribute = require("./instrument/attribute")
16 | var _ = require("../helpers")
17 | var constants = require("../constants")
18 |
19 | /* --- tests --- */
20 | describe('test_attribute_preference:', function(){
21 | describe('boolean', function(){
22 | it('conversion where there are choices', function(){
23 | var a = new attribute.Attribute();
24 | assert.strictEqual(true, a._convert(true, [ constants.iot_boolean, constants.iot_integer ]))
25 | assert.strictEqual(true, a._convert(true, [ constants.iot_boolean, constants.iot_number ]))
26 | assert.strictEqual(true, a._convert(true, [ constants.iot_boolean, constants.iot_string ]))
27 |
28 | assert.strictEqual(1, a._convert(true, [ constants.iot_integer, constants.iot_number ]))
29 | assert.strictEqual(1, a._convert(true, [ constants.iot_integer, constants.iot_string ]))
30 | assert.strictEqual(1, a._convert(true, [ constants.iot_number, constants.iot_string ]))
31 | });
32 | });
33 | describe('integer', function(){
34 | it('conversion where there are choices', function(){
35 | var a = new attribute.Attribute();
36 | assert.strictEqual(true, a._convert(3, [ constants.iot_boolean, constants.iot_integer ]))
37 | assert.strictEqual(true, a._convert(3, [ constants.iot_boolean, constants.iot_number ]))
38 | assert.strictEqual(true, a._convert(3, [ constants.iot_boolean, constants.iot_string ]))
39 |
40 | assert.strictEqual(3, a._convert(3, [ constants.iot_integer, constants.iot_number ]))
41 | assert.strictEqual(3, a._convert(3, [ constants.iot_integer, constants.iot_string ]))
42 | assert.strictEqual(3, a._convert(3, [ constants.iot_number, constants.iot_string ]))
43 | });
44 | });
45 | describe('number', function(){
46 | it('conversion where there are choices', function(){
47 | var a = new attribute.Attribute();
48 | assert.strictEqual(true, a._convert(3.14, [ constants.iot_boolean, constants.iot_integer ]))
49 | assert.strictEqual(true, a._convert(3.14, [ constants.iot_boolean, constants.iot_number ]))
50 | assert.strictEqual(true, a._convert(3.14, [ constants.iot_boolean, constants.iot_string ]))
51 |
52 | assert.strictEqual(3.14, a._convert(3.14, [ constants.iot_integer, constants.iot_number ]))
53 | assert.strictEqual(3, a._convert(3.14, [ constants.iot_integer, constants.iot_string ]))
54 | assert.strictEqual(3.14, a._convert(3.14, [ constants.iot_number, constants.iot_string ]))
55 | });
56 | });
57 | describe('number', function(){
58 | it('conversion where there are choices', function(){
59 | var a = new attribute.Attribute();
60 | assert.strictEqual(true, a._convert("on", [ constants.iot_boolean, constants.iot_integer ]))
61 | assert.strictEqual(true, a._convert("on", [ constants.iot_boolean, constants.iot_number ]))
62 | assert.strictEqual("on", a._convert("on", [ constants.iot_boolean, constants.iot_string ]))
63 |
64 | assert.ok(isNaN(a._convert("on", [ constants.iot_integer, constants.iot_number ])))
65 | assert.strictEqual("on", a._convert("on", [ constants.iot_integer, constants.iot_string ]))
66 | assert.strictEqual("on", a._convert("on", [ constants.iot_number, constants.iot_string ]))
67 | });
68 | });
69 | })
70 |
--------------------------------------------------------------------------------
/test/to-be-deleted/test_attribute_rgb.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_attribute_rgb.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2014-02-14
7 | *
8 | * Test RGB with attributes
9 | */
10 |
11 | "use strict";
12 |
13 | var assert = require("assert")
14 | var iotdb = require("../iotdb")
15 | var attribute = require("./instrument/attribute")
16 | var model = require("../model")
17 | var _ = require("../helpers")
18 | var constants = require("../constants")
19 |
20 | var wrap_validate = function(a, value, paramd) {
21 | if (paramd === undefined) {
22 | paramd = {}
23 | }
24 | paramd['value'] = value
25 |
26 | a.validate(paramd)
27 | return paramd.value
28 | }
29 |
30 | /* --- tests --- */
31 | describe('test_attribute_rgb:', function(){
32 | describe('validate', function(){
33 | it('bad RGB - no otherwise', function(){
34 | var a = attribute.make_string("value").reading()
35 | .format("color")
36 |
37 | var x = wrap_validate(a, "a")
38 | assert.ok(x === undefined)
39 |
40 | var x = wrap_validate(a, "")
41 | assert.ok(x === undefined)
42 |
43 | var x = wrap_validate(a, "FF")
44 | assert.ok(x === undefined)
45 | });
46 | });
47 | describe('model', function(){
48 | it('bad RGB - no otherwise', function(){
49 | var AModel = model.make_model('A')
50 | .attribute(
51 | attribute.make_string('rgb').reading()
52 | .format("color")
53 | )
54 | .make();
55 |
56 | var a = new AModel();
57 | a._clear_ostate = function() {};
58 | a.set('rgb', 'A')
59 | assert.strictEqual(a.state("ostate").rgb, null)
60 |
61 | a.set('rgb', '')
62 | assert.strictEqual(a.state("ostate").rgb, null)
63 |
64 | a.set('rgb', 'FF')
65 | assert.strictEqual(a.state("ostate").rgb, null)
66 | });
67 | it('good RGB', function(){
68 | var AModel = model.make_model('A')
69 | .attribute(
70 | attribute.make_string('rgb').reading()
71 | .format("color")
72 | )
73 | .make();
74 |
75 | var a = new AModel();
76 | a._clear_ostate = function() {};
77 | a.set('rgb', '#000000')
78 | assert.strictEqual(a.state("ostate").rgb, "#000000")
79 |
80 | a.set('rgb', '#FF00FF')
81 | assert.strictEqual(a.state("ostate").rgb, "#FF00FF")
82 |
83 | a.set('rgb', '#FFFFFF')
84 | assert.strictEqual(a.state("ostate").rgb, "#FFFFFF")
85 | });
86 | it('good color', function(){
87 | var AModel = model.make_model('A')
88 | .attribute(
89 | attribute.make_string('rgb').reading()
90 | .format("color")
91 | )
92 | .make();
93 |
94 | var a = new AModel();
95 | a._clear_ostate = function() {};
96 | a.set('rgb', 'red')
97 | assert.strictEqual(a.state("ostate").rgb, "#FF0000")
98 |
99 | a.set('rgb', 'green')
100 | assert.strictEqual(a.state("ostate").rgb, "#008000")
101 |
102 | a.set('rgb', 'blue')
103 | assert.strictEqual(a.state("ostate").rgb, "#0000FF")
104 | });
105 | });
106 | })
107 |
--------------------------------------------------------------------------------
/test/to-be-deleted/test_attribute_set.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_attribute_list.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2015-06-28
7 | *
8 | * Test attribtues with lists
9 | */
10 |
11 | "use strict";
12 |
13 | var assert = require("assert")
14 | var iotdb = require("../iotdb")
15 | var attribute = require("./instrument/attribute")
16 | var model = require("../model")
17 | var _ = require("../helpers")
18 | var constants = require("../constants")
19 |
20 | /* --- tests --- */
21 | describe('test_attribute_rgb:', function(){
22 | describe('validate string/set conversions', function(){
23 | it('', function(){
24 | var a = attribute.make_string("value").set();
25 |
26 | var x = a.validate_value(null)
27 | assert.ok(_.isEqual(x, []))
28 |
29 | var x = a.validate_value("")
30 | assert.ok(_.isEqual(x, [ "" ]))
31 |
32 | var x = a.validate_value("a")
33 | assert.ok(_.isEqual(x, [ "a" ]))
34 |
35 | var x = a.validate_value(1)
36 | assert.ok(_.isEqual(x, [ "1" ]))
37 |
38 | var x = a.validate_value([ 1 ])
39 | assert.ok(_.isEqual(x, [ "1" ]))
40 |
41 | var x = a.validate_value([ 9, 8, 9, 8, 9, "8", "9" ])
42 | assert.ok(_.isEqual(x, [ "9", "8" ]))
43 |
44 | var x = a.validate_value([ 1, 3, 5 ])
45 | assert.ok(_.isEqual(x, [ "1", "3", "5" ]))
46 |
47 | var x = a.validate_value([ "1", 3, "5", 1 ])
48 | assert.ok(_.isEqual(x, [ "1", "3", "5", ]))
49 |
50 | var x = a.validate_value([ "1 3 5" ])
51 | assert.ok(_.isEqual(x, [ "1 3 5" ]))
52 |
53 | var x = a.validate_value("1 3 5")
54 | assert.ok(_.isEqual(x, [ "1 3 5" ]))
55 | });
56 | });
57 | describe('validate data/set conversions', function(){
58 | it('', function(){
59 | var a = attribute.make_datetime("value").set();
60 |
61 | var x = a.validate_value(null)
62 | assert.ok(_.isEqual(x, []))
63 |
64 | // because undefined
65 | var x = a.validate_value("")
66 | assert.ok(_.isEqual(x, []))
67 |
68 | var now_dt = new Date();
69 | var now_iso = now_dt.toISOString();
70 |
71 | var x = a.validate_value(now_dt)
72 | assert.ok(_.isEqual(x, [ now_iso, ]))
73 |
74 | var x = a.validate_value([ now_dt, now_dt ])
75 | assert.ok(_.isEqual(x, [ now_iso, ]))
76 | });
77 | });
78 | describe('model', function(){
79 | it('Model string/set', function(){
80 | var AModel = model.make_model('A')
81 | .attribute(
82 | attribute
83 | .make_string('value')
84 | .set()
85 | )
86 | .make();
87 |
88 | var a = new AModel();
89 | a._clear_ostate = function() {};
90 |
91 | a.set('value', null)
92 | var x = a.state("ostate").value;
93 | assert.ok(_.isEqual(x, []))
94 |
95 | a.set('value', "")
96 | var x = a.state("ostate").value;
97 | assert.ok(_.isEqual(x, [ "" ]))
98 |
99 | a.set('value', "a")
100 | var x = a.state("ostate").value;
101 | assert.ok(_.isEqual(x, [ "a" ]))
102 |
103 | a.set('value', 1)
104 | var x = a.state("ostate").value;
105 | assert.ok(_.isEqual(x, [ "1" ]))
106 |
107 | a.set('value', [ 1 ])
108 | var x = a.state("ostate").value;
109 | assert.ok(_.isEqual(x, [ "1" ]))
110 |
111 | a.set('value', [ 1, 3, 5 ])
112 | var x = a.state("ostate").value;
113 | assert.ok(_.isEqual(x, [ "1", "3", "5" ]))
114 |
115 | a.set('value', [ "1", 3, "5", 1 ])
116 | var x = a.state("ostate").value;
117 | assert.ok(_.isEqual(x, [ "1", "3", "5", ]))
118 |
119 | a.set('value', [ "1 3 5" ])
120 | var x = a.state("ostate").value;
121 | assert.ok(_.isEqual(x, [ "1 3 5" ]))
122 |
123 | a.set('value', "1 3 5")
124 | var x = a.state("ostate").value;
125 | assert.ok(_.isEqual(x, [ "1 3 5" ]))
126 | });
127 | });
128 | })
129 |
--------------------------------------------------------------------------------
/test/to-be-deleted/test_thing_model_code.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_thing_code.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2014-01-16
7 | *
8 | * Test the code setting variants
9 | */
10 |
11 | "use strict";
12 |
13 | var assert = require("assert")
14 | var attribute = require("./instrument/attribute")
15 | var model = require("../model")
16 | var _ = require("../helpers")
17 | var constants = require("../constants")
18 |
19 | /* --- tests --- */
20 | describe('test_thing_model_code:', function(){
21 | it('no-code', function(){
22 | assert.throws(function() {
23 | var AModel = model.make_model()
24 | .make();
25 | }, Error);
26 | });
27 | it('has-code', function(){
28 | assert.doesNotThrow(function() {
29 | var AModel = model.make_model('AModel')
30 | .make();
31 | }, Error);
32 | });
33 | it('has-code', function(){
34 | assert.doesNotThrow(function() {
35 | var AModel = model.make_model()
36 | .code('AModel')
37 | .make();
38 | }, Error);
39 | });
40 | it('code-case', function(){
41 | var AModel = model.make_model()
42 | .code('AModel')
43 | .make();
44 | var a = new AModel();
45 | assert.strictEqual("a-model", a.code());
46 | });
47 | it('code-case', function(){
48 | var AModel = model.make_model()
49 | .code('aModel')
50 | .make();
51 | var a = new AModel();
52 | assert.strictEqual("a-model", a.code());
53 | });
54 | it('code-case', function(){
55 | assert.throws(function() {
56 | var AModel = model.make_model()
57 | .code('$$$')
58 | .make();
59 | });
60 | });
61 | })
62 |
--------------------------------------------------------------------------------
/test/to-be-deleted/test_thing_set.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_thing_set.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2014-01-05
7 | *
8 | * Test setting values
9 | */
10 |
11 | "use strict";
12 |
13 | var assert = require("assert")
14 | var attribute = require("./instrument/attribute")
15 | var model = require("../model")
16 | var _ = require("../helpers")
17 | var constants = require("../constants")
18 |
19 | /* --- tests --- */
20 | describe('test_thing_set:', function(){
21 | it('set', function(){
22 | var T = model.make_model('T')
23 | .attribute(attribute.make_boolean('on').control())
24 | .attribute(
25 | attribute.make_integer('intensity').control()
26 | .maximum(10)
27 | .minimum(0)
28 | )
29 | .make();
30 | var t = new T();
31 | t._clear_ostate = function() {};
32 | assert.ok(_.is.Equal({ on: null, intensity: null, "@timestamp": _.timestamp.epoch(), }, t.state("ostate")))
33 | t.set('on', true);
34 | assert.ok(_.d.is.subset({ on: true, intensity: null }, t.state("ostate")))
35 | t.set('on', false);
36 | assert.ok(_.d.is.subset({ on: false, intensity: null }, t.state("ostate")))
37 | t.set('on', 10);
38 | assert.ok(_.d.is.subset({ on: true, intensity: null }, t.state("ostate")))
39 | t.set('on', 0);
40 | assert.ok(_.d.is.subset({ on: false, intensity: null }, t.state("ostate")))
41 | t.set('intensity', 10);
42 | assert.ok(_.d.is.subset({ on: false, intensity: 10 }, t.state("ostate")))
43 | t.set('intensity', 1);
44 | assert.ok(_.d.is.subset({ on: false, intensity: 1 }, t.state("ostate")))
45 | });
46 | /* NO MORE TRANSACTIONS
47 | it('transaction - no validation', function(){
48 | var T = model.make_model('T')
49 | .attribute(attribute.make_boolean('on').control())
50 | .make();
51 | var t = new T();
52 |
53 | // turn off validation
54 | t.start({ validate: false });
55 | assert.ok(_.is.Equal({ on: null}, t.state("ostate")))
56 | t.set('on', 1);
57 | assert.ok(_.is.Equal({ on: 1}, t.state("ostate")))
58 | t.end()
59 | assert.ok(_.is.Equal({ on: 1}, t.state("ostate")))
60 | });
61 | */
62 | /* NO MORE TRANSACTIONS
63 | it('transaction - force validation', function(){
64 | var T = model.make_model('T')
65 | .attribute(attribute.make_boolean('on').control())
66 | .make();
67 | var t = new T();
68 |
69 | // turn on validation
70 | t.start({ validate: true });
71 | assert.ok(_.is.Equal({ on: null}, t.state("ostate")))
72 | t.set('on', 1);
73 | assert.ok(_.is.Equal({ on: true}, t.state("ostate")))
74 | t.end()
75 | assert.ok(_.is.Equal({ on: true}, t.state("ostate")))
76 | });
77 | */
78 | it('set - semantic', function(){
79 | var T = model.make_model('T')
80 | .attribute(
81 | attribute.make_boolean('on')
82 | .control()
83 | .code('powered')
84 | )
85 | .make();
86 | var t = new T();
87 | t._clear_ostate = function() {};
88 |
89 | assert.strictEqual(null, t.state("ostate")['powered'])
90 | assert.ok(isNaN(t.state("ostate")['on']))
91 |
92 | t.set('powered', true)
93 | assert.strictEqual(true, t.state("ostate")['powered'])
94 |
95 | t.set('on', false)
96 | assert.strictEqual(true, t.state("ostate")['powered']) // no change
97 |
98 | t.set('iot-purpose:on', false)
99 | assert.strictEqual(false, t.state("ostate")['powered'])
100 |
101 | t.set('iot-purpose:on', true)
102 | assert.strictEqual(true, t.state("ostate")['powered'])
103 | });
104 | })
105 |
--------------------------------------------------------------------------------
/test/to-be-deleted/test_thing_setup.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_thing_setup.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2014-01-05
7 | *
8 | * Test setting up things
9 | */
10 |
11 | "use strict";
12 |
13 | var assert = require("assert")
14 | var attribute = require("./instrument/attribute")
15 | var model = require("../model")
16 | var _ = require("../helpers")
17 | var constants = require("../constants")
18 |
19 | /* --- tests --- */
20 | describe('test_thing_setup:', function(){
21 | it('constructor', function(){
22 | var T = model.make_model('T')
23 | .make();
24 | assert.ok(typeof T === "function");
25 | });
26 | it('empty setup', function(){
27 | var T = model.make_model('T')
28 | .make();
29 | var t = new T();
30 | assert.ok(_.is.Equal({ "@timestamp": _.timestamp.epoch(),}, t.state("ostate")))
31 | });
32 | it('single attribute setup', function(){
33 | var T = model.make_model('T')
34 | .attribute(attribute.make_boolean('on').control())
35 | .make();
36 | var t = new T();
37 | t._clear_ostate = function() {};
38 | assert.ok(_.d.is.subset({ on: null }, t.state("ostate")))
39 | t.set('on', true);
40 | assert.ok(_.d.is.subset({ on: true }, t.state("ostate")))
41 | t.set('on', false);
42 | assert.ok(_.d.is.subset({ on: false }, t.state("ostate")))
43 | t.set('on', 10);
44 | assert.ok(_.d.is.subset({ on: true }, t.state("ostate")))
45 | t.set('on', 0);
46 | assert.ok(_.d.is.subset({ on: false }, t.state("ostate")))
47 | });
48 | it('multiple attribute setup', function(){
49 | var T = model.make_model('T')
50 | .attribute(attribute.make_boolean('on').control())
51 | .attribute(attribute.make_number('intensity').control())
52 | .make();
53 | var t = new T();
54 | t._clear_ostate = function() {};
55 | assert.ok(_.d.is.subset({ on: null, intensity: null }, t.state("ostate")))
56 | t.set('on', true);
57 | assert.ok(_.d.is.subset({ on: true, intensity: null }, t.state("ostate")))
58 | t.set('on', false);
59 | assert.ok(_.d.is.subset({ on: false, intensity: null }, t.state("ostate")))
60 | t.set('on', 10);
61 | assert.ok(_.d.is.subset({ on: true, intensity: null }, t.state("ostate")))
62 | t.set('on', 0);
63 | assert.ok(_.d.is.subset({ on: false, intensity: null }, t.state("ostate")))
64 | t.set('intensity', 10);
65 | assert.ok(_.d.is.subset({ on: false, intensity: 10 }, t.state("ostate")))
66 | t.set('intensity', 1);
67 | assert.ok(_.d.is.subset({ on: false, intensity: 1 }, t.state("ostate")))
68 | });
69 | })
70 |
--------------------------------------------------------------------------------
/test/to-be-deleted/test_thing_validate.js:
--------------------------------------------------------------------------------
1 | /*
2 | * test_thing_validate.js
3 | *
4 | * David Janes
5 | * IOTDB
6 | * 2014-01-16
7 | *
8 | * Test validation at the Thing level
9 | */
10 |
11 | "use strict";
12 |
13 | var assert = require("assert")
14 | var attribute = require("./instrument/attribute")
15 | var model = require("../model")
16 | var _ = require("../helpers")
17 | var constants = require("../constants")
18 |
19 | /* --- tests --- */
20 | /* DPJ 2015-02-22 gone for now - we may bring this feature back */
21 | // describe('test_thing_validate', function(){
22 | // it('attribute validation', function(){
23 | // /**
24 | // * Test that attribute validation is called
25 | // * and that the return value is not
26 | // * checked against the required types
27 | // */
28 | // var AModel = model.make_model('A')
29 | // .attribute(
30 | // attribute.make_boolean('on').control()
31 | // .validator(function(paramd) {
32 | // paramd.value = 0;
33 | // })
34 | // )
35 | // .make();
36 | //
37 | // var a = new AModel();
38 | // a.set('on', false)
39 | //
40 | // assert.strictEqual(0, a.get('on'))
41 | // });
42 | // it('model validation', function(){
43 | // /**
44 | // * Test that model validation is called
45 | // * and that the return value is not
46 | // * checked against the required types
47 | // */
48 | // var AModel = model.make_model('A')
49 | // .attribute(
50 | // attribute.make_boolean('on').control()
51 | // )
52 | // .validator(function(paramd) {
53 | // paramd.changed['on'] = 0;
54 | // })
55 | // .make();
56 | //
57 | // var a = new AModel();
58 | // a.set('on', false)
59 | //
60 | // assert.strictEqual(0, a.get('on'))
61 | // });
62 | // it('model validation (broken)', function(){
63 | // /**
64 | // * Test that 'thingd' can't be used
65 | // * to alter the model's state
66 | // */
67 | // var AModel = model.make_model('A')
68 | // .attribute(
69 | // attribute.make_boolean('on').control()
70 | // )
71 | // .validator(function(paramd) {
72 | // paramd.thingd['on'] = 0;
73 | // })
74 | // .make();
75 | //
76 | // var a = new AModel();
77 | // a.set('on', false)
78 | //
79 | // assert.strictEqual(false, a.get('on'))
80 | // });
81 | // })
82 |
--------------------------------------------------------------------------------
/users.js:
--------------------------------------------------------------------------------
1 | /*
2 | * users.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2016-02-03
7 | *
8 | * Users
9 | *
10 | * Copyright [2013-2016] [David P. Janes]
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 | "use strict";
26 |
27 | /**
28 | * Users
29 | * Sorry no real docs. By default everything is open.
30 | * HomeStar changes these to do user authentication.
31 | * Transporters are the biggest clients of this interface
32 | */
33 | module.exports = {
34 | owner: function () {
35 | return null;
36 | },
37 |
38 | authorize: function (authd, callback) {
39 | return callback(null, true);
40 | },
41 | };
42 |
--------------------------------------------------------------------------------
/windows.js:
--------------------------------------------------------------------------------
1 | /*
2 | * windows.js
3 | *
4 | * David Janes
5 | * IOTDB.org
6 | * 2016-02-03
7 | *
8 | * Windows compatibility
9 | *
10 | * Copyright [2013-2016] [David P. Janes]
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 | "use strict";
26 |
27 | const setup = function () {
28 | if (!process.env.HOME && process.env.USERPROFILE) {
29 | process.env.HOME = process.env.USERPROFILE;
30 | }
31 | };
32 |
33 | /**
34 | */
35 | exports.setup = setup;
36 |
--------------------------------------------------------------------------------