From fe8dea90ec451f933376e97491bcc8ba271f7109 Mon Sep 17 00:00:00 2001 From: Luke Rhodes Date: Wed, 1 Jan 2020 13:06:14 +1100 Subject: [PATCH] =?UTF-8?q?Support=20for=20a=20=E2=80=9Cwindow=E2=80=9D=20?= =?UTF-8?q?accessory=20that=20mimic=20the=20functionality=20of=20a=20windo?= =?UTF-8?q?w-covering=20(#494)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- accessories/index.js | 2 ++ accessories/window.js | 50 +++++++++++++++++++++++++++++++++++++++++++ platform.js | 1 + 3 files changed, 53 insertions(+) create mode 100644 accessories/window.js diff --git a/accessories/index.js b/accessories/index.js index 3007e668..7017d4bc 100644 --- a/accessories/index.js +++ b/accessories/index.js @@ -9,6 +9,7 @@ const Fan = require('./fan'); const GarageDoorOpener = require('./garageDoorOpener'); const Lock = require('./lock'); const Light = require('./light'); +const Window = require('./window'); const WindowCovering = require('./windowCovering'); module.exports = { @@ -23,5 +24,6 @@ module.exports = { GarageDoorOpener, Lock, Light, + Window, WindowCovering } diff --git a/accessories/window.js b/accessories/window.js new file mode 100644 index 00000000..36ad533a --- /dev/null +++ b/accessories/window.js @@ -0,0 +1,50 @@ +const { assert } = require('chai'); + +const delayForDuration = require('../helpers/delayForDuration'); +const ServiceManagerTypes = require('../helpers/serviceManagerTypes'); +const catchDelayCancelError = require('../helpers/catchDelayCancelError'); +const WindowCoveringAccessory = require('./windowCovering'); + +class WindowAccessory extends WindowCoveringAccessory { + + setupServiceManager () { + const { data, log, name, serviceManagerType } = this; + + this.serviceManager = new ServiceManagerTypes[serviceManagerType](name, Service.Window, log); + + this.serviceManager.addToggleCharacteristic({ + name: 'currentPosition', + type: Characteristic.CurrentPosition, + bind: this, + getMethod: this.getCharacteristicValue, + setMethod: this.setCharacteristicValue, + props: { + + } + }); + + this.serviceManager.addToggleCharacteristic({ + name: 'positionState', + type: Characteristic.PositionState, + bind: this, + getMethod: this.getCharacteristicValue, + setMethod: this.setCharacteristicValue, + props: { + + } + }); + + this.serviceManager.addToggleCharacteristic({ + name: 'targetPosition', + type: Characteristic.TargetPosition, + bind: this, + getMethod: this.getCharacteristicValue, + setMethod: this.setCharacteristicValue, + props: { + setValuePromise: this.setTargetPosition.bind(this) + } + }); + } +} + +module.exports = WindowCoveringAccessory; diff --git a/platform.js b/platform.js index f0fe656d..a61bf6d3 100644 --- a/platform.js +++ b/platform.js @@ -20,6 +20,7 @@ const classTypes = { 'fan': Accessory.Fan, 'outlet': Accessory.Outlet, 'light': Accessory.Light, + 'window': Accessory.Window, 'window-covering': Accessory.WindowCovering, }