Skip to content

Commit

Permalink
Add accessories specific configuration, Fix command label content
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain DUBOC committed Mar 30, 2017
1 parent cd5eaf2 commit e4197ae
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 163 deletions.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,39 @@ Configuration sample:
| `password` | mandatory, your TaHoma/Cozytouch account password |
| `service` | optional, service name in [TaHoma, Cozytouch], default: TaHoma |
| `refreshPeriod` | optional, device states refresh period in minute, default: 10 |
| `exclude` | optional, list of protocols (hue,enocean,zwave,io,rts) to exclude |
| `exclude` | optional, list of protocols (hue,enocean,zwave,io,rts) or device (name) to exclude |
| `Alarm` | optional, Alarm configuration object |
| | | `STAY_ARM`| list of zones (A,B,C) to activate in "STAY" mode | |
| | | `AWAY_ARM`| list of zones (A,B,C) to activate in "NIGHT" mode | |
|

Full configuration example:
```
{
"bridge": {
...
},
"description": "...",
"accessories": [],
"platforms":[
{
"platform": "Tahoma",
"name": "Tahoma",
"user": "yourusername",
"password": "yourpassword",
"service": "TaHoma",
"exclude": ["hue","rts","Garage Door"],
"Alarm": {
"STAY_ARM": "A,C",
"NIGHT_ARM": "B"
}
}
]
}
```

# Limitation

