Skip to content

Commit

Permalink
added the garage door switch
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelVdheeren committed Aug 29, 2020
1 parent ae2e8b1 commit 038b784
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 7 additions & 9 deletions abilities/garage-door-switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 4 additions & 1 deletion accessories/garage-door-openers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 038b784

Please sign in to comment.