Skip to content

Commit

Permalink
fixes targetDoorState update
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Nov 12, 2016
1 parent cf115ec commit 53d5645
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions accessories/GarageDoorOpener.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ module.exports = function (iface) {
});

if (settings.topic.statusDoor) {
var initial = true;

/* TODO opening/closing/stopped
Characteristic.CurrentDoorState.OPEN = 0;
Expand All @@ -47,22 +46,19 @@ module.exports = function (iface) {
log.debug('> hap set', settings.name, 'CurrentDoorState.CLOSED');
garage.getService(Service.GarageDoorOpener)
.setCharacteristic(Characteristic.CurrentDoorState, Characteristic.CurrentDoorState.CLOSED);
if (initial) {
log.debug('> hap set', settings.name, 'CurrentDoorState.CLOSED');
garage.getService(Service.GarageDoorOpener)
.setCharacteristic(Characteristic.CurrentDoorState, Characteristic.CurrentDoorState.CLOSED);
initial = false;
}
log.debug('> hap update', settings.name, 'TargetDoorState.CLOSED');
garage.getService(Service.GarageDoorOpener)
.updateCharacteristic(Characteristic.TargetDoorState, Characteristic.CurrentDoorState.CLOSED);


} else {
log.debug('> hap set', settings.name, 'CurrentDoorState.OPEN');
garage.getService(Service.GarageDoorOpener)
.setCharacteristic(Characteristic.CurrentDoorState, Characteristic.CurrentDoorState.OPEN);
if (initial) {
log.debug('> hap set', settings.name, 'CurrentDoorState.OPEN');
garage.getService(Service.GarageDoorOpener)
.setCharacteristic(Characteristic.CurrentDoorState, Characteristic.CurrentDoorState.OPEN);
initial = false;
}
log.debug('> hap update', settings.name, 'TargetDoorState.OPEN');
garage.getService(Service.GarageDoorOpener)
.updateCharacteristic(Characteristic.TargetDoorState, Characteristic.CurrentDoorState.OPEN);

}
});

Expand Down Expand Up @@ -118,29 +114,24 @@ module.exports = function (iface) {

if (settings.topic.statusLock) {

var initialLock = true;

mqttSub(settings.topic.statusLock, function (val) {
if (val === settings.payload.lockSecured) {
log.debug('> hap set', settings.name, 'LockCurrentState.SECURED');
garage.getService(Service.LockMechanism)
.setCharacteristic(Characteristic.LockCurrentState, Characteristic.LockCurrentState.SECURED);
if (initialLock) {
log.debug('> hap set', settings.name, 'LockTargetState.SECURED');
garage.getService(Service.LockMechanism)
.setCharacteristic(Characteristic.LockTargetState, Characteristic.LockTargetState.SECURED);
initialLock = false;
}
log.debug('> hap update', settings.name, 'LockCurrentState.SECURED');
garage.getService(Service.LockMechanism)
.updateCharacteristic(Characteristic.LockTargetState, Characteristic.LockCurrentState.SECURED);

} else {
log.debug('> hap set', settings.name, 'LockCurrentState.UNSECURED');
garage.getService(Service.LockMechanism)
.setCharacteristic(Characteristic.LockCurrentState, Characteristic.LockCurrentState.UNSECURED);
if (initialLock) {
log.debug('> hap set', settings.name, 'LockTargetState.UNSECURED');
garage.getService(Service.LockMechanism)
.setCharacteristic(Characteristic.LockTargetState, Characteristic.LockTargetState.UNSECURED);
initialLock = false;
}
log.debug('> hap update', settings.name, 'LockCurrentState.UNSECURED');
garage.getService(Service.LockMechanism)
.updateCharacteristic(Characteristic.LockTargetState, Characteristic.LockCurrentState.UNSECURED);

}
});

Expand Down

0 comments on commit 53d5645

Please sign in to comment.