Expand Down
5 changes: 3 additions & 2 deletions accessories/AbstractAccessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ AbstractAccessory.prototype = {
if (this.isCommandInProgress()) {
this.api.cancelCommand(this.lastExecId, function() {});
}

this.api.executeCommand(this.device.deviceURL, command, function(status, error, data) {

var label = command.name + ' ' + this.name;
this.api.executeCommand(label, this.device.deviceURL, command, function(status, error, data) {
if(!error) {
if (status == ExecutionState.INITIALIZED)
that.lastExecId = data.execId;
Expand Down
14 changes: 9 additions & 5 deletions accessories/Alarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ module.exports = function(homebridge, abstractAccessory, api) {
* Accessory "Alarm"
*/

Alarm = function(log, api, device) {
Alarm = function(log, api, device, config) {
AbstractAccessory.call(this, log, api, device);

this.stayZones = config.STAY_ARM || 'A';
this.nightZones = config.NIGHT_ARM || 'B';

var service = new Service.SecuritySystem(device.label);

this.currentState = service.getCharacteristic(Characteristic.SecuritySystemCurrentState);
Expand All @@ -40,11 +44,11 @@ Alarm.prototype = {
default:
case Characteristic.SecuritySystemTargetState.STAY_ARM:
command = new Command('alarmZoneOn');
command.parameters = ['A'];
command.parameters = [this.stayZones];
break;
case Characteristic.SecuritySystemTargetState.NIGHT_ARM:
command = new Command('alarmZoneOn');
command.parameters = ['B'];
command.parameters = [this.nightZones];
break;
case Characteristic.SecuritySystemTargetState.AWAY_ARM:
command = new Command('alarmOn');
Expand All @@ -59,8 +63,8 @@ Alarm.prototype = {
callback(error);
break;
case ExecutionState.COMPLETED:
if(this.device.widget == 'StatelessAlarmController') { // If stateless alarm, update target immediately
that.targetState.updateValue(value);
if(that.device.widget == 'StatelessAlarmController') { // If stateless alarm, update target immediately
that.currentState.updateValue(value);
}
break;
case ExecutionState.FAILED:
Expand Down
2 changes: 1 addition & 1 deletion accessories/Awning.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(homebridge, abstractAccessory, api) {
* Accessory "Awning"
*/

Awning = function(log, api, device) {
Awning = function(log, api, device, config) {
AbstractAccessory.call(this, log, api, device);
var service = new Service.WindowCovering(device.label);

Expand Down
2 changes: 1 addition & 1 deletion accessories/ContactSensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(homebridge, abstractAccessory, api) {
* Accessory "ContactSensor"
*/

ContactSensor = function(log, api, device) {
ContactSensor = function(log, api, device, config) {
AbstractAccessory.call(this, log, api, device);
var service = new Service.ContactSensor(device.label);

Expand Down
2 changes: 1 addition & 1 deletion accessories/DoorLock.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(homebridge, abstractAccessory, api) {
* Accessory "DoorLock"
*/

DoorLock = function(log, api, device) {
DoorLock = function(log, api, device, config) {
AbstractAccessory.call(this, log, api, device);
var service = new Service.LockMechanism(device.label);

Expand Down
122 changes: 0 additions & 122 deletions accessories/ElectricitySensor.js

This file was deleted.

16 changes: 4 additions & 12 deletions accessories/GarageDoor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ GarageDoor = function(log, api, device) {

this.currentState = service.getCharacteristic(Characteristic.CurrentDoorState);
this.targetState = service.getCharacteristic(Characteristic.TargetDoorState)
this.targetState.on('set', this.setState.bind(this));
if(this.device.widget == 'UpDownGarageDoor4T') {
this.targetState.on('set', this.cycle.bind(this));
} else {
Expand Down Expand Up @@ -68,28 +67,21 @@ GarageDoor.prototype = {
cycle: function(value, callback) {
var that = this;

if(value == Characteristic.TargetDoorState.CLOSED) {
callback("Can't close this device");
return;
}
var command = new Command('cycle');
this.executeCommand(command, function(status, error, data) {
switch (status) {
case ExecutionState.INITIALIZED:
callback(error);
break;
case ExecutionState.IN_PROGRESS:
that.currentState.updateValue(Characteristic.CurrentDoorState.OPENING);
break;
case ExecutionState.COMPLETED:
that.currentState.updateValue(Characteristic.CurrentDoorState.OPEN);
setTimeout(function() {
that.currentState.updateValue(Characteristic.CurrentDoorState.CLOSED);
}, 30000); // Simulate end of cycle after 30 seconds
var newValue = (value == Characteristic.TargetDoorState.OPEN) ? Characteristic.CurrentDoorState.OPEN : Characteristic.CurrentDoorState.CLOSED;
that.currentState.updateValue(newValue);
break;
case ExecutionState.FAILED:
// Update target in case of error
that.targetState.updateValue(Characteristic.TargetDoorState.CLOSED);
// Restore target in case of error
that.targetState.updateValue(value == Characteristic.TargetDoorState.OPEN ? Characteristic.TargetDoorState.CLOSED : Characteristic.TargetDoorState.OPEN);
break;
default:
break;
Expand Down
34 changes: 33 additions & 1 deletion accessories/Gate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ Gate = function(log, api, device) {

this.currentState = service.getCharacteristic(Characteristic.CurrentDoorState);
this.targetState = service.getCharacteristic(Characteristic.TargetDoorState)
this.targetState.on('set', this.setState.bind(this));
if(this.device.widget == 'OpenCloseGate4T') {
this.targetState.on('set', this.cycle.bind(this));
} else {
this.targetState.on('set', this.setState.bind(this));
}

this.services.push(service);
};
Expand Down Expand Up @@ -57,6 +61,34 @@ Gate.prototype = {
}
});
},

/**
* Triggered when Homekit try to modify the Characteristic.TargetDoorState for UpDownGarageDoor4T
**/
cycle: function(value, callback) {
var that = this;

var command = new Command('cycle');
this.executeCommand(command, function(status, error, data) {
switch (status) {
case ExecutionState.INITIALIZED:
callback(error);
break;
case ExecutionState.IN_PROGRESS:
break;
case ExecutionState.COMPLETED:
var newValue = (value == Characteristic.TargetDoorState.OPEN) ? Characteristic.CurrentDoorState.OPEN : Characteristic.CurrentDoorState.CLOSED;
that.currentState.updateValue(newValue);
break;
case ExecutionState.FAILED:
// Restore target in case of error
that.targetState.updateValue(value == Characteristic.TargetDoorState.OPEN ? Characteristic.TargetDoorState.CLOSED : Characteristic.TargetDoorState.OPEN);
break;
default:
break;
}
});
},

onStateUpdate: function(name, value) {
if (name == State.STATE_OPEN_CLOSED_PEDESTRIAN) {
Expand Down
2 changes: 1 addition & 1 deletion accessories/HeatingSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(homebridge, abstractAccessory, api) {
* Accessory "HeatingSystem"
*/

HeatingSystem = function(log, api, device) {
HeatingSystem = function(log, api, device, config) {
AbstractAccessory.call(this, log, api, device);
var service = new Service.Thermostat(device.label);

Expand Down
2 changes: 1 addition & 1 deletion accessories/Light.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(homebridge, abstractAccessory, api) {
* Accessory "Light"
*/

Light = function(log, api, device) {
Light = function(log, api, device, config) {
AbstractAccessory.call(this, log, api, device);
var service = new Service.Lightbulb(device.label);

Expand Down
2 changes: 1 addition & 1 deletion accessories/LightSensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(homebridge, abstractAccessory, api) {
* Accessory "LightSensor"
*/

LightSensor = function(log, api, device) {
LightSensor = function(log, api, device, config) {
AbstractAccessory.call(this, log, api, device);
var service = new Service.LightSensor(device.label);

Expand Down
2 changes: 1 addition & 1 deletion accessories/OccupancySensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(homebridge, abstractAccessory, api) {
* Accessory "OccupancySensor"
*/

OccupancySensor = function(log, api, device) {
OccupancySensor = function(log, api, device, config) {
AbstractAccessory.call(this, log, api, device);
var service = new Service.OccupancySensor(device.label);

Expand Down
5 changes: 4 additions & 1 deletion accessories/RollerShutter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ module.exports = function(homebridge, abstractAccessory, api) {
* Accessory "RollerShutter"
*/

RollerShutter = function(log, api, device) {
RollerShutter = function(log, api, device, config) {
AbstractAccessory.call(this, log, api, device);
var service = new Service.WindowCovering(device.label);

this.stayZones = config.STAY_ARM || 'A';
this.nightZones = config.NIGHT_ARM || 'B';

this.currentPosition = service.getCharacteristic(Characteristic.CurrentPosition);
this.targetPosition = service.getCharacteristic(Characteristic.TargetPosition);
if(this.device.widget == 'UpDownRollerShutter') {
Expand Down
2 changes: 1 addition & 1 deletion accessories/SmokeSensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(homebridge, abstractAccessory, api) {
* Accessory "SmokeSensor"
*/

SmokeSensor = function(log, api, device) {
SmokeSensor = function(log, api, device, config) {
AbstractAccessory.call(this, log, api, device);
var service = new Service.SmokeSensor(device.label);

Expand Down
Loading

0 comments on commit e4197ae

Please sign in to comment.