diff --git a/README.md b/README.md index f07fd97..4535461 100644 --- a/README.md +++ b/README.md @@ -159,14 +159,17 @@ Value is in milliseconds: } ``` -You can also configure an `autoCloseDelay` +You can also configure an `autoCloseDelay` and `autoCloseVirtual` to physically or virtually close the garage door. ```json { "platforms": [ { "settings": { - "1529094720": {"autoCloseDelay": 300000} // 5 minutes + "1529094720": { + "autoCloseDelay": 300000, // 5 minutes + "autoCloseVirtual": true + } } } ] diff --git a/src/accessories/garageDoorOpener.ts b/src/accessories/garageDoorOpener.ts index 1a0b3e5..ecc660d 100644 --- a/src/accessories/garageDoorOpener.ts +++ b/src/accessories/garageDoorOpener.ts @@ -31,6 +31,7 @@ import {Characteristic, Service} from 'src/config/hap'; type GarageDoorOpenerSettings = { delay?: number; autoCloseDelay?: number; + autoCloseVirtual?: boolean; }; type GarageDoorOpenerState = { currentDoorState: number; @@ -52,7 +53,7 @@ export const setupGarageDoorOpener = ( const {deviceId, endpointId, state, settings} = context; - const {delay: garageDoorDelay = DEFAULT_GARAGE_DOOR_DELAY, autoCloseDelay} = settings; + const {delay: garageDoorDelay = DEFAULT_GARAGE_DOOR_DELAY, autoCloseDelay, autoCloseVirtual} = settings; const assignState = (update: Partial): void => { Object.assign(state, update); @@ -208,7 +209,9 @@ export const setupGarageDoorOpener = ( callback(); return; } - await toggleGarageDoor(); + if (targetDoorState == TargetDoorState.OPEN || (targetDoorState == TargetDoorState.CLOSED && !autoCloseVirtual)) { + await toggleGarageDoor(); + } assignCurrentDoorState(nextCurrentDoorState); // Handle Stopped state, if we are stopped, wait one second and trigger again to reverse course @@ -238,7 +241,8 @@ export const setupGarageDoorOpener = ( assignCurrentDoorState(CurrentDoorState.OPEN); if (autoCloseDelay) { await waitFor(`${deviceId}.pending`, autoCloseDelay); - assignCurrentDoorState(CurrentDoorState.CLOSED); + const targetDoorState = service.getCharacteristic(Characteristic.TargetDoorState); + targetDoorState.setValue(Characteristic.TargetDoorState.CLOSED); } } catch (err) { // debug(`Aborted OPEN update with delay=${chalkNumber(delay)}`); @@ -246,7 +250,7 @@ export const setupGarageDoorOpener = ( break; } case CurrentDoorState.CLOSING: { - const delay = (state.computedPosition * garageDoorDelay) / 100; + const delay = autoCloseDelay && autoCloseVirtual ? 1 * 1000 : (state.computedPosition * garageDoorDelay) / 100; // debug(`delay=${chalkNumber(delay)}`); try { await waitFor(`${deviceId}.pending`, delay);