From 038b784d07a7291eb537aae2bf0c217a6782bdc1 Mon Sep 17 00:00:00 2001 From: Michael Vanderheeren Date: Mon, 1 Jun 2020 23:15:17 +0200 Subject: [PATCH] added the garage door switch --- abilities/garage-door-switch.js | 16 +++++++--------- accessories/garage-door-openers.js | 5 ++++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/abilities/garage-door-switch.js b/abilities/garage-door-switch.js index 55cc255..f0985a3 100644 --- a/abilities/garage-door-switch.js +++ b/abilities/garage-door-switch.js @@ -7,7 +7,8 @@ module.exports = homebridge => { class GarageDoorSwitchAbility extends Ability { /** - * @param {string} switchProperty - The device property to trigger the garage door to open or close. + * @param {string} switchProperty - The device property to trigger the + * garage door to open or close. * @param {string} stateProperty - The device property used to indicate the * garage door is closed. * @param {function} setSwitch - A function that updates the device's switch @@ -22,11 +23,11 @@ module.exports = homebridge => { } get state() { - return this.device[this._stateProperty] || 0; + return this.device[this._stateProperty] || 0 } get isSwitchedOn() { - return this.device[this._switchProperty] || false; + return this.device[this._switchProperty] || false } get currentState() { @@ -76,12 +77,12 @@ module.exports = homebridge => { this.platformAccessory .getService(Service.GarageDoorOpener) .getCharacteristic(Characteristic.CurrentDoorState) - .on('get', this.getState.bind(this)); + .on('get', this.getState.bind(this)) this.platformAccessory .getService(Service.GarageDoorOpener) .getCharacteristic(Characteristic.TargetDoorState) - .on('get', this.getState.bind(this)); + .on('get', this.getState.bind(this)) // This is the handler to catch device events // This one is always correct! @@ -192,10 +193,7 @@ module.exports = homebridge => { } getState(callback) { - const CDS = Characteristic.CurrentDoorState - const TDS = Characteristic.TargetDoorState - - callback(null, this.currentState); + callback(null, this.currentState) } detach() { diff --git a/accessories/garage-door-openers.js b/accessories/garage-door-openers.js index 4d328ad..f8ad241 100644 --- a/accessories/garage-door-openers.js +++ b/accessories/garage-door-openers.js @@ -5,7 +5,10 @@ module.exports = homebridge => { require('../abilities/garage-door-switch')(homebridge) const GarageDoorOpenerAbility = require('../abilities/garage-door-opener')(homebridge) - const { ShellyAccessory, ShellyRelayAccessory } = require('./base')(homebridge) + const { + ShellyAccessory, + ShellyRelayAccessory + } = require('./base')(homebridge) class Shelly1GarageDoorSwitchAccessory extends ShellyRelayAccessory { constructor(device, index, config, log) {