mirror of
https://github.com/mtan93/homebridge.git
synced 2026-05-13 14:26:04 +01:00
Routines for unsigned int values, such as enumeration like types
This commit is contained in:
+22
-20
@@ -8,9 +8,11 @@ new features include:
|
|||||||
- Window
|
- Window
|
||||||
- WindowCovering
|
- WindowCovering
|
||||||
- ContactSensor
|
- ContactSensor
|
||||||
New 2015-0918:
|
New 2015-09-18:
|
||||||
- Services Switch and Outlet
|
- Services Switch and Outlet
|
||||||
- Code cleanup
|
- Code cleanup
|
||||||
|
New 2015-09-19:
|
||||||
|
- GarageDoorOpener Service
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
var Service = require("HAP-NodeJS").Service;
|
var Service = require("HAP-NodeJS").Service;
|
||||||
@@ -148,20 +150,7 @@ KNXDevice.prototype = {
|
|||||||
this.knxread (groupAddresses);
|
this.knxread (groupAddresses);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/** Write special type routines
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// special types
|
|
||||||
knxwrite_percent: function(callback, groupAddress, value) {
|
|
||||||
var numericValue = 0;
|
|
||||||
if (value && value>=0 && value <= 100) {
|
|
||||||
numericValue = 255*value/100; // convert 1..100 to 1..255 for KNX bus
|
|
||||||
} else {
|
|
||||||
this.log("[ERROR] Percentage value ot of bounds ");
|
|
||||||
numericValue = 0;
|
|
||||||
}
|
|
||||||
this.knxwrite(callback, groupAddress,'DPT5',numericValue);
|
|
||||||
},
|
|
||||||
/** Registering routines
|
/** Registering routines
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -210,11 +199,22 @@ KNXDevice.prototype = {
|
|||||||
this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName);
|
this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName);
|
||||||
var hk_value = Math.round(val*10)/10;
|
var hk_value = Math.round(val*10)/10;
|
||||||
if (hk_value>=characteristic.minimumValue && hk_value<=characteristic.maximumValue) {
|
if (hk_value>=characteristic.minimumValue && hk_value<=characteristic.maximumValue) {
|
||||||
characteristic.setValue(hk_value, undefined, 'fromKNXBus'); // 1 decoimal for HomeKit
|
characteristic.setValue(hk_value, undefined, 'fromKNXBus'); // 1 decimal for HomeKit
|
||||||
} else {
|
} else {
|
||||||
this.log("Value %s out of bounds %s...%s ",hk_value, characteristic.minimumValue, characteristic.maximumValue);
|
this.log("Value %s out of bounds %s...%s ",hk_value, characteristic.minimumValue, characteristic.maximumValue);
|
||||||
}
|
}
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
//integer
|
||||||
|
knxregister_int: function(addresses, characteristic) {
|
||||||
|
this.log("knx registering FLOAT " + addresses);
|
||||||
|
knxd_registerGA(addresses, function(val, src, dest, type){
|
||||||
|
this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName);
|
||||||
|
if (val>=(characteristic.minimumValue || 0) && val<=(characteristic.maximumValue || 255) {
|
||||||
|
characteristic.setValue(val, undefined, 'fromKNXBus');
|
||||||
|
} else {
|
||||||
|
this.log("Value %s out of bounds %s...%s ",hk_value, (characteristic.minimumValue || 0), (characteristic.maximumValue || 255));
|
||||||
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
knxregister_HVAC: function(addresses, characteristic) {
|
knxregister_HVAC: function(addresses, characteristic) {
|
||||||
@@ -431,11 +431,12 @@ KNXDevice.prototype = {
|
|||||||
this.setHVACState(value, callback, context, config.Set);
|
this.setHVACState(value, callback, context, config.Set);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
break;
|
break;
|
||||||
default:
|
default: {
|
||||||
this.log("[ERROR] unknown type passed");
|
this.log("[ERROR] unknown type passed");
|
||||||
throw new Error("[ERROR] unknown type passed");
|
throw new Error("[ERROR] unknown type passed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ([config.Set].concat(config.Listen || []).length>0) {
|
if ([config.Set].concat(config.Listen || []).length>0) {
|
||||||
//this.log("Binding LISTEN");
|
//this.log("Binding LISTEN");
|
||||||
// can read
|
// can read
|
||||||
@@ -453,8 +454,7 @@ KNXDevice.prototype = {
|
|||||||
this.knxregister_float([config.Set].concat(config.Listen || []), myCharacteristic);
|
this.knxregister_float([config.Set].concat(config.Listen || []), myCharacteristic);
|
||||||
break;
|
break;
|
||||||
case "Int":
|
case "Int":
|
||||||
// use float as return type for ints, for we don't care
|
this.knxregister_int([config.Set].concat(config.Listen || []), myCharacteristic);
|
||||||
this.knxregister_float([config.Set].concat(config.Listen || []), myCharacteristic);
|
|
||||||
break;
|
break;
|
||||||
case "HVAC":
|
case "HVAC":
|
||||||
this.knxregister_HVAC([config.Set].concat(config.Listen || []), myCharacteristic);
|
this.knxregister_HVAC([config.Set].concat(config.Listen || []), myCharacteristic);
|
||||||
@@ -559,6 +559,8 @@ KNXDevice.prototype = {
|
|||||||
}
|
}
|
||||||
if (config.TargetDoorState) {
|
if (config.TargetDoorState) {
|
||||||
this.log("GarageDoorOpener TargetDoorState characteristic enabled");
|
this.log("GarageDoorOpener TargetDoorState characteristic enabled");
|
||||||
|
//myService.getCharacteristic(Characteristic.TargetDoorState).minimumValue=0; //
|
||||||
|
//myService.getCharacteristic(Characteristic.TargetDoorState).maximumValue=4; //
|
||||||
this.bindCharacteristic(myService, Characteristic.TargetDoorState, "Int", config.TargetDoorState);
|
this.bindCharacteristic(myService, Characteristic.TargetDoorState, "Int", config.TargetDoorState);
|
||||||
}
|
}
|
||||||
if (config.ObstructionDetected) {
|
if (config.ObstructionDetected) {
|
||||||
|
|||||||
Reference in New Issue
Block a user