mirror of
https://github.com/mtan93/homebridge.git
synced 2026-05-19 06:08:55 +01:00
switch back from xmlrpc branch to master
This commit is contained in:
@@ -2,9 +2,25 @@
|
||||
//
|
||||
// Homematic Platform Shim for HomeBridge
|
||||
//
|
||||
// to add the homematic platform add this to config.json. Example:
|
||||
// "platforms": [
|
||||
// {
|
||||
// "platform": "HomeMatic",
|
||||
// "name": "HomeMatic",
|
||||
// "filter_device":[],
|
||||
// "filter_channel":["BidCos-RF.KEQXXXXXXX:4", "BidCos-RF.LEQXXXXXXX:2"],
|
||||
// "outlets":[ "BidCos-RF.KEQXXXXXXX:4","BidCos-RF.IEQXXXXXXX:1"]
|
||||
//
|
||||
// }
|
||||
//
|
||||
// V0.1 - 2015/10/29
|
||||
// - initial version
|
||||
// - reintegrated Homematic Platform fork from https://github.com/thkl/homebridge/tree/xmlrpc
|
||||
// 2015/10/30 thkl
|
||||
// - added Rotary Sensors ; fixed thermostat
|
||||
|
||||
// ],
|
||||
|
||||
|
||||
|
||||
var types = require("hap-nodejs/accessories/types.js");
|
||||
|
||||
+122
-107
@@ -1,4 +1,3 @@
|
||||
"use strict";
|
||||
var types = require("hap-nodejs/accessories/types.js");
|
||||
|
||||
|
||||
@@ -12,17 +11,27 @@ function HomeMaticGenericChannel(log, platform, id, name, type, adress, special)
|
||||
this.eventupdate = false;
|
||||
this.special = special;
|
||||
this.currentStateCharacteristic = [];
|
||||
this.reverseDP = [];
|
||||
this.datapointMappings = [];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
HomeMaticGenericChannel.prototype = {
|
||||
|
||||
|
||||
addValueMapping: function(dp,value,mappedvalue) {
|
||||
if (this.datapointMappings[dp]==undefined) {
|
||||
this.datapointMappings[dp] = [];
|
||||
}
|
||||
this.datapointMappings[dp][value] = mappedvalue;
|
||||
} ,
|
||||
|
||||
// Return current States
|
||||
query: function(dp,callback) {
|
||||
if (this.state[dp] !== undefined) {
|
||||
var that = this;
|
||||
|
||||
if (this.state[dp] != undefined) {
|
||||
callback(this.state[dp]);
|
||||
} else {
|
||||
// that.log("No cached Value found start fetching and send temp 0 back");
|
||||
@@ -33,7 +42,7 @@ HomeMaticGenericChannel.prototype = {
|
||||
},
|
||||
|
||||
dpvalue:function(dp,fallback) {
|
||||
if (this.state[dp] !== undefined) {
|
||||
if (this.state[dp] != undefined) {
|
||||
return(this.state[dp]);
|
||||
} else {
|
||||
return fallback;
|
||||
@@ -62,24 +71,21 @@ HomeMaticGenericChannel.prototype = {
|
||||
this.eventupdate = false;
|
||||
},
|
||||
|
||||
reverse: function(value) {
|
||||
if (value == "true") return "false";
|
||||
if (value == "false") return "true";
|
||||
if (value === 0) return 1;
|
||||
if (value === 1) return 0;
|
||||
if (value == "0") return "1";
|
||||
if (value == "1") return "0";
|
||||
return value;
|
||||
},
|
||||
|
||||
cache:function(dp,value) {
|
||||
var that = this;
|
||||
|
||||
if ((that.reverseDP[dp] !== undefined) && (that.reverseDP[dp] === true)) {
|
||||
value = that.reverse(value);
|
||||
|
||||
// Check custom Mapping from HM to HomeKit
|
||||
var map = this.datapointMappings[dp];
|
||||
if (map != undefined) {
|
||||
this.log("Mapping found for " + dp);
|
||||
if (map[value]!=undefined) {
|
||||
this.log("Mapping found for " + dp + " " + value);
|
||||
value = map[value];
|
||||
}
|
||||
}
|
||||
|
||||
if (that.currentStateCharacteristic[dp] !== undefined) {
|
||||
if (that.currentStateCharacteristic[dp]!=undefined) {
|
||||
that.currentStateCharacteristic[dp].updateValue(value, null);
|
||||
}
|
||||
this.state[dp] = value;
|
||||
@@ -88,7 +94,7 @@ HomeMaticGenericChannel.prototype = {
|
||||
|
||||
delayed: function(mode, dp,value,delay) {
|
||||
|
||||
if (this.eventupdate === true) {
|
||||
if (this.eventupdate==true) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -99,15 +105,12 @@ HomeMaticGenericChannel.prototype = {
|
||||
|
||||
this.log(this.name + " delaying command "+mode + " " + dp +" with value " + value);
|
||||
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) {
|
||||
|
||||
if (this.eventupdate === true) {
|
||||
if (this.eventupdate==true) {
|
||||
return;
|
||||
}
|
||||
var that = this;
|
||||
@@ -119,7 +122,8 @@ HomeMaticGenericChannel.prototype = {
|
||||
},
|
||||
|
||||
informationCharacteristics: function() {
|
||||
return [{
|
||||
return [
|
||||
{
|
||||
cType: types.NAME_CTYPE,
|
||||
onUpdate: null,
|
||||
perms: ["pr"],
|
||||
@@ -169,12 +173,13 @@ HomeMaticGenericChannel.prototype = {
|
||||
supportBonjour: false,
|
||||
manfDescription: "Identify Accessory",
|
||||
designedMaxLength: 1
|
||||
}];
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
controlCharacteristics: function(that) {
|
||||
|
||||
var cTypes = [{
|
||||
cTypes = [{
|
||||
cType: types.NAME_CTYPE,
|
||||
onUpdate: null,
|
||||
perms: ["pr"],
|
||||
@@ -184,14 +189,14 @@ HomeMaticGenericChannel.prototype = {
|
||||
supportBonjour: false,
|
||||
manfDescription: "Name of service",
|
||||
designedMaxLength: 255
|
||||
}];
|
||||
}]
|
||||
|
||||
|
||||
if (this.type=="SWITCH") {
|
||||
cTypes.push({
|
||||
cType: types.POWER_STATE_CTYPE,
|
||||
onUpdate: function(value) {
|
||||
that.command("set", "STATE", (value == 1) ? true : false);
|
||||
that.command("set","STATE" , (value==1)?true:false)
|
||||
},
|
||||
|
||||
onRead: function(callback) {
|
||||
@@ -227,13 +232,14 @@ HomeMaticGenericChannel.prototype = {
|
||||
supportBonjour: false,
|
||||
manfDescription: "Is Outlet in Use",
|
||||
designedMaxLength: 1
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (this.type=="KEYMATIC") {
|
||||
cTypes.push({
|
||||
cTypes.push(
|
||||
{
|
||||
cType: types.CURRENT_LOCK_MECHANISM_STATE_CTYPE,
|
||||
|
||||
onRead: function(callback) {
|
||||
@@ -253,11 +259,12 @@ HomeMaticGenericChannel.prototype = {
|
||||
supportBonjour: false,
|
||||
manfDescription: "Current State of your Lock",
|
||||
designedMaxLength: 1
|
||||
}, {
|
||||
},
|
||||
{
|
||||
cType: types.TARGET_LOCK_MECHANISM_STATE_CTYPE,
|
||||
|
||||
onUpdate: function(value) {
|
||||
that.command("set", "STATE", (value == 1) ? "true" : "false");
|
||||
that.command("set","STATE",(value==1)?"true":"false")
|
||||
},
|
||||
|
||||
onRead: function(callback) {
|
||||
@@ -265,7 +272,8 @@ HomeMaticGenericChannel.prototype = {
|
||||
},
|
||||
|
||||
onRegister: function(characteristic) {
|
||||
that.reverseDP["STATE"] = true;
|
||||
that.addValueMapping("STATE","1",0);
|
||||
that.addValueMapping("STATE","0",1);
|
||||
that.currentStateCharacteristic["STATE"] = characteristic;
|
||||
characteristic.eventEnabled = true;
|
||||
that.remoteGetValue("STATE");
|
||||
@@ -279,13 +287,14 @@ HomeMaticGenericChannel.prototype = {
|
||||
supportBonjour: false,
|
||||
manfDescription: "Target State of your Lock",
|
||||
designedMaxLength: 1
|
||||
},
|
||||
}
|
||||
|
||||
,
|
||||
{
|
||||
cType: types.TARGET_DOORSTATE_CTYPE,
|
||||
|
||||
onUpdate: function(value) {
|
||||
that.command("set", "OPEN", "true");
|
||||
that.command("set","OPEN" , "true")
|
||||
},
|
||||
|
||||
onRead: function(callback) {
|
||||
@@ -306,13 +315,17 @@ HomeMaticGenericChannel.prototype = {
|
||||
designedMaxLength: 1
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (this.type=="DIMMER") {
|
||||
cTypes.push({
|
||||
cType: types.POWER_STATE_CTYPE,
|
||||
onUpdate: function(value) {
|
||||
that.command("set", "LEVEL", (value == true) ? "1" : "0");
|
||||
that.command("set","LEVEL" , (value==true) ? "1" : "0")
|
||||
},
|
||||
|
||||
onRead: function(callback) {
|
||||
@@ -332,7 +345,8 @@ HomeMaticGenericChannel.prototype = {
|
||||
supportBonjour: false,
|
||||
manfDescription: "Change the power state",
|
||||
designedMaxLength: 1
|
||||
}, {
|
||||
},
|
||||
{
|
||||
cType: types.BRIGHTNESS_CTYPE,
|
||||
onUpdate: function(value) {
|
||||
that.delayed("set","LEVEL" , String(value/100),100);
|
||||
@@ -362,8 +376,11 @@ HomeMaticGenericChannel.prototype = {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (this.type=="BLIND") {
|
||||
cTypes.push({
|
||||
cTypes.push(
|
||||
{
|
||||
cType: types.WINDOW_COVERING_CURRENT_POSITION_CTYPE,
|
||||
|
||||
onRead: function(callback) {
|
||||
@@ -416,7 +433,8 @@ HomeMaticGenericChannel.prototype = {
|
||||
designedMaxValue: 100,
|
||||
designedMinStep: 1,
|
||||
unit: "%"
|
||||
}, {
|
||||
},
|
||||
{
|
||||
cType: types.WINDOW_COVERING_OPERATION_STATE_CTYPE,
|
||||
|
||||
onRead: function(callback) {
|
||||
@@ -443,8 +461,11 @@ HomeMaticGenericChannel.prototype = {
|
||||
);
|
||||
}
|
||||
|
||||
// Simple Contact (Magnet)
|
||||
|
||||
if (this.type=="SHUTTER_CONTACT") {
|
||||
cTypes.push({
|
||||
cTypes.push(
|
||||
{
|
||||
cType: types.CONTACT_SENSOR_STATE_CTYPE,
|
||||
|
||||
onRead: function(callback) {
|
||||
@@ -466,8 +487,38 @@ HomeMaticGenericChannel.prototype = {
|
||||
});
|
||||
}
|
||||
|
||||
// Rotary Handle
|
||||
if (this.type=="ROTARY_HANDLE_SENSOR") {
|
||||
cTypes.push(
|
||||
{
|
||||
cType: types.CONTACT_SENSOR_STATE_CTYPE,
|
||||
|
||||
onRead: function(callback) {
|
||||
that.query("STATE",callback);
|
||||
},
|
||||
|
||||
onRegister: function(characteristic) {
|
||||
that.addValueMapping("STATE","2",1);
|
||||
that.currentStateCharacteristic["STATE"] = characteristic;
|
||||
characteristic.eventEnabled = true;
|
||||
that.remoteGetValue("STATE");
|
||||
},
|
||||
|
||||
perms: ["pr","ev"],
|
||||
format: "bool",
|
||||
initialValue: that.dpvalue("STATE",0),
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Current State"
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Motion Detector
|
||||
|
||||
if (this.type=="MOTION_DETECTOR") {
|
||||
cTypes.push({
|
||||
cTypes.push(
|
||||
{
|
||||
cType: types.MOTION_DETECTED_CTYPE,
|
||||
|
||||
onRead: function(callback) {
|
||||
@@ -489,47 +540,25 @@ HomeMaticGenericChannel.prototype = {
|
||||
});
|
||||
}
|
||||
|
||||
if (this.type == "CLIMATECONTROL_RT_TRANSCEIVER") {
|
||||
// Heating Device
|
||||
|
||||
if ((this.type=="CLIMATECONTROL_RT_TRANSCEIVER") || (this.type=="THERMALCONTROL_TRANSMIT")) {
|
||||
|
||||
cTypes.push({
|
||||
cType: types.NAME_CTYPE,
|
||||
onUpdate: null,
|
||||
perms: ["pr"],
|
||||
format: "string",
|
||||
initialValue: this.name,
|
||||
supportEvents: true,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Name of service",
|
||||
designedMaxLength: 255
|
||||
cType: types.NAME_CTYPE,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,
|
||||
perms: ["pr"],
|
||||
format: "int",
|
||||
initialValue: 1,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Current Mode",
|
||||
designedMaxLength: 1,
|
||||
designedMinValue: 1,
|
||||
designedMaxValue: 1,
|
||||
designedMinStep: 1
|
||||
cType: types.CURRENTHEATINGCOOLING_CTYPE,onUpdate: null,
|
||||
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"],
|
||||
format: "int",
|
||||
initialValue: 1,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Target Mode",
|
||||
designedMinValue: 1,
|
||||
designedMaxValue: 1,
|
||||
designedMinStep: 1
|
||||
cType: types.TARGETHEATINGCOOLING_CTYPE,onUpdate: null,perms: ["pw","pr"],
|
||||
format: "int",initialValue: 1,supportEvents: false,supportBonjour: false,manfDescription: "Target Mode",
|
||||
designedMinValue: 1,designedMaxValue: 1,designedMinStep: 1
|
||||
},
|
||||
|
||||
{
|
||||
@@ -545,19 +574,16 @@ HomeMaticGenericChannel.prototype = {
|
||||
characteristic.eventEnabled = true;
|
||||
that.remoteGetValue("ACTUAL_TEMPERATURE");
|
||||
},
|
||||
perms: ["pr", "ev"],
|
||||
format: "double",
|
||||
perms: ["pw","pr","ev"], perms: ["pr"],format: "double",
|
||||
initialValue: that.dpvalue("ACTUAL_TEMPERATURE",20),
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Current Temperature",
|
||||
unit: "celsius"
|
||||
supportEvents: false,supportBonjour: false,manfDescription: "Current Temperature",unit: "celsius"
|
||||
},
|
||||
|
||||
{
|
||||
cType: types.TARGET_TEMPERATURE_CTYPE,
|
||||
onUpdate: function(value) {
|
||||
that.delayed("set", "SET_TEMPERATURE", value, 500);
|
||||
//that.delayed("set", "SET_TEMPERATURE", value,500);
|
||||
that.delayed("set", "MANU_MODE", value,500);
|
||||
},
|
||||
onRead: function(callback) {
|
||||
that.query("SET_TEMPERATURE",callback);
|
||||
@@ -568,35 +594,23 @@ HomeMaticGenericChannel.prototype = {
|
||||
characteristic.eventEnabled = true;
|
||||
that.remoteGetValue("SET_TEMPERATURE");
|
||||
},
|
||||
perms: ["pw", "pr", "ev"],
|
||||
format: "double",
|
||||
perms: ["pw","pr","ev"],format: "double",
|
||||
initialValue: that.dpvalue("SET_TEMPERATURE",16),
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Target Temperature",
|
||||
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,
|
||||
perms: ["pr"],
|
||||
format: "int",
|
||||
initialValue: 0,
|
||||
supportEvents: false,
|
||||
supportBonjour: false,
|
||||
manfDescription: "Current Temperature Unit",
|
||||
unit: "celsius"
|
||||
cType: types.TEMPERATURE_UNITS_CTYPE,onRead: null,
|
||||
perms: ["pr"],format: "int",initialValue: 0,supportEvents: false,
|
||||
supportBonjour: false,manfDescription: "Current Temperature Unit",unit: "celsius"
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return cTypes;
|
||||
return cTypes
|
||||
},
|
||||
|
||||
sType: function() {
|
||||
@@ -618,21 +632,21 @@ HomeMaticGenericChannel.prototype = {
|
||||
return types.WINDOW_COVERING_STYPE;
|
||||
}
|
||||
|
||||
if (this.type == "CLIMATECONTROL_RT_TRANSCEIVER") {
|
||||
if ((this.type=="CLIMATECONTROL_RT_TRANSCEIVER") || (this.type=="THERMALCONTROL_TRANSMIT")) {
|
||||
return types.THERMOSTAT_STYPE;
|
||||
}
|
||||
|
||||
if (this.type == "SHUTTER_CONTACT") {
|
||||
if ((this.type=="SHUTTER_CONTACT") ||(this.type=="ROTARY_HANDLE_SENSOR")) {
|
||||
return types.CONTACT_SENSOR_STYPE;
|
||||
}
|
||||
|
||||
if (this.type=="MOTION_DETECTOR") {
|
||||
return types.MOTION_SENSOR_STYPE;
|
||||
return types.MOTION_SENSOR_STYPE
|
||||
}
|
||||
|
||||
|
||||
if (this.type=="KEYMATIC") {
|
||||
return types.LOCK_MECHANISM_STYPE;
|
||||
return types.LOCK_MECHANISM_STYPE
|
||||
}
|
||||
|
||||
|
||||
@@ -643,12 +657,13 @@ HomeMaticGenericChannel.prototype = {
|
||||
var that = this;
|
||||
var services = [{
|
||||
sType: types.ACCESSORY_INFORMATION_STYPE,
|
||||
characteristics: this.informationCharacteristics()
|
||||
}, {
|
||||
characteristics: this.informationCharacteristics(),
|
||||
},
|
||||
{
|
||||
sType: this.sType(),
|
||||
characteristics: this.controlCharacteristics(that)
|
||||
}];
|
||||
this.log("Loaded services for " + this.name);
|
||||
this.log("Loaded services for " + this.name)
|
||||
return services;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user