thing-it-device-ecobee
Version:
[thing-it-node] Device Plugin for ecobee © products.
96 lines (82 loc) • 1.95 kB
JavaScript
module.exports = {
metadata: {
family: "electricMeter",
plugin: "electricMeter",
label: "ecobee © Smart Electric Meter",
tangible: true,
discoverable: true,
state: [{
id: "consumption",
label: "Consumption",
type: {
id: "number"
}
}],
actorTypes: [],
sensorTypes: [],
services: [],
configuration: []
},
create: function () {
return new ElectricMeter();
},
discovery: function (options) {
var discovery = new ElectricMeterDiscovery();
discovery.options = options;
return discovery;
}
};
var q = require('q');
function ElectricMeterDiscovery() {
/**
*
* @param options
*/
ElectricMeterDiscovery.prototype.start = function () {
if (this.node.isSimulated()) {
} else {
}
};
/**
*
* @param options
*/
ElectricMeterDiscovery.prototype.stop = function () {
};
}
/**
*
*/
function ElectricMeter() {
/**
*
*/
ElectricMeter.prototype.start = function () {
var deferred = q.defer();
this.state = {consumption: 0};
if (this.isSimulated()) {
setInterval(function () {
this.state.consumption = Math.floor((Math.random() * 1000));
this.state.batteryLevel = 100 - 20 * Math.floor((Math.random() * 6));
this.publishStateChange();
}.bind(this), 10000);
deferred.resolve();
} else {
deferred.resolve();
}
return deferred.promise;
};
/**
*
*/
ElectricMeter.prototype.setState = function (state) {
this.state = state;
this.publishStateChange();
};
/**
*
*/
ElectricMeter.prototype.getState = function () {
return this.state;
};
}