mirror of
https://github.com/mtan93/homebridge.git
synced 2026-03-08 05:31:55 +00:00
Fixes, cleanup
Got rid of old code I clearly don’t need anymore. Switched `this.log`s to `debug`s. Fix for picking wrong vDev for thermostat current temp. Added configuration for `Name` characteristic…which I guess became required.
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
"xml2js": "0.4.x",
|
||||
"xmldoc": "0.1.x",
|
||||
"yamaha-nodejs": "0.4.x",
|
||||
"teslams": "1.0.1"
|
||||
"teslams": "1.0.1",
|
||||
"debug": "^2.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
var debug = require('debug')('ZWayServer');
|
||||
var Service = require("HAP-NodeJS").Service;
|
||||
var Characteristic = require("HAP-NodeJS").Characteristic;
|
||||
var types = require("HAP-NodeJS/accessories/types.js");
|
||||
@@ -81,26 +82,6 @@ ZWayServerPlatform.getVDevServiceTypes = function(vdev){
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
ZWayServerPlatform.getVDevCharacteristicsTypes = function(vdev){
|
||||
var typeKey = ZWayServerPlatform.getVDevTypeKey(vdev);
|
||||
switch (typeKey) {
|
||||
case "switchBinary":
|
||||
return [types.POWER_STATE_CTYPE];
|
||||
case "switchMultilevel":
|
||||
return [types.POWER_STATE_CTYPE, types.BRIGHTNESS_CTYPE];
|
||||
case "thermostat":
|
||||
return [types.TARGET_TEMPERATURE_CTYPE, types.TEMPERATURE_UNITS_CTYPE, types.CURRENTHEATINGCOOLING_CTYPE, types.TARGETHEATINGCOOLING_CTYPE];
|
||||
case "sensorMultilevel.Temperature":
|
||||
return [types.CURRENT_TEMPERATURE_CTYPE, types.TEMPERATURE_UNITS_CTYPE];
|
||||
case "sensorBinary.Door/Window":
|
||||
return [types.CURRENT_DOOR_STATE_CTYPE, types.TARGET_DOORSTATE_CTYPE, types.OBSTRUCTION_DETECTED_CTYPE];
|
||||
case "battery.Battery":
|
||||
return [types.BATTERY_LEVEL_CTYPE, types.STATUS_LOW_BATTERY_CTYPE];
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
ZWayServerPlatform.prototype = {
|
||||
|
||||
zwayRequest: function(opts){
|
||||
@@ -116,7 +97,7 @@ opts.proxy = 'http://localhost:8888';
|
||||
|
||||
request(opts, function(error, response, body){
|
||||
if(response.statusCode == 401){
|
||||
that.log("Authenticating...");
|
||||
debug("Authenticating...");
|
||||
request({
|
||||
method: "POST",
|
||||
url: that.url + 'ZAutomation/api/v1/login',
|
||||
@@ -139,7 +120,7 @@ proxy: 'http://localhost:8888',
|
||||
if(response.statusCode == 200){
|
||||
that.sessionId = body.data.sid;
|
||||
opts.headers["Cookie"] = "ZWAYSession=" + that.sessionId;
|
||||
that.log("Authenticated. Resubmitting original request...");
|
||||
debug("Authenticated. Resubmitting original request...");
|
||||
request(opts, function(error, response, body){
|
||||
if(response.statusCode == 200){
|
||||
deferred.resolve(body);
|
||||
@@ -162,7 +143,7 @@ proxy: 'http://localhost:8888',
|
||||
,
|
||||
|
||||
accessories: function(callback) {
|
||||
this.log("Fetching Z-Way devices...");
|
||||
debug("Fetching Z-Way devices...");
|
||||
|
||||
var that = this;
|
||||
var foundAccessories = [];
|
||||
@@ -175,7 +156,7 @@ proxy: 'http://localhost:8888',
|
||||
var groupedDevices = {};
|
||||
for(var i = 0; i < devices.length; i++){
|
||||
var vdev = devices[i];
|
||||
if(vdev.tags.indexOf("HomeBridge:Skip") >= 0) { that.log("Tag says skip!"); continue; }
|
||||
if(vdev.tags.indexOf("HomeBridge:Skip") >= 0) { debug("Tag says skip!"); continue; }
|
||||
var gdid = vdev.id.replace(/^(.*?)_zway_(\d+-\d+)-\d.*/, '$1_$2');
|
||||
var gd = groupedDevices[gdid] || (groupedDevices[gdid] = {devices: [], types: {}, primary: undefined});
|
||||
gd.devices.push(vdev);
|
||||
@@ -187,10 +168,10 @@ proxy: 'http://localhost:8888',
|
||||
if(!groupedDevices.hasOwnProperty(gdid)) continue;
|
||||
|
||||
// Debug/log...
|
||||
that.log('Got grouped device ' + gdid + ' consiting of devices:');
|
||||
debug('Got grouped device ' + gdid + ' consiting of devices:');
|
||||
var gd = groupedDevices[gdid];
|
||||
for(var j = 0; j < gd.devices.length; j++){
|
||||
that.log(gd.devices[j].id + " - " + gd.devices[j].deviceType + (gd.devices[j].metrics && gd.devices[j].metrics.probeTitle ? "." + gd.devices[j].metrics.probeTitle : ""));
|
||||
debug(gd.devices[j].id + " - " + gd.devices[j].deviceType + (gd.devices[j].metrics && gd.devices[j].metrics.probeTitle ? "." + gd.devices[j].metrics.probeTitle : ""));
|
||||
}
|
||||
|
||||
var accessory = null;
|
||||
@@ -199,14 +180,14 @@ proxy: 'http://localhost:8888',
|
||||
gd.primary = gd.types[zwshkDeviceClasses[ti].primaryType];
|
||||
var pd = gd.devices[gd.primary];
|
||||
var name = pd.metrics && pd.metrics.title ? pd.metrics.title : pd.id;
|
||||
that.log("Using class with primaryType " + zwshkDeviceClasses[ti].primaryType + ", " + name + " (" + pd.id + ") as primary.");
|
||||
debug("Using class with primaryType " + zwshkDeviceClasses[ti].primaryType + ", " + name + " (" + pd.id + ") as primary.");
|
||||
accessory = new ZWayServerAccessory(name, zwshkDeviceClasses[ti], gd, that);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!accessory)
|
||||
that.log("WARN: Didn't find suitable device class!");
|
||||
debug("WARN: Didn't find suitable device class!");
|
||||
else
|
||||
foundAccessories.push(accessory);
|
||||
|
||||
@@ -238,360 +219,6 @@ ZWayServerAccessory.prototype = {
|
||||
qs: (value === undefined ? undefined : value)
|
||||
});
|
||||
},
|
||||
|
||||
/*
|
||||
informationCharacteristics: function() {
|
||||
return [
|
||||
{
|
||||
cType: types.NAME_CTYPE,
|
||||
onUpdate: null,
|
||||
perms: ["pr"],
|
||||
format: "string",
|
||||
initialValue: this.name,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Name of the accessory",
|
||||
designedMaxLength: 255
|
||||
},{
|
||||
cType: types.MANUFACTURER_CTYPE,
|
||||
onUpdate: null,
|
||||
perms: ["pr"],
|
||||
format: "string",
|
||||
initialValue: "Z-Wave.me",
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Manufacturer",
|
||||
designedMaxLength: 255
|
||||
},{
|
||||
cType: types.MODEL_CTYPE,
|
||||
onUpdate: null,
|
||||
perms: ["pr"],
|
||||
format: "string",
|
||||
initialValue: "VDev",
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Model",
|
||||
designedMaxLength: 255
|
||||
},{
|
||||
cType: types.SERIAL_NUMBER_CTYPE,
|
||||
onUpdate: null,
|
||||
perms: ["pr"],
|
||||
format: "string",
|
||||
initialValue: "",
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "SN",
|
||||
designedMaxLength: 255
|
||||
},{
|
||||
cType: types.IDENTIFY_CTYPE,
|
||||
onUpdate: null,
|
||||
perms: ["pw"],
|
||||
format: "bool",
|
||||
initialValue: false,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Identify Accessory",
|
||||
designedMaxLength: 1
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
controlCharacteristics: function(vdev) {
|
||||
var that = this;
|
||||
var cTypes = [];
|
||||
|
||||
var cxs = ZWayServerPlatform.getVDevCharacteristicsTypes(vdev);
|
||||
|
||||
if(!cxs || cxs.length <= 0) return cTypes;
|
||||
|
||||
if (cxs.indexOf(types.POWER_STATE_CTYPE) >= 0) {
|
||||
cTypes.push({
|
||||
cType: types.POWER_STATE_CTYPE,
|
||||
onUpdate: function(value) {
|
||||
if (value == 0) {
|
||||
that.command(vdev, "off");
|
||||
} else {
|
||||
that.command(vdev, "on");
|
||||
}
|
||||
},
|
||||
perms: ["pw","pr","ev"],
|
||||
format: "bool",
|
||||
initialValue: 0,
|
||||
supportEvents: true,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Change the power state",
|
||||
designedMaxLength: 1
|
||||
});
|
||||
}
|
||||
|
||||
if (cxs.indexOf(types.BRIGHTNESS_CTYPE) >= 0) {
|
||||
cTypes.push({
|
||||
cType: types.BRIGHTNESS_CTYPE,
|
||||
onUpdate: function(value) {
|
||||
that.command(vdev, "exact", {level: parseInt(value, 10)});
|
||||
},
|
||||
perms: ["pw","pr","ev"],
|
||||
format: "int",
|
||||
initialValue: 0,
|
||||
supportEvents: true,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Adjust Brightness of Light",
|
||||
designedMinValue: 0,
|
||||
designedMaxValue: 100,
|
||||
designedMinStep: 1,
|
||||
unit: "%"
|
||||
});
|
||||
}
|
||||
|
||||
if (cxs.indexOf(types.CURRENT_TEMPERATURE_CTYPE) >= 0) {
|
||||
cTypes.push({
|
||||
cType: types.CURRENT_TEMPERATURE_CTYPE,
|
||||
onUpdate: null,
|
||||
onRead: function(callback) {
|
||||
that.platform.zwayRequest({
|
||||
method: "GET",
|
||||
url: that.platform.url + 'ZAutomation/api/v1/devices/' + vdev.id
|
||||
}).then(function(result){
|
||||
callback(result.data.metrics.level);
|
||||
});
|
||||
},
|
||||
perms: ["pr","ev"],
|
||||
format: "int",
|
||||
initialValue: 20,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Current Temperature",
|
||||
unit: "celsius"
|
||||
});
|
||||
}
|
||||
|
||||
if (cxs.indexOf(types.TARGET_TEMPERATURE_CTYPE) >= 0) {
|
||||
cTypes.push({
|
||||
cType: types.TARGET_TEMPERATURE_CTYPE,
|
||||
onUpdate: function(value) {
|
||||
try {
|
||||
that.command(vdev, "exact", {level: parseFloat(value)});
|
||||
}
|
||||
catch (e) {
|
||||
that.log(e);
|
||||
}
|
||||
},
|
||||
onRead: function(callback) {
|
||||
that.platform.zwayRequest({
|
||||
method: "GET",
|
||||
url: that.platform.url + 'ZAutomation/api/v1/devices/' + vdev.id
|
||||
}).then(function(result){
|
||||
callback(result.data.metrics.level);
|
||||
});
|
||||
},
|
||||
perms: ["pw","pr","ev"],
|
||||
format: "int",
|
||||
initialValue: 20,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Target Temperature",
|
||||
designedMinValue: vdev.metrics && vdev.metrics.min !== undefined ? vdev.metrics.min : 5,
|
||||
designedMaxValue: vdev.metrics && vdev.metrics.max !== undefined ? vdev.metrics.max : 40,
|
||||
designedMinStep: 1,
|
||||
unit: "celsius"
|
||||
});
|
||||
}
|
||||
|
||||
if (cxs.indexOf(types.TEMPERATURE_UNITS_CTYPE) >= 0) {
|
||||
cTypes.push({
|
||||
cType: types.TEMPERATURE_UNITS_CTYPE,
|
||||
perms: ["pr"],
|
||||
format: "int",
|
||||
//TODO: Let this update from the device if it changes after startup.
|
||||
initialValue: vdev.metrics.scaleTitle.indexOf("F") >= 0 ? 1 : 0,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Unit",
|
||||
});
|
||||
}
|
||||
|
||||
if (cxs.indexOf(types.CURRENTHEATINGCOOLING_CTYPE) >= 0) {
|
||||
cTypes.push({
|
||||
cType: types.CURRENTHEATINGCOOLING_CTYPE,
|
||||
//TODO: Support multifunction thermostats...only heating supported now.
|
||||
/ *
|
||||
onUpdate: null,
|
||||
onRead: function(callback) {
|
||||
that.getCurrentHeatingCooling(function(currentHeatingCooling){
|
||||
callback(currentHeatingCooling);
|
||||
});
|
||||
},
|
||||
* /
|
||||
perms: ["pr"],
|
||||
format: "int",
|
||||
initialValue: 1,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Current Mode",
|
||||
designedMaxLength: 1,
|
||||
designedMinValue: 0,
|
||||
designedMaxValue: 2,
|
||||
designedMinStep: 1,
|
||||
});
|
||||
}
|
||||
|
||||
if (cxs.indexOf(types.TARGETHEATINGCOOLING_CTYPE) >= 0) {
|
||||
cTypes.push({
|
||||
cType: types.TARGETHEATINGCOOLING_CTYPE,
|
||||
//TODO: Support multifunction thermostats...only heating supported now.
|
||||
/ *
|
||||
onUpdate: function(value) {
|
||||
that.setTargetHeatingCooling(value);
|
||||
},
|
||||
onRead: function(callback) {
|
||||
that.getTargetHeatingCoooling(function(targetHeatingCooling){
|
||||
callback(targetHeatingCooling);
|
||||
});
|
||||
},
|
||||
* /
|
||||
perms: ["pr"],
|
||||
format: "int",
|
||||
initialValue: 0,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Target Mode",
|
||||
designedMinValue: 0,
|
||||
designedMaxValue: 3,
|
||||
designedMinStep: 1,
|
||||
});
|
||||
}
|
||||
|
||||
if (cxs.indexOf(types.CONTACT_SENSOR_STATE_CTYPE) >= 0) {
|
||||
cTypes.push({
|
||||
cType: types.CONTACT_SENSOR_STATE_CTYPE,
|
||||
onUpdate: null,
|
||||
onRead: function(callback) {
|
||||
that.platform.zwayRequest({
|
||||
method: "GET",
|
||||
url: that.platform.url + 'ZAutomation/api/v1/devices/' + vdev.id
|
||||
}).then(function(result){
|
||||
callback(result.data.metrics.level == "off" ? 1 : 0);
|
||||
});
|
||||
},
|
||||
perms: ["pr","ev"],
|
||||
format: "bool",
|
||||
initialValue: 1,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Contact State",
|
||||
designedMaxLength: 1
|
||||
});
|
||||
}
|
||||
|
||||
if (cxs.indexOf(types.CURRENT_DOOR_STATE_CTYPE) >= 0) {
|
||||
cTypes.push({
|
||||
cType: types.CURRENT_DOOR_STATE_CTYPE,
|
||||
onRead: function(callback) {
|
||||
that.platform.zwayRequest({
|
||||
method: "GET",
|
||||
url: that.platform.url + 'ZAutomation/api/v1/devices/' + vdev.id
|
||||
}).then(function(result){
|
||||
callback(result.data.metrics.level == "off" ? 1 : 0);
|
||||
});
|
||||
},
|
||||
perms: ["pr","ev"],
|
||||
format: "int",
|
||||
initialValue: 1,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Current Door State",
|
||||
designedMinValue: 0,
|
||||
designedMaxValue: 4,
|
||||
designedMinStep: 1,
|
||||
designedMaxLength: 1
|
||||
});
|
||||
}
|
||||
|
||||
if (cxs.indexOf(types.TARGET_DOORSTATE_CTYPE) >= 0) {
|
||||
cTypes.push({
|
||||
cType: types.TARGET_DOORSTATE_CTYPE,
|
||||
onRead: function(callback) {
|
||||
that.platform.zwayRequest({
|
||||
method: "GET",
|
||||
url: that.platform.url + 'ZAutomation/api/v1/devices/' + vdev.id
|
||||
}).then(function(result){
|
||||
callback(result.data.metrics.level == "off" ? 0 : 1);
|
||||
});
|
||||
},
|
||||
perms: ["pr","ev"], //TODO: If we support some non-sensor device that can actually open, add "pw"!
|
||||
format: "int",
|
||||
initialValue: 0,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Target Door State",
|
||||
designedMinValue: 0,
|
||||
designedMaxValue: 1,
|
||||
designedMinStep: 1,
|
||||
designedMaxLength: 1
|
||||
});
|
||||
}
|
||||
|
||||
if (cxs.indexOf(types.OBSTRUCTION_DETECTED_CTYPE) >= 0) {
|
||||
cTypes.push({
|
||||
cType: types.OBSTRUCTION_DETECTED_CTYPE,
|
||||
perms: ["pr","ev"],
|
||||
format: "bool",
|
||||
initialValue: false,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Obstruction Detected"
|
||||
});
|
||||
}
|
||||
|
||||
if (cxs.indexOf(types.BATTERY_LEVEL_CTYPE) >= 0) {
|
||||
cTypes.push({
|
||||
cType: types.BATTERY_LEVEL_CTYPE,
|
||||
onRead: function(callback) {
|
||||
that.platform.zwayRequest({
|
||||
method: "GET",
|
||||
url: that.platform.url + 'ZAutomation/api/v1/devices/' + vdev.id
|
||||
}).then(function(result){
|
||||
callback(result.data.metrics.level);
|
||||
});
|
||||
},
|
||||
perms: ["pr","ev"],
|
||||
format: "uint8",
|
||||
initialValue: 100,
|
||||
supportEvents: true,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Battery Level",
|
||||
designedMinValue: 0,
|
||||
designedMaxValue: 100,
|
||||
designedMinStep: 1,
|
||||
unit: "%"
|
||||
});
|
||||
}
|
||||
|
||||
if (cxs.indexOf(types.STATUS_LOW_BATTERY_CTYPE) >= 0) {
|
||||
cTypes.push({
|
||||
cType: types.STATUS_LOW_BATTERY_CTYPE,
|
||||
onUpdate: null,
|
||||
onRead: function(callback) {
|
||||
that.platform.zwayRequest({
|
||||
method: "GET",
|
||||
url: that.platform.url + 'ZAutomation/api/v1/devices/' + vdev.id
|
||||
}).then(function(result){
|
||||
callback(result.data.metrics.level <= that.platform.batteryLow ? 1 : 0);
|
||||
});
|
||||
},
|
||||
perms: ["pr","ev"],
|
||||
format: "uint8",
|
||||
initialValue: 0,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Battery is low",
|
||||
designedMaxLength: 1
|
||||
});
|
||||
}
|
||||
|
||||
return cTypes;
|
||||
},
|
||||
*/
|
||||
|
||||
getVDevServices: function(vdev){
|
||||
var typeKey = ZWayServerPlatform.getVDevTypeKey(vdev);
|
||||
@@ -647,6 +274,12 @@ ZWayServerAccessory.prototype = {
|
||||
map[(new Characteristic.ChargingState).UUID] = ["battery.Battery"]; //TODO: Always a fixed result
|
||||
}
|
||||
|
||||
if(cx instanceof Characteristic.Name) return vdevPreferred;
|
||||
|
||||
// Special case!: If cx is a CurrentTemperature, ignore the preferred device...we want the sensor if available!
|
||||
if(cx instanceof Characteristic.CurrentTemperature) vdevPreferred = null;
|
||||
//
|
||||
|
||||
var typekeys = map[cx.UUID];
|
||||
if(typekeys === undefined) return null;
|
||||
|
||||
@@ -668,19 +301,29 @@ ZWayServerAccessory.prototype = {
|
||||
var that = this;
|
||||
|
||||
var gdv = function(){
|
||||
that.log("Default value for " + vdev.metrics.title + " is " + vdev.metrics.level);
|
||||
debug("Default value for " + vdev.metrics.title + " is " + vdev.metrics.level);
|
||||
return vdev.metrics.level;
|
||||
};
|
||||
|
||||
if(cx instanceof Characteristic.Name){
|
||||
cx.getDefaultValue = function(){ return this.name; };
|
||||
cx.on('get', function(callback, context){
|
||||
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
callback(false, that.name);
|
||||
});
|
||||
cx.writable = false;
|
||||
return cx;
|
||||
}
|
||||
|
||||
if(cx instanceof Characteristic.On){
|
||||
cx.getDefaultValue = gdv;
|
||||
cx.on('get', function(callback, context){
|
||||
that.log("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
that.platform.zwayRequest({
|
||||
method: "GET",
|
||||
url: that.platform.url + 'ZAutomation/api/v1/devices/' + vdev.id
|
||||
}).then(function(result){
|
||||
that.log("Got value: " + result.data.metrics.level + ", for " + vdev.metrics.title + ".");
|
||||
debug("Got value: " + result.data.metrics.level + ", for " + vdev.metrics.title + ".");
|
||||
var val;
|
||||
if(result.data.metrics.level === "off"){
|
||||
val = false;
|
||||
@@ -703,12 +346,12 @@ ZWayServerAccessory.prototype = {
|
||||
if(cx instanceof Characteristic.Brightness){
|
||||
cx.getDefaultValue = gdv;
|
||||
cx.on('get', function(callback, context){
|
||||
that.log("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
that.platform.zwayRequest({
|
||||
method: "GET",
|
||||
url: that.platform.url + 'ZAutomation/api/v1/devices/' + vdev.id
|
||||
}).then(function(result){
|
||||
that.log("Got value " + result.data.metrics.level + " for " + vdev.metrics.title + ".");
|
||||
debug("Got value: " + result.data.metrics.level + ", for " + vdev.metrics.title + ".");
|
||||
callback(false, result.data.metrics.level);
|
||||
});
|
||||
}.bind(this));
|
||||
@@ -723,11 +366,12 @@ ZWayServerAccessory.prototype = {
|
||||
if(cx instanceof Characteristic.CurrentTemperature){
|
||||
cx.getDefaultValue = gdv;
|
||||
cx.on('get', function(callback, context){
|
||||
that.log("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
that.platform.zwayRequest({
|
||||
method: "GET",
|
||||
url: that.platform.url + 'ZAutomation/api/v1/devices/' + vdev.id
|
||||
}).then(function(result){
|
||||
debug("Got value: " + result.data.metrics.level + ", for " + vdev.metrics.title + ".");
|
||||
callback(false, result.data.metrics.level);
|
||||
});
|
||||
}.bind(this));
|
||||
@@ -739,7 +383,7 @@ ZWayServerAccessory.prototype = {
|
||||
if(cx instanceof Characteristic.TargetTemperature){
|
||||
cx.getDefaultValue = gdv;
|
||||
cx.on('get', function(callback, context){
|
||||
that.log("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
this.platform.zwayRequest({
|
||||
method: "GET",
|
||||
url: that.platform.url + 'ZAutomation/api/v1/devices/' + vdev.id
|
||||
@@ -749,6 +393,7 @@ ZWayServerAccessory.prototype = {
|
||||
}.bind(this));
|
||||
cx.on('set', function(level, callback){
|
||||
this.command(vdev, "exact", {level: parseInt(level, 10)}).then(function(result){
|
||||
debug("Got value: " + result.data.metrics.level + ", for " + vdev.metrics.title + ".");
|
||||
callback();
|
||||
});
|
||||
}.bind(this));
|
||||
@@ -761,7 +406,7 @@ ZWayServerAccessory.prototype = {
|
||||
//TODO: Always in °C for now.
|
||||
cx.getDefaultValue = function(){ return Characteristic.TemperatureDisplayUnits.CELCIUS; };
|
||||
cx.on('get', function(callback, context){
|
||||
that.log("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
callback(false, Characteristic.TemperatureDisplayUnits.CELCIUS);
|
||||
});
|
||||
cx.writable = false;
|
||||
@@ -772,7 +417,7 @@ ZWayServerAccessory.prototype = {
|
||||
//TODO: Always HEAT for now, we don't have an example to work with that supports another function.
|
||||
cx.getDefaultValue = function(){ return Characteristic.CurrentHeatingCoolingState.HEAT; };
|
||||
cx.on('get', function(callback, context){
|
||||
that.log("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
callback(false, Characteristic.CurrentHeatingCoolingState.HEAT);
|
||||
});
|
||||
return cx;
|
||||
@@ -782,7 +427,7 @@ ZWayServerAccessory.prototype = {
|
||||
//TODO: Always HEAT for now, we don't have an example to work with that supports another function.
|
||||
cx.getDefaultValue = function(){ return Characteristic.TargetHeatingCoolingState.HEAT; };
|
||||
cx.on('get', function(callback, context){
|
||||
that.log("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
callback(false, Characteristic.TargetHeatingCoolingState.HEAT);
|
||||
});
|
||||
cx.writable = false;
|
||||
@@ -794,11 +439,12 @@ ZWayServerAccessory.prototype = {
|
||||
return vdev.metrics.level == "off" ? Characteristic.CurrentDoorState.CLOSED : Characteristic.CurrentDoorState.OPEN;
|
||||
};
|
||||
cx.on('get', function(callback, context){
|
||||
that.log("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
this.platform.zwayRequest({
|
||||
method: "GET",
|
||||
url: that.platform.url + 'ZAutomation/api/v1/devices/' + vdev.id
|
||||
}).then(function(result){
|
||||
debug("Got value: " + result.data.metrics.level + ", for " + vdev.metrics.title + ".");
|
||||
callback(false, result.data.metrics.level == "off" ? Characteristic.CurrentDoorState.CLOSED : Characteristic.CurrentDoorState.OPEN);
|
||||
});
|
||||
}.bind(this));
|
||||
@@ -808,7 +454,7 @@ ZWayServerAccessory.prototype = {
|
||||
//TODO: We only support this for Door sensors now, so it's a fixed value.
|
||||
cx.getDefaultValue = function(){ return Characteristic.TargetDoorState.CLOSED; };
|
||||
cx.on('get', function(callback, context){
|
||||
that.log("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
callback(false, Characteristic.TargetDoorState.CLOSED);
|
||||
});
|
||||
//cx.readable = false;
|
||||
@@ -819,7 +465,7 @@ ZWayServerAccessory.prototype = {
|
||||
//TODO: We only support this for Door sensors now, so it's a fixed value.
|
||||
cx.getDefaultValue = function(){ return false; };
|
||||
cx.on('get', function(callback, context){
|
||||
that.log("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
callback(false, false);
|
||||
});
|
||||
//cx.readable = false;
|
||||
@@ -829,11 +475,12 @@ ZWayServerAccessory.prototype = {
|
||||
if(cx instanceof Characteristic.BatteryLevel){
|
||||
cx.getDefaultValue = gdv;
|
||||
cx.on('get', function(callback, context){
|
||||
that.log("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
that.platform.zwayRequest({
|
||||
method: "GET",
|
||||
url: that.platform.url + 'ZAutomation/api/v1/devices/' + vdev.id
|
||||
}).then(function(result){
|
||||
debug("Got value: " + result.data.metrics.level + ", for " + vdev.metrics.title + ".");
|
||||
callback(false, result.data.metrics.level);
|
||||
});
|
||||
}.bind(this));
|
||||
@@ -842,11 +489,12 @@ ZWayServerAccessory.prototype = {
|
||||
if(cx instanceof Characteristic.StatusLowBattery){
|
||||
cx.getDefaultValue = function(){ return Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL; };
|
||||
cx.on('get', function(callback, context){
|
||||
that.log("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
that.platform.zwayRequest({
|
||||
method: "GET",
|
||||
url: that.platform.url + 'ZAutomation/api/v1/devices/' + vdev.id
|
||||
}).then(function(result){
|
||||
debug("Got value: " + result.data.metrics.level + ", for " + vdev.metrics.title + ".");
|
||||
callback(false, result.data.metrics.level <= that.platform.batteryLow ? Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL);
|
||||
});
|
||||
}.bind(this));
|
||||
@@ -856,7 +504,7 @@ ZWayServerAccessory.prototype = {
|
||||
//TODO: No known chargeable devices(?), so always return false.
|
||||
cx.getDefaultValue = function(){ return Characteristic.ChargingState.NOT_CHARGING; };
|
||||
cx.on('get', function(callback, context){
|
||||
that.log("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
|
||||
callback(false, Characteristic.ChargingState.NOT_CHARGING);
|
||||
});
|
||||
//cx.readable = false;
|
||||
@@ -872,7 +520,7 @@ ZWayServerAccessory.prototype = {
|
||||
var vdev = this.getVDevForCharacteristic(cx, vdev);
|
||||
if(!vdev){
|
||||
success = false;
|
||||
this.log("ERROR! Failed to configure required characteristic \"" + service.characteristics[i].displayName + "\"!");
|
||||
debug("ERROR! Failed to configure required characteristic \"" + service.characteristics[i].displayName + "\"!");
|
||||
}
|
||||
cx = this.configureCharacteristic(cx, vdev);
|
||||
}
|
||||
@@ -881,6 +529,7 @@ ZWayServerAccessory.prototype = {
|
||||
var vdev = this.getVDevForCharacteristic(cx);
|
||||
if(!vdev) continue;
|
||||
cx = this.configureCharacteristic(cx, vdev);
|
||||
if(cx) service.addCharacteristic(cx);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
@@ -903,7 +552,7 @@ ZWayServerAccessory.prototype = {
|
||||
if(this.devDesc.types["battery.Battery"])
|
||||
services = services.concat(this.getVDevServices(this.devDesc.devices[this.devDesc.types["battery.Battery"]]));
|
||||
|
||||
this.log("Loaded services for " + this.name);
|
||||
debug("Loaded services for " + this.name);
|
||||
return services;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user