cleanup formatting

This commit is contained in:
Thomas König
2015-10-29 19:15:35 +01:00
committed by Stefan Kuper
parent b277b76c39
commit 6b36ec9dc4
2 changed files with 766 additions and 730 deletions

View File

@@ -17,14 +17,14 @@ var HomeMaticGenericChannel = require(path.resolve(__dirname, 'HomematicChannel.
function RegaRequest(log,ccuip) { function RegaRequest(log, ccuip) {
this.log = log; this.log = log;
this.ccuIP = ccuip; this.ccuIP = ccuip;
} }
RegaRequest.prototype = { RegaRequest.prototype = {
script: function (script, callback) { script: function(script, callback) {
var post_options = { var post_options = {
host: this.ccuIP, host: this.ccuIP,
@@ -40,10 +40,10 @@ RegaRequest.prototype = {
var post_req = http.request(post_options, function(res) { var post_req = http.request(post_options, function(res) {
var data = ""; var data = "";
res.setEncoding('binary'); res.setEncoding('binary');
res.on('data', function (chunk) { res.on('data', function(chunk) {
data += chunk.toString(); data += chunk.toString();
}); });
res.on('end', function () { res.on('end', function() {
var pos = data.lastIndexOf("<xml><exec>"); var pos = data.lastIndexOf("<xml><exec>");
var response = (data.substring(0, pos)); var response = (data.substring(0, pos));
callback(response); callback(response);
@@ -60,32 +60,30 @@ RegaRequest.prototype = {
}, },
getValue: function(channel,datapoint,callback) { getValue: function(channel, datapoint, callback) {
var that = this; var that = this;
var script = "var d = dom.GetObject(\""+channel+"."+datapoint+"\");if (d){Write(d.State());}"; var script = "var d = dom.GetObject(\"" + channel + "." + datapoint + "\");if (d){Write(d.State());}";
//that.log("Rega Request " + script); //that.log("Rega Request " + script);
var regarequest = this.script(script, function(data) { var regarequest = this.script(script, function(data) {
that.log("Rega Response" + data); that.log("Rega Response" + data);
if (data!=undefined) { if (data != undefined) {
callback(parseFloat(data)); callback(parseFloat(data));
} }
} });
);
}, },
setValue: function(channel,datapoint,value) { setValue: function(channel, datapoint, value) {
var that = this; var that = this;
var script = "var d = dom.GetObject(\""+channel+"."+datapoint+"\");if (d){d.State(\""+value+"\");}"; var script = "var d = dom.GetObject(\"" + channel + "." + datapoint + "\");if (d){d.State(\"" + value + "\");}";
//that.log("Rega Request " + script); //that.log("Rega Request " + script);
var regarequest = this.script(script, function(data) { var regarequest = this.script(script, function(data) {});
});
} }
} }
function HomematicRPC(log,ccuip,platform) { function HomematicRPC(log, ccuip, platform) {
this.log = log; this.log = log;
this.ccuip = ccuip; this.ccuip = ccuip;
this.platform = platform; this.platform = platform;
@@ -95,50 +93,53 @@ function HomematicRPC(log,ccuip,platform) {
this.localIP; this.localIP;
} }
HomematicRPC.prototype= { HomematicRPC.prototype = {
init:function() { init: function() {
var that = this; var that = this;
var ip = this.getIPAddress(); var ip = this.getIPAddress();
if (ip=="0.0.0.0") { if (ip == "0.0.0.0") {
that.log("Can not fetch IP"); that.log("Can not fetch IP");
return; return;
} }
this.localIP = ip; this.localIP = ip;
this.log("Local IP: "+this.localIP) this.log("Local IP: " + this.localIP)
this.server = xmlrpc.createServer({ host: this.localIP , port: 9090 }) this.server = xmlrpc.createServer({
host: this.localIP,
port: 9090
})
this.server.on('NotFound', function(method, params) { this.server.on('NotFound', function(method, params) {
that.log('Method ' + method + ' does not exist'); that.log('Method ' + method + ' does not exist');
}); });
this.server.on('system.listMethods', function (err, params, callback) { this.server.on('system.listMethods', function(err, params, callback) {
that.log('Method call params for \'system.listMethods\': ' + params) that.log('Method call params for \'system.listMethods\': ' + params)
callback(null,['system.listMethods', 'system.multicall']); callback(null, ['system.listMethods', 'system.multicall']);
}); });
this.server.on('system.multicall', function (err, params, callback) { this.server.on('system.multicall', function(err, params, callback) {
params.map(function(events) { params.map(function(events) {
try { try {
events.map(function(event){ events.map(function(event) {
if ((event["methodName"]=="event") && (event['params'] != undefined)) { if ((event["methodName"] == "event") && (event['params'] != undefined)) {
var params = event['params']; var params = event['params'];
var channel = "BidCos-RF." + params[1]; var channel = "BidCos-RF." + params[1];
var datapoint = params[2]; var datapoint = params[2];
var value = params[3]; var value = params[3];
that.platform.foundAccessories.map(function(accessory){ that.platform.foundAccessories.map(function(accessory) {
if (accessory.adress == channel) { if (accessory.adress == channel) {
accessory.event(datapoint,value); accessory.event(datapoint, value);
} }
}); });
} }
}); });
} catch(err) {} } catch (err) {}
}); });
callback(null); callback(null);
}); });
@@ -147,7 +148,7 @@ HomematicRPC.prototype= {
this.connect(); this.connect();
process.on('SIGINT', function () { process.on('SIGINT', function() {
if (that.stopping) { if (that.stopping) {
return; return;
} }
@@ -155,7 +156,7 @@ HomematicRPC.prototype= {
that.stop(); that.stop();
}); });
process.on('SIGTERM', function () { process.on('SIGTERM', function() {
if (that.stopping) { if (that.stopping) {
return; return;
} }
@@ -178,52 +179,56 @@ HomematicRPC.prototype= {
return '0.0.0.0'; return '0.0.0.0';
}, },
getValue:function(channel,datapoint,callback) { getValue: function(channel, datapoint, callback) {
var that = this; var that = this;
if (this.client == undefined) { if (this.client == undefined) {
that.log("Returning cause client is invalid"); that.log("Returning cause client is invalid");
return; return;
} }
if (channel.indexOf("BidCos-RF.")>-1) { if (channel.indexOf("BidCos-RF.") > -1)  {
channel = channel.substr(10); channel = channel.substr(10);
this.log("Calling rpc getValue"); this.log("Calling rpc getValue");
this.client.methodCall('getValue', [channel,datapoint], function (error, value) { this.client.methodCall('getValue', [channel, datapoint], function(error, value) {
callback(value); callback(value);
}); });
return; return;
} }
}, },
setValue:function(channel,datapoint,value) { setValue: function(channel, datapoint, value) {
var that = this; var that = this;
if (this.client == undefined) return; if (this.client == undefined) return;
if (channel.indexOf("BidCos-RF.")>-1) { if (channel.indexOf("BidCos-RF.") > -1)  {
channel = channel.substr(10); channel = channel.substr(10);
} }
this.client.methodCall('setValue', [channel,datapoint,value], function (error, value) { this.client.methodCall('setValue', [channel, datapoint, value], function(error, value) {
}); });
}, },
connect:function(){ connect: function() {
var that = this; var that = this;
this.log('Creating Local HTTP Client for CCU RPC Events'); this.log('Creating Local HTTP Client for CCU RPC Events');
this.client = xmlrpc.createClient({ host: this.ccuip, port: 2001, path: '/'}); this.client = xmlrpc.createClient({
host: this.ccuip,
port: 2001,
path: '/'
});
this.log('CCU RPC Init Call on port 2001'); this.log('CCU RPC Init Call on port 2001');
this.client.methodCall('init', ['http://'+this.localIP+':9090','homebridge'], function (error, value) { this.client.methodCall('init', ['http://' + this.localIP + ':9090', 'homebridge'], function(error, value) {
that.log('CCU Response ....') that.log('CCU Response ....')
}); });
}, },
stop:function() { stop: function() {
this.log("Removing Event Server"); this.log("Removing Event Server");
this.client.methodCall('init', ['http://'+this.localIP+':9090'], function (error, value) { this.client.methodCall('init', ['http://' + this.localIP + ':9090'], function(error, value) {
}); });
setTimeout(process.exit(0), 1000); setTimeout(process.exit(0), 1000);
@@ -245,7 +250,7 @@ function HomeMaticPlatform(log, config) {
this.foundAccessories = []; this.foundAccessories = [];
this.adressesToQuery = []; this.adressesToQuery = [];
this.xmlrpc = new HomematicRPC(this.log,this.ccuIP,this); this.xmlrpc = new HomematicRPC(this.log, this.ccuIP, this);
this.xmlrpc.init(); this.xmlrpc.init();
} }
@@ -260,7 +265,7 @@ HomeMaticPlatform.prototype = {
var script = "string sDeviceId;string sChannelId;boolean df = true;Write(\'{\"devices\":[\');foreach(sDeviceId, root.Devices().EnumIDs()){object oDevice = dom.GetObject(sDeviceId);if(oDevice){var oInterface = dom.GetObject(oDevice.Interface());if(df) {df = false;} else { Write(\',\');}Write(\'{\');Write(\'\"id\": \"\' # sDeviceId # \'\",\');Write(\'\"name\": \"\' # oDevice.Name() # \'\",\');Write(\'\"address\": \"\' # oDevice.Address() # \'\",\');Write(\'\"channels\": [\');boolean bcf = true;foreach(sChannelId, oDevice.Channels().EnumIDs()){object oChannel = dom.GetObject(sChannelId);if(bcf) {bcf = false;} else {Write(\',\');}Write(\'{\');Write(\'\"cId\": \' # sChannelId # \',\');Write(\'\"name\": \"\' # oChannel.Name() # \'\",\');if(oInterface){Write(\'\"address\": \"\' # oInterface.Name() #\'.'\ # oChannel.Address() # \'\",\');}Write(\'\"type\": \"\' # oChannel.HssType() # \'\"\');Write(\'}\');}Write(\']}\');}}Write(\']}\');"; var script = "string sDeviceId;string sChannelId;boolean df = true;Write(\'{\"devices\":[\');foreach(sDeviceId, root.Devices().EnumIDs()){object oDevice = dom.GetObject(sDeviceId);if(oDevice){var oInterface = dom.GetObject(oDevice.Interface());if(df) {df = false;} else { Write(\',\');}Write(\'{\');Write(\'\"id\": \"\' # sDeviceId # \'\",\');Write(\'\"name\": \"\' # oDevice.Name() # \'\",\');Write(\'\"address\": \"\' # oDevice.Address() # \'\",\');Write(\'\"channels\": [\');boolean bcf = true;foreach(sChannelId, oDevice.Channels().EnumIDs()){object oChannel = dom.GetObject(sChannelId);if(bcf) {bcf = false;} else {Write(\',\');}Write(\'{\');Write(\'\"cId\": \' # sChannelId # \',\');Write(\'\"name\": \"\' # oChannel.Name() # \'\",\');if(oInterface){Write(\'\"address\": \"\' # oInterface.Name() #\'.'\ # oChannel.Address() # \'\",\');}Write(\'\"type\": \"\' # oChannel.HssType() # \'\"\');Write(\'}\');}Write(\']}\');}}Write(\']}\');";
var regarequest = new RegaRequest(this.log,this.ccuIP).script(script, function(data) { var regarequest = new RegaRequest(this.log, this.ccuIP).script(script, function(data) {
var json = JSON.parse(data); var json = JSON.parse(data);
if (json['devices'] != undefined) { if (json['devices'] != undefined) {
json['devices'].map(function(device) { json['devices'].map(function(device) {
@@ -286,14 +291,11 @@ HomeMaticPlatform.prototype = {
// that.log('name', ch.name, ' -> address:', ch.address); // that.log('name', ch.name, ' -> address:', ch.address);
if ((ch.address != undefined) && (!isChannelFiltered)) { if ((ch.address != undefined) && (!isChannelFiltered)) {
if ((ch.type=="SWITCH") || (ch.type=="BLIND") || (ch.type=="SHUTTER_CONTACT") if ((ch.type == "SWITCH") || (ch.type == "BLIND") || (ch.type == "SHUTTER_CONTACT") || (ch.type == "DIMMER") || (ch.type == "CLIMATECONTROL_RT_TRANSCEIVER") ||  (ch.type == "MOTION_DETECTOR") ||  (ch.type == "KEYMATIC")) {
|| (ch.type=="DIMMER") || (ch.type=="CLIMATECONTROL_RT_TRANSCEIVER")
|| (ch.type=="MOTION_DETECTOR") || (ch.type=="KEYMATIC")
) {
// Switch found // Switch found
// Check if marked as Outlet // Check if marked as Outlet
var special = (that.outlets.indexOf(ch.address) > -1) ? 'OUTLET' : undefined; var special = (that.outlets.indexOf(ch.address) > -1) ? 'OUTLET' : undefined;
accessory = new HomeMaticGenericChannel(that.log, that, ch.id , ch.name , ch.type , ch.address, special); accessory = new HomeMaticGenericChannel(that.log, that, ch.id, ch.name, ch.type, ch.address, special);
that.foundAccessories.push(accessory); that.foundAccessories.push(accessory);
} }
@@ -309,7 +311,7 @@ HomeMaticPlatform.prototype = {
}); });
/* /*
accessory = new HomeMaticGenericChannel(that.log, that, "1234" , "DummyKM" , "KEYMATIC" , "1234"); accessory = new HomeMaticGenericChannel(that.log, that, "1234" , "DummyKM" , "KEYMATIC" , "1234");
that.foundAccessories.push(accessory); that.foundAccessories.push(accessory);
@@ -325,37 +327,37 @@ HomeMaticPlatform.prototype = {
}, },
setValue:function(channel,datapoint,value) { setValue: function(channel, datapoint, value) {
if (channel.indexOf("BidCos-RF.")>-1) { if (channel.indexOf("BidCos-RF.") > -1)  {
this.xmlrpc.setValue(channel,datapoint,value); this.xmlrpc.setValue(channel, datapoint, value);
return; return;
} }
if (channel.indexOf("VirtualDevices.")>-1) { if (channel.indexOf("VirtualDevices.") > -1)  {
var rega = new RegaRequest(this.log,this.ccuIP); var rega = new RegaRequest(this.log, this.ccuIP);
rega.setValue(channel,datapoint,value); rega.setValue(channel, datapoint, value);
return; return;
} }
}, },
getValue:function(channel,datapoint,callback) { getValue: function(channel, datapoint, callback) {
if (channel.indexOf("BidCos-RF.")>-1) { if (channel.indexOf("BidCos-RF.") > -1)  {
this.xmlrpc.getValue(channel,datapoint,callback); this.xmlrpc.getValue(channel, datapoint, callback);
return; return;
} }
if (channel.indexOf("VirtualDevices.")>-1) { if (channel.indexOf("VirtualDevices.") > -1)  {
var rega = new RegaRequest(this.log,this.ccuIP); var rega = new RegaRequest(this.log, this.ccuIP);
rega.getValue(channel,datapoint,callback); rega.getValue(channel, datapoint, callback);
return; return;
} }
}, },
prepareRequest: function(accessory,script) { prepareRequest: function(accessory, script) {
var that = this; var that = this;
this.sendQueue.push(script); this.sendQueue.push(script);
that.delayed(100); that.delayed(100);
@@ -369,13 +371,12 @@ HomeMaticPlatform.prototype = {
}); });
this.sendQueue = []; this.sendQueue = [];
//this.log("RegaSend: " + script); //this.log("RegaSend: " + script);
var regarequest = new RegaRequest(this.log,this.ccuIP).script(script, function(data) { var regarequest = new RegaRequest(this.log, this.ccuIP).script(script, function(data) {});
});
}, },
sendRequest: function(accessory,script,callback) { sendRequest: function(accessory, script, callback) {
var that = this; var that = this;
var regarequest = new RegaRequest(this.log,this.ccuIP).script(script, function(data) { var regarequest = new RegaRequest(this.log, this.ccuIP).script(script, function(data) {
if (data != undefined) { if (data != undefined) {
try { try {
var json = JSON.parse(data); var json = JSON.parse(data);
@@ -390,13 +391,16 @@ HomeMaticPlatform.prototype = {
delayed: function(delay) { delayed: function(delay) {
var timer = this.delayed[delay]; var timer = this.delayed[delay];
if( timer ) { if (timer) {
this.log("removing old command"); this.log("removing old command");
clearTimeout( timer ); clearTimeout(timer);
} }
var that = this; var that = this;
this.delayed[delay] = setTimeout( function(){clearTimeout(that.delayed[delay]);that.sendPreparedRequests()}, delay?delay:100); this.delayed[delay] = setTimeout(function() {
clearTimeout(that.delayed[delay]);
that.sendPreparedRequests()
}, delay ? delay : 100);
this.log("New Timer was set"); this.log("New Timer was set");
} }
} }

View File

@@ -1,7 +1,7 @@
var types = require("hap-nodejs/accessories/types.js"); var types = require("hap-nodejs/accessories/types.js");
function HomeMaticGenericChannel(log,platform, id ,name, type ,adress,special) { function HomeMaticGenericChannel(log, platform, id, name, type, adress, special) {
this.name = name; this.name = name;
this.type = type; this.type = type;
this.adress = adress; this.adress = adress;
@@ -16,110 +16,111 @@ function HomeMaticGenericChannel(log,platform, id ,name, type ,adress,special) {
HomeMaticGenericChannel.prototype = { HomeMaticGenericChannel.prototype = {
// Return current States // Return current States
query: function(dp,callback) { query: function(dp, callback) {
var that = this; var that = this;
if (this.state[dp] != undefined) { if (this.state[dp] != undefined) {
callback(this.state[dp]); callback(this.state[dp]);
} else { } else {
// that.log("No cached Value found start fetching and send temp 0 back"); // that.log("No cached Value found start fetching and send temp 0 back");
this.remoteGetValue(dp); this.remoteGetValue(dp);
callback(0); callback(0);
} }
}, },
dpvalue:function(dp,fallback) { dpvalue: function(dp, fallback) {
if (this.state[dp] != undefined) { if (this.state[dp] != undefined) {
return(this.state[dp]); return (this.state[dp]);
} else { } else {
return fallback; return fallback;
} }
}, },
remoteGetValue:function(dp) { remoteGetValue: function(dp) {
var that = this; var that = this;
that.platform.getValue(that.adress,dp,function(newValue) { that.platform.getValue(that.adress, dp, function(newValue) {
that.log("Remote Value Response for " + that.adress + "." + dp + "->" + newValue); that.log("Remote Value Response for " + that.adress + "." + dp + "->" + newValue);
that.eventupdate = true; that.eventupdate = true;
that.cache(dp,newValue); that.cache(dp, newValue);
that.eventupdate = false; that.eventupdate = false;
}); });
}, },
event:function(dp,newValue) { event: function(dp, newValue) {
if (dp=="LEVEL") { if (dp == "LEVEL") {
newValue = newValue*100; newValue = newValue * 100;
} }
this.eventupdate = true; this.eventupdate = true;
this.cache(dp,newValue); this.cache(dp, newValue);
this.eventupdate = false; this.eventupdate = false;
}, },
reverse:function(value) { reverse: function(value) {
if (value=="true") return "false"; if (value == "true") return "false";
if (value=="false") return "true"; if (value == "false") return "true";
if (value==0) return 1; if (value == 0) return 1;
if (value==1) return 0; if (value == 1) return 0;
if (value=="0") return "1"; if (value == "0") return "1";
if (value=="1") return "0"; if (value == "1") return "0";
return value; return value;
}, },
cache:function(dp,value) { cache: function(dp, value) {
var that = this; var that = this;
if ((that.reverseDP[dp]!=undefined) && (that.reverseDP[dp]==true)) { if ((that.reverseDP[dp] != undefined) && (that.reverseDP[dp] == true)) {
value = that.reverse(value); value = that.reverse(value);
} }
if (that.currentStateCharacteristic[dp]!=undefined) { if (that.currentStateCharacteristic[dp] != undefined) {
that.currentStateCharacteristic[dp].updateValue(value, null); that.currentStateCharacteristic[dp].updateValue(value, null);
} }
this.state[dp] = value; this.state[dp] = value;
}, },
delayed: function(mode, dp,value,delay) { delayed: function(mode, dp, value, delay) {
if (this.eventupdate==true) { if (this.eventupdate == true) {
return; return;
} }
var timer = this.delayed[delay]; var timer = this.delayed[delay];
if( timer ) { if (timer) {
clearTimeout( timer ); clearTimeout(timer);
} }
this.log(this.name + " delaying command "+mode + " " + dp +" with value " + value); this.log(this.name + " delaying command " + mode + " " + dp + " with value " + value);
var that = this; var that = this;
this.delayed[delay] = setTimeout( function(){clearTimeout(that.delayed[delay]);that.command(mode,dp,value)}, delay?delay:100 ); this.delayed[delay] = setTimeout(function() {
clearTimeout(that.delayed[delay]);
that.command(mode, dp, value)
}, delay ? delay : 100);
}, },
command: function(mode,dp,value,callback) { command: function(mode, dp, value, callback) {
if (this.eventupdate==true) { if (this.eventupdate == true) {
return; return;
} }
var that = this; var that = this;
if (mode == "set") { if (mode == "set") {
//this.log("Send " + value + " to Datapoint " + dp + " at " + that.adress); //this.log("Send " + value + " to Datapoint " + dp + " at " + that.adress);
that.platform.setValue(that.adress,dp,value); that.platform.setValue(that.adress, dp, value);
} }
}, },
informationCharacteristics: function() { informationCharacteristics: function() {
return [ return [{
{
cType: types.NAME_CTYPE, cType: types.NAME_CTYPE,
onUpdate: null, onUpdate: null,
perms: ["pr"], perms: ["pr"],
@@ -129,7 +130,7 @@ HomeMaticGenericChannel.prototype = {
supportBonjour: false, supportBonjour: false,
manfDescription: "Name of the accessory", manfDescription: "Name of the accessory",
designedMaxLength: 255 designedMaxLength: 255
},{ }, {
cType: types.MANUFACTURER_CTYPE, cType: types.MANUFACTURER_CTYPE,
onUpdate: null, onUpdate: null,
perms: ["pr"], perms: ["pr"],
@@ -139,7 +140,7 @@ HomeMaticGenericChannel.prototype = {
supportBonjour: false, supportBonjour: false,
manfDescription: "Manufacturer", manfDescription: "Manufacturer",
designedMaxLength: 255 designedMaxLength: 255
},{ }, {
cType: types.MODEL_CTYPE, cType: types.MODEL_CTYPE,
onUpdate: null, onUpdate: null,
perms: ["pr"], perms: ["pr"],
@@ -149,17 +150,17 @@ HomeMaticGenericChannel.prototype = {
supportBonjour: false, supportBonjour: false,
manfDescription: "Model", manfDescription: "Model",
designedMaxLength: 255 designedMaxLength: 255
},{ }, {
cType: types.SERIAL_NUMBER_CTYPE, cType: types.SERIAL_NUMBER_CTYPE,
onUpdate: null, onUpdate: null,
perms: ["pr"], perms: ["pr"],
format: "string", format: "string",
initialValue: this.adress , initialValue: this.adress,
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "SN", manfDescription: "SN",
designedMaxLength: 255 designedMaxLength: 255
},{ }, {
cType: types.IDENTIFY_CTYPE, cType: types.IDENTIFY_CTYPE,
onUpdate: null, onUpdate: null,
perms: ["pw"], perms: ["pw"],
@@ -169,8 +170,7 @@ HomeMaticGenericChannel.prototype = {
supportBonjour: false, supportBonjour: false,
manfDescription: "Identify Accessory", manfDescription: "Identify Accessory",
designedMaxLength: 1 designedMaxLength: 1
} }]
]
}, },
controlCharacteristics: function(that) { controlCharacteristics: function(that) {
@@ -188,15 +188,15 @@ HomeMaticGenericChannel.prototype = {
}] }]
if (this.type=="SWITCH") { if (this.type == "SWITCH") {
cTypes.push({ cTypes.push({
cType: types.POWER_STATE_CTYPE, cType: types.POWER_STATE_CTYPE,
onUpdate: function(value) { onUpdate: function(value) {
that.command("set","STATE" , (value==1)?true:false) that.command("set", "STATE", (value == 1) ? true : false)
}, },
onRead: function(callback) { onRead: function(callback) {
that.query("STATE",callback); that.query("STATE", callback);
}, },
onRegister: function(characteristic) { onRegister: function(characteristic) {
@@ -205,23 +205,23 @@ HomeMaticGenericChannel.prototype = {
that.remoteGetValue("STATE"); that.remoteGetValue("STATE");
}, },
perms: ["pw","pr","ev"], perms: ["pw", "pr", "ev"],
format: "bool", format: "bool",
initialValue: that.dpvalue("STATE",0), initialValue: that.dpvalue("STATE", 0),
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "Change the power state", manfDescription: "Change the power state",
designedMaxLength: 1 designedMaxLength: 1
}); });
if (this.special=="OUTLET") { if (this.special == "OUTLET") {
cTypes.push({ cTypes.push({
cType: types.OUTLET_IN_USE_CTYPE, cType: types.OUTLET_IN_USE_CTYPE,
onRead: function(callback) { onRead: function(callback) {
callback(true); callback(true);
}, },
perms: ["pr","ev"], perms: ["pr", "ev"],
format: "bool", format: "bool",
initialValue: true, initialValue: true,
supportEvents: false, supportEvents: false,
@@ -233,13 +233,12 @@ HomeMaticGenericChannel.prototype = {
} }
if (this.type=="KEYMATIC") { if (this.type == "KEYMATIC") {
cTypes.push( cTypes.push({
{
cType: types.CURRENT_LOCK_MECHANISM_STATE_CTYPE, cType: types.CURRENT_LOCK_MECHANISM_STATE_CTYPE,
onRead: function(callback) { onRead: function(callback) {
that.query("STATE",callback); that.query("STATE", callback);
}, },
onRegister: function(characteristic) { onRegister: function(characteristic) {
@@ -248,23 +247,22 @@ HomeMaticGenericChannel.prototype = {
that.remoteGetValue("STATE"); that.remoteGetValue("STATE");
}, },
perms: ["pr","ev"], perms: ["pr", "ev"],
format: "bool", format: "bool",
initialValue: that.dpvalue("STATE",0), initialValue: that.dpvalue("STATE", 0),
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "Current State of your Lock", manfDescription: "Current State of your Lock",
designedMaxLength: 1 designedMaxLength: 1
}, }, {
{
cType: types.TARGET_LOCK_MECHANISM_STATE_CTYPE, cType: types.TARGET_LOCK_MECHANISM_STATE_CTYPE,
onUpdate: function(value) { onUpdate: function(value) {
that.command("set","STATE",(value==1)?"true":"false") that.command("set", "STATE", (value == 1) ? "true" : "false")
}, },
onRead: function(callback) { onRead: function(callback) {
that.query("STATE",callback); that.query("STATE", callback);
}, },
onRegister: function(characteristic) { onRegister: function(characteristic) {
@@ -275,21 +273,20 @@ HomeMaticGenericChannel.prototype = {
}, },
perms: ["pw","pr","ev"], perms: ["pw", "pr", "ev"],
format: "bool", format: "bool",
initialValue: that.dpvalue("STATE",0), initialValue: that.dpvalue("STATE", 0),
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "Target State of your Lock", manfDescription: "Target State of your Lock",
designedMaxLength: 1 designedMaxLength: 1
} }
, , {
{
cType: types.TARGET_DOORSTATE_CTYPE, cType: types.TARGET_DOORSTATE_CTYPE,
onUpdate: function(value) { onUpdate: function(value) {
that.command("set","OPEN" , "true") that.command("set", "OPEN", "true")
}, },
onRead: function(callback) { onRead: function(callback) {
@@ -301,7 +298,7 @@ HomeMaticGenericChannel.prototype = {
characteristic.eventEnabled = true; characteristic.eventEnabled = true;
}, },
perms: ["pw","pr","ev"], perms: ["pw", "pr", "ev"],
format: "bool", format: "bool",
initialValue: 1, initialValue: 1,
supportEvents: false, supportEvents: false,
@@ -316,15 +313,15 @@ HomeMaticGenericChannel.prototype = {
if (this.type=="DIMMER") { if (this.type == "DIMMER") {
cTypes.push({ cTypes.push({
cType: types.POWER_STATE_CTYPE, cType: types.POWER_STATE_CTYPE,
onUpdate: function(value) { onUpdate: function(value) {
that.command("set","LEVEL" , (value==true) ? "1" : "0") that.command("set", "LEVEL", (value == true) ? "1" : "0")
}, },
onRead: function(callback) { onRead: function(callback) {
that.query("LEVEL",callback); that.query("LEVEL", callback);
}, },
onRegister: function(characteristic) { onRegister: function(characteristic) {
@@ -333,22 +330,21 @@ HomeMaticGenericChannel.prototype = {
that.remoteGetValue("LEVEL"); that.remoteGetValue("LEVEL");
}, },
perms: ["pw","pr","ev"], perms: ["pw", "pr", "ev"],
format: "bool", format: "bool",
initialValue: (that.dpvalue("LEVEL")>0,0), initialValue: (that.dpvalue("LEVEL") > 0, 0),
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "Change the power state", manfDescription: "Change the power state",
designedMaxLength: 1 designedMaxLength: 1
}, }, {
{
cType: types.BRIGHTNESS_CTYPE, cType: types.BRIGHTNESS_CTYPE,
onUpdate: function(value) { onUpdate: function(value) {
that.delayed("set","LEVEL" , String(value/100),100); that.delayed("set", "LEVEL", String(value / 100), 100);
}, },
onRead: function(callback) { onRead: function(callback) {
that.query("LEVEL",callback); that.query("LEVEL", callback);
}, },
onRegister: function(characteristic) { onRegister: function(characteristic) {
@@ -358,9 +354,9 @@ HomeMaticGenericChannel.prototype = {
}, },
perms: ["pw","pr","ev"], perms: ["pw", "pr", "ev"],
format: "int", format: "int",
initialValue: that.dpvalue("LEVEL",0), initialValue: that.dpvalue("LEVEL", 0),
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "Adjust Brightness of Light", manfDescription: "Adjust Brightness of Light",
@@ -371,13 +367,12 @@ HomeMaticGenericChannel.prototype = {
}); });
} }
if (this.type=="BLIND") { if (this.type == "BLIND") {
cTypes.push( cTypes.push({
{
cType: types.WINDOW_COVERING_CURRENT_POSITION_CTYPE, cType: types.WINDOW_COVERING_CURRENT_POSITION_CTYPE,
onRead: function(callback) { onRead: function(callback) {
that.query("LEVEL",callback); that.query("LEVEL", callback);
}, },
onRegister: function(characteristic) { onRegister: function(characteristic) {
@@ -386,9 +381,9 @@ HomeMaticGenericChannel.prototype = {
that.remoteGetValue("LEVEL"); that.remoteGetValue("LEVEL");
}, },
perms: ["pr","ev"], perms: ["pr", "ev"],
format: "int", format: "int",
initialValue: that.dpvalue("LEVEL",0), initialValue: that.dpvalue("LEVEL", 0),
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "Current Blind Position", manfDescription: "Current Blind Position",
@@ -402,12 +397,12 @@ HomeMaticGenericChannel.prototype = {
cType: types.WINDOW_COVERING_TARGET_POSITION_CTYPE, cType: types.WINDOW_COVERING_TARGET_POSITION_CTYPE,
onUpdate: function(value) { onUpdate: function(value) {
that.delayed("set","LEVEL" , String(value/100),100); that.delayed("set", "LEVEL", String(value / 100), 100);
}, },
onRead: function(callback) { onRead: function(callback) {
that.query("LEVEL",callback); that.query("LEVEL", callback);
}, },
onRegister: function(characteristic) { onRegister: function(characteristic) {
@@ -416,9 +411,9 @@ HomeMaticGenericChannel.prototype = {
that.remoteGetValue("LEVEL"); that.remoteGetValue("LEVEL");
}, },
perms: ["pw","pr","ev"], perms: ["pw", "pr", "ev"],
format: "int", format: "int",
initialValue: that.dpvalue("LEVEL",0), initialValue: that.dpvalue("LEVEL", 0),
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "Target Blind Position", manfDescription: "Target Blind Position",
@@ -426,12 +421,11 @@ HomeMaticGenericChannel.prototype = {
designedMaxValue: 100, designedMaxValue: 100,
designedMinStep: 1, designedMinStep: 1,
unit: "%" unit: "%"
}, }, {
{
cType: types.WINDOW_COVERING_OPERATION_STATE_CTYPE, cType: types.WINDOW_COVERING_OPERATION_STATE_CTYPE,
onRead: function(callback) { onRead: function(callback) {
that.query("DIRECTION",callback); that.query("DIRECTION", callback);
}, },
onRegister: function(characteristic) { onRegister: function(characteristic) {
@@ -440,9 +434,9 @@ HomeMaticGenericChannel.prototype = {
that.remoteGetValue("DIRECTION"); that.remoteGetValue("DIRECTION");
}, },
perms: ["pr","ev"], perms: ["pr", "ev"],
format: "int", format: "int",
initialValue: that.dpvalue("DIRECTION",0), initialValue: that.dpvalue("DIRECTION", 0),
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "Operating State ", manfDescription: "Operating State ",
@@ -454,13 +448,12 @@ HomeMaticGenericChannel.prototype = {
); );
} }
if (this.type=="SHUTTER_CONTACT") { if (this.type == "SHUTTER_CONTACT") {
cTypes.push( cTypes.push({
{
cType: types.CONTACT_SENSOR_STATE_CTYPE, cType: types.CONTACT_SENSOR_STATE_CTYPE,
onRead: function(callback) { onRead: function(callback) {
that.query("STATE",callback); that.query("STATE", callback);
}, },
onRegister: function(characteristic) { onRegister: function(characteristic) {
@@ -469,22 +462,21 @@ HomeMaticGenericChannel.prototype = {
that.remoteGetValue("STATE"); that.remoteGetValue("STATE");
}, },
perms: ["pr","ev"], perms: ["pr", "ev"],
format: "bool", format: "bool",
initialValue: that.dpvalue("STATE",0), initialValue: that.dpvalue("STATE", 0),
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "Current State" manfDescription: "Current State"
}); });
} }
if (this.type=="MOTION_DETECTOR") { if (this.type == "MOTION_DETECTOR") {
cTypes.push( cTypes.push({
{
cType: types.MOTION_DETECTED_CTYPE, cType: types.MOTION_DETECTED_CTYPE,
onRead: function(callback) { onRead: function(callback) {
that.query("MOTION",callback); that.query("MOTION", callback);
}, },
onRegister: function(characteristic) { onRegister: function(characteristic) {
@@ -493,32 +485,56 @@ HomeMaticGenericChannel.prototype = {
that.remoteGetValue("MOTION"); that.remoteGetValue("MOTION");
}, },
perms: ["pr","ev"], perms: ["pr", "ev"],
format: "bool", format: "bool",
initialValue: that.dpvalue("MOTION",0), initialValue: that.dpvalue("MOTION", 0),
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "Current Motion State" manfDescription: "Current Motion State"
}); });
} }
if (this.type=="CLIMATECONTROL_RT_TRANSCEIVER") { if (this.type == "CLIMATECONTROL_RT_TRANSCEIVER") {
cTypes.push({ cTypes.push({
cType: types.NAME_CTYPE,onUpdate: null,perms: ["pr"],format: "string", cType: types.NAME_CTYPE,
initialValue: this.name,supportEvents: true,supportBonjour: false,manfDescription: "Name of service",designedMaxLength: 255 onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: this.name,
supportEvents: true,
supportBonjour: false,
manfDescription: "Name of service",
designedMaxLength: 255
}, },
{ {
cType: types.CURRENTHEATINGCOOLING_CTYPE,onUpdate: null, cType: types.CURRENTHEATINGCOOLING_CTYPE,
perms: ["pr"],format: "int",initialValue: 1,supportEvents: false, onUpdate: null,
supportBonjour: false,manfDescription: "Current Mode",designedMaxLength: 1,designedMinValue: 1,designedMaxValue: 1,designedMinStep: 1 perms: ["pr"],
format: "int",
initialValue: 1,
supportEvents: false,
supportBonjour: false,
manfDescription: "Current Mode",
designedMaxLength: 1,
designedMinValue: 1,
designedMaxValue: 1,
designedMinStep: 1
}, },
{ {
cType: types.TARGETHEATINGCOOLING_CTYPE,onUpdate: null,perms: ["pw","pr"], cType: types.TARGETHEATINGCOOLING_CTYPE,
format: "int",initialValue: 1,supportEvents: false,supportBonjour: false,manfDescription: "Target Mode", onUpdate: null,
designedMinValue: 1,designedMaxValue: 1,designedMinStep: 1 perms: ["pw", "pr"],
format: "int",
initialValue: 1,
supportEvents: false,
supportBonjour: false,
manfDescription: "Target Mode",
designedMinValue: 1,
designedMaxValue: 1,
designedMinStep: 1
}, },
{ {
@@ -526,7 +542,7 @@ HomeMaticGenericChannel.prototype = {
onUpdate: null, onUpdate: null,
onRead: function(callback) { onRead: function(callback) {
that.query("ACTUAL_TEMPERATURE",callback); that.query("ACTUAL_TEMPERATURE", callback);
}, },
onRegister: function(characteristic) { onRegister: function(characteristic) {
@@ -534,18 +550,23 @@ HomeMaticGenericChannel.prototype = {
characteristic.eventEnabled = true; characteristic.eventEnabled = true;
that.remoteGetValue("ACTUAL_TEMPERATURE"); that.remoteGetValue("ACTUAL_TEMPERATURE");
}, },
perms: ["pw","pr","ev"], perms: ["pr"],format: "double", perms: ["pw", "pr", "ev"],
initialValue: that.dpvalue("ACTUAL_TEMPERATURE",20), perms: ["pr"],
supportEvents: false,supportBonjour: false,manfDescription: "Current Temperature",unit: "celsius" format: "double",
initialValue: that.dpvalue("ACTUAL_TEMPERATURE", 20),
supportEvents: false,
supportBonjour: false,
manfDescription: "Current Temperature",
unit: "celsius"
}, },
{ {
cType: types.TARGET_TEMPERATURE_CTYPE, cType: types.TARGET_TEMPERATURE_CTYPE,
onUpdate: function(value) { onUpdate: function(value) {
that.delayed("set", "SET_TEMPERATURE", value,500); that.delayed("set", "SET_TEMPERATURE", value, 500);
}, },
onRead: function(callback) { onRead: function(callback) {
that.query("SET_TEMPERATURE",callback); that.query("SET_TEMPERATURE", callback);
}, },
onRegister: function(characteristic) { onRegister: function(characteristic) {
@@ -553,16 +574,28 @@ HomeMaticGenericChannel.prototype = {
characteristic.eventEnabled = true; characteristic.eventEnabled = true;
that.remoteGetValue("SET_TEMPERATURE"); that.remoteGetValue("SET_TEMPERATURE");
}, },
perms: ["pw","pr","ev"],format: "double", perms: ["pw", "pr", "ev"],
initialValue: that.dpvalue("SET_TEMPERATURE",16), format: "double",
supportEvents: false,supportBonjour: false, manfDescription: "Target Temperature", initialValue: that.dpvalue("SET_TEMPERATURE", 16),
designedMinValue: 16,designedMaxValue: 38,designedMinStep: 1,unit: "celsius" supportEvents: false,
supportBonjour: false,
manfDescription: "Target Temperature",
designedMinValue: 16,
designedMaxValue: 38,
designedMinStep: 1,
unit: "celsius"
}, },
{ {
cType: types.TEMPERATURE_UNITS_CTYPE,onRead: null, cType: types.TEMPERATURE_UNITS_CTYPE,
perms: ["pr"],format: "int",initialValue: 0,supportEvents: false, onRead: null,
supportBonjour: false,manfDescription: "Current Temperature Unit",unit: "celsius" perms: ["pr"],
format: "int",
initialValue: 0,
supportEvents: false,
supportBonjour: false,
manfDescription: "Current Temperature Unit",
unit: "celsius"
} }
); );
@@ -574,37 +607,37 @@ HomeMaticGenericChannel.prototype = {
sType: function() { sType: function() {
if (this.type=="SWITCH") { if (this.type == "SWITCH") {
if (this.special=="OUTLET") { if (this.special == "OUTLET") {
return types.OUTLET_STYPE; return types.OUTLET_STYPE;
} else { } else {
return types.LIGHTBULB_STYPE; return types.LIGHTBULB_STYPE;
} }
} }
if (this.type=="DIMMER") { if (this.type == "DIMMER") {
return types.LIGHTBULB_STYPE; return types.LIGHTBULB_STYPE;
} }
if (this.type=="BLIND") { if (this.type == "BLIND") {
return types.WINDOW_COVERING_STYPE; return types.WINDOW_COVERING_STYPE;
} }
if (this.type=="CLIMATECONTROL_RT_TRANSCEIVER") { if (this.type == "CLIMATECONTROL_RT_TRANSCEIVER") {
return types.THERMOSTAT_STYPE; return types.THERMOSTAT_STYPE;
} }
if (this.type=="SHUTTER_CONTACT") { if (this.type == "SHUTTER_CONTACT") {
return types.CONTACT_SENSOR_STYPE; return types.CONTACT_SENSOR_STYPE;
} }
if (this.type=="MOTION_DETECTOR") { if (this.type == "MOTION_DETECTOR") {
return types.MOTION_SENSOR_STYPE return types.MOTION_SENSOR_STYPE
} }
if (this.type=="KEYMATIC") { if (this.type == "KEYMATIC") {
return types.LOCK_MECHANISM_STYPE return types.LOCK_MECHANISM_STYPE
} }
@@ -617,8 +650,7 @@ HomeMaticGenericChannel.prototype = {
var services = [{ var services = [{
sType: types.ACCESSORY_INFORMATION_STYPE, sType: types.ACCESSORY_INFORMATION_STYPE,
characteristics: this.informationCharacteristics(), characteristics: this.informationCharacteristics(),
}, }, {
{
sType: this.sType(), sType: this.sType(),
characteristics: this.controlCharacteristics(that) characteristics: this.controlCharacteristics(that)
}]; }];