UNPKG

thing-it-device-spark-photon

Version:

[thing-it-node] Device Plugin for Spark Photon.

74 lines (62 loc) 1.44 kB
module.exports = { metadata: { family: "sparkPhoton", plugin: "sparkPhoton", label: "SparkPhoton", tangible: true, discoverable: false, state: [], actorTypes: [], sensorTypes: [], services: [], configuration: [] }, create: function (device) { return new SparkPhoton(); }, discovery: function (options) { var discovery = new SparkPhoton(); discovery.options = options; return discovery; } }; var q = require('q'); /** * */ function SparkPhoton() { /** * */ SparkPhoton.prototype.start = function () { var deferred = q.defer(); this.state = { switch: false, level: 0, batteryLevel: 100 }; if (this.isSimulated()) { setInterval(function () { this.state.batteryLevel = 100 - 20 * Math.floor((Math.random() * 6)); this.publishStateChange(); }.bind(this), 10000); deferred.resolve(); } else { deferred.resolve(); } return deferred.promise; }; /** * */ SparkPhoton.prototype.setState = function (state) { this.state = state; this.publishStateChange(); }; /** * */ SparkPhoton.prototype.getState = function () { return this.state; }; }