mirror of
https://github.com/mtan93/homebridge.git
synced 2026-04-16 22:05:15 +01:00
Merge pull request #342 from stipus/master
Added SecuritySystem,Window/Covering,obstruction
This commit is contained in:
@@ -29,12 +29,22 @@
|
|||||||
// - Added offEventGroup && offEventName to events (turn <event> on launches one HS event. turn <event> off can launch another HS event)
|
// - Added offEventGroup && offEventName to events (turn <event> on launches one HS event. turn <event> off can launch another HS event)
|
||||||
// - Added GarageDoorOpener support
|
// - Added GarageDoorOpener support
|
||||||
// - Added Lock support
|
// - Added Lock support
|
||||||
|
// V0.10 - 2015/10/29
|
||||||
|
// - Added Security System support
|
||||||
|
// - Added Window support
|
||||||
|
// - Added Window Covering support
|
||||||
|
// - Added obstruction support to doors, windows, and windowCoverings
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Remember to add platform to config.json.
|
// Remember to add platform to config.json.
|
||||||
//
|
//
|
||||||
// You can get HomeSeer Device References by clicking a HomeSeer device name, then
|
// You can get HomeSeer Device References by clicking a HomeSeer device name, then
|
||||||
// choosing the Advanced Tab.
|
// choosing the Advanced Tab.
|
||||||
|
//
|
||||||
|
// The uuid_base parameter is valid for all events and accessories.
|
||||||
|
// If you set this parameter to some unique identifier, the HomeKit accessory ID will be based on uuid_base instead of the accessory name.
|
||||||
|
// It is then easier to change the accessory name without messing the HomeKit database.
|
||||||
|
//
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
// "platforms": [
|
// "platforms": [
|
||||||
@@ -148,10 +158,31 @@
|
|||||||
// "lockValue":1 // Required - HomeSeer device control value to lock
|
// "lockValue":1 // Required - HomeSeer device control value to lock
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
|
// "ref":230, // Required - HomeSeer Device Reference of a Security System
|
||||||
|
// "type":"SecuritySystem", // Required for a security system
|
||||||
|
// "name":"Home alarm", // Optional - HomeSeer device name is the default
|
||||||
|
// "armedStayValues":[0], // Optional - List of the HomeSeer device values for a HomeKit security state=ARMED-STAY
|
||||||
|
// "armedAwayValues":[1], // Optional - List of the HomeSeer device values for a HomeKit security state=ARMED-AWAY
|
||||||
|
// "armedNightValues":[2], // Optional - List of the HomeSeer device values for a HomeKit security state=ARMED-NIGHT
|
||||||
|
// "disarmedValues":[3], // Optional - List of the HomeSeer device values for a HomeKit security state=DISARMED
|
||||||
|
// "alarmValues":[4], // Optional - List of the HomeSeer device values for a HomeKit security state=ALARM
|
||||||
|
// "armStayValue":0, // Required - HomeSeer device control value to arm in stay mode. If you don't have this mode, select any value that arms your system
|
||||||
|
// "armAwayValue":1, // Required - HomeSeer device control value to arm in away mode. If you don't have this mode, select any value that arms your system
|
||||||
|
// "armNightValue":2, // Required - HomeSeer device control value to arm in night mode. If you don't have this mode, select any value that arms your system
|
||||||
|
// "disarmValue":3 // Required - HomeSeer device control value to disarm security system
|
||||||
|
// },
|
||||||
|
// {
|
||||||
// "ref":115, // Required - HomeSeer Device Reference for a device holding battery level (0-100)
|
// "ref":115, // Required - HomeSeer Device Reference for a device holding battery level (0-100)
|
||||||
// "type":"Battery", // Required for a Battery
|
// "type":"Battery", // Required for a Battery
|
||||||
// "name":"Roomba battery", // Optional - HomeSeer device name is the default
|
// "name":"Roomba battery", // Optional - HomeSeer device name is the default
|
||||||
// "batteryThreshold":15 // Optional - If the level is below this value, the HomeKit LowBattery characteristic is set to 1. Default is 10
|
// "batteryThreshold":15 // Optional - If the level is below this value, the HomeKit LowBattery characteristic is set to 1. Default is 10
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "ref":240, // Required - HomeSeer Device Reference for a door - HomeSeer values must go from 0 (closed) to 100 (open)
|
||||||
|
// "type":"Door", // Required for a Door
|
||||||
|
// "name":"Main door", // Optional - HomeSeer device name is the default
|
||||||
|
// "obstructionRef":241, // Optional - HomeSeer device reference for your door obstruction state (can be the same as ref)
|
||||||
|
// "obstructionValues":[1] // Optional - List of the HomeSeer device values for a HomeKit obstruction state=OBSTRUCTION
|
||||||
// }
|
// }
|
||||||
// ]
|
// ]
|
||||||
// }
|
// }
|
||||||
@@ -177,8 +208,10 @@
|
|||||||
// - Battery (batteryThreshold option)
|
// - Battery (batteryThreshold option)
|
||||||
// - GarageDoorOpener (state, control, obstruction, lock options)
|
// - GarageDoorOpener (state, control, obstruction, lock options)
|
||||||
// - Lock (unsecured, secured, jammed options)
|
// - Lock (unsecured, secured, jammed options)
|
||||||
// - Door
|
// - SecuritySystem (arm, disarm options)
|
||||||
|
// - Door (obstruction option)
|
||||||
|
// - Window (obstruction option)
|
||||||
|
// - WindowCovering (obstruction option)
|
||||||
|
|
||||||
var Service = require("hap-nodejs").Service;
|
var Service = require("hap-nodejs").Service;
|
||||||
var Characteristic = require("hap-nodejs").Characteristic;
|
var Characteristic = require("hap-nodejs").Characteristic;
|
||||||
@@ -672,7 +705,7 @@ HomeSeerAccessory.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setLockTargetState: function(state, callback) {
|
setLockTargetState: function(state, callback) {
|
||||||
this.log("Setting target lock state state to %s", state);
|
this.log("Setting target lock state to %s", state);
|
||||||
|
|
||||||
var ref = this.config.lockRef;
|
var ref = this.config.lockRef;
|
||||||
var value = 0;
|
var value = 0;
|
||||||
@@ -694,6 +727,62 @@ HomeSeerAccessory.prototype = {
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getSecuritySystemCurrentState: function(callback) {
|
||||||
|
var url = this.access_url + "request=getstatus&ref=" + this.ref;
|
||||||
|
|
||||||
|
httpRequest(url, 'GET', function(error, response, body) {
|
||||||
|
if (error) {
|
||||||
|
this.log('HomeSeer get security system current state function failed: %s', error.message);
|
||||||
|
callback( error, 3 );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var status = JSON.parse( body );
|
||||||
|
var value = status.Devices[0].value;
|
||||||
|
|
||||||
|
this.log('HomeSeer get security system current state function succeeded: value=' + value );
|
||||||
|
if( this.config.armedStayValues && this.config.armedStayValues.indexOf(value) != -1 )
|
||||||
|
callback( null, 0 );
|
||||||
|
else if( this.config.armedAwayValues && this.config.armedAwayValues.indexOf(value) != -1 )
|
||||||
|
callback( null, 1 );
|
||||||
|
else if( this.config.armedNightValues && this.config.armedNightValues.indexOf(value) != -1 )
|
||||||
|
callback( null, 2 );
|
||||||
|
else if( this.config.disarmedValues && this.config.disarmedValues.indexOf(value) != -1 )
|
||||||
|
callback( null, 3 );
|
||||||
|
else if( this.config.alarmValues && this.config.alarmValues.indexOf(value) != -1 )
|
||||||
|
callback( null, 4 );
|
||||||
|
else
|
||||||
|
callback( null, 0 );
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
|
setSecuritySystemTargetState: function(state, callback) {
|
||||||
|
this.log("Setting security system state to %s", state);
|
||||||
|
|
||||||
|
var value = 0;
|
||||||
|
if( state == 0 && this.config.armStayValue )
|
||||||
|
value = this.config.armStayValue;
|
||||||
|
else if( state == 1 && this.config.armAwayValue )
|
||||||
|
value = this.config.armAwayValue;
|
||||||
|
else if( state == 2 && this.config.armNightValue )
|
||||||
|
value = this.config.armNightValue;
|
||||||
|
else if( state == 3 && this.config.disarmValue )
|
||||||
|
value = this.config.disarmValue;
|
||||||
|
|
||||||
|
var url = this.access_url + "request=controldevicebyvalue&ref=" + this.ref + "&value=" + value;
|
||||||
|
httpRequest(url, 'GET', function(error, response, body) {
|
||||||
|
if (error) {
|
||||||
|
this.log('HomeSeer set target security system state function failed: %s', error.message);
|
||||||
|
callback(error);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.log('HomeSeer set target security system state function succeeded!');
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
getPositionState: function(callback) {
|
getPositionState: function(callback) {
|
||||||
callback( null, 2 ); // Temporarily return STOPPED. TODO: full door support
|
callback( null, 2 ); // Temporarily return STOPPED. TODO: full door support
|
||||||
},
|
},
|
||||||
@@ -897,9 +986,52 @@ HomeSeerAccessory.prototype = {
|
|||||||
doorService
|
doorService
|
||||||
.getCharacteristic(Characteristic.PositionState)
|
.getCharacteristic(Characteristic.PositionState)
|
||||||
.on('get', this.getPositionState.bind(this));
|
.on('get', this.getPositionState.bind(this));
|
||||||
|
if( this.config.obstructionRef ) {
|
||||||
|
doorService
|
||||||
|
.addCharacteristic(new Characteristic.ObstructionDetected())
|
||||||
|
.on('get', this.getObstructionDetected.bind(this));
|
||||||
|
}
|
||||||
services.push( doorService );
|
services.push( doorService );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "Window": {
|
||||||
|
var windowService = new Service.Window();
|
||||||
|
windowService
|
||||||
|
.getCharacteristic(Characteristic.CurrentPosition)
|
||||||
|
.on('get', this.getValue.bind(this));
|
||||||
|
windowService
|
||||||
|
.getCharacteristic(Characteristic.TargetPosition)
|
||||||
|
.on('set', this.setValue.bind(this));
|
||||||
|
windowService
|
||||||
|
.getCharacteristic(Characteristic.PositionState)
|
||||||
|
.on('get', this.getPositionState.bind(this));
|
||||||
|
if( this.config.obstructionRef ) {
|
||||||
|
windowService
|
||||||
|
.addCharacteristic(new Characteristic.ObstructionDetected())
|
||||||
|
.on('get', this.getObstructionDetected.bind(this));
|
||||||
|
}
|
||||||
|
services.push( windowService );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "WindowCovering": {
|
||||||
|
var windowCoveringService = new Service.WindowCovering();
|
||||||
|
windowCoveringService
|
||||||
|
.getCharacteristic(Characteristic.CurrentPosition)
|
||||||
|
.on('get', this.getValue.bind(this));
|
||||||
|
windowCoveringService
|
||||||
|
.getCharacteristic(Characteristic.TargetPosition)
|
||||||
|
.on('set', this.setValue.bind(this));
|
||||||
|
windowCoveringService
|
||||||
|
.getCharacteristic(Characteristic.PositionState)
|
||||||
|
.on('get', this.getPositionState.bind(this));
|
||||||
|
services.push( windowCoveringService );
|
||||||
|
if( this.config.obstructionRef ) {
|
||||||
|
windowCoveringService
|
||||||
|
.addCharacteristic(new Characteristic.ObstructionDetected())
|
||||||
|
.on('get', this.getObstructionDetected.bind(this));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "Battery": {
|
case "Battery": {
|
||||||
this.config.batteryRef = this.ref;
|
this.config.batteryRef = this.ref;
|
||||||
var batteryService = new Service.BatteryService();
|
var batteryService = new Service.BatteryService();
|
||||||
@@ -974,6 +1106,17 @@ HomeSeerAccessory.prototype = {
|
|||||||
services.push( lockService );
|
services.push( lockService );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "SecuritySystem": {
|
||||||
|
var securitySystemService = new Service.SecuritySystem();
|
||||||
|
securitySystemService
|
||||||
|
.getCharacteristic(Characteristic.SecuritySystemCurrentState)
|
||||||
|
.on('get', this.getSecuritySystemCurrentState.bind(this));
|
||||||
|
securitySystemService
|
||||||
|
.getCharacteristic(Characteristic.SecuritySystemTargetState)
|
||||||
|
.on('set', this.setSecuritySystemTargetState.bind(this));
|
||||||
|
services.push( securitySystemService );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:{
|
default:{
|
||||||
var lightbulbService = new Service.Lightbulb();
|
var lightbulbService = new Service.Lightbulb();
|
||||||
|
|||||||
Reference in New Issue
Block a user