From 44c5b2c5a1191f7427acf77456d9bb138f93517c Mon Sep 17 00:00:00 2001 From: Ben Webb <31914419+benwebbbenwebb@users.noreply.github.com> Date: Thu, 5 Jan 2023 00:24:11 +1100 Subject: [PATCH] verticalSwing changes - rename swing parameter to verticalSwing where possible add support for 3D swing (vertical+horizontal) and made to existing controls remove swingMode characteristic from services when verticalSwing disabled in config --- homekit/AirConditioner.js | 31 ++++++++++++++++---------- homekit/StateManager.js | 45 ++++++++++++++++---------------------- sensibo/unified.js | 46 +++++++++++++++++++++++++++++---------- 3 files changed, 73 insertions(+), 49 deletions(-) diff --git a/homekit/AirConditioner.js b/homekit/AirConditioner.js index c09da9a..bb5fa87 100644 --- a/homekit/AirConditioner.js +++ b/homekit/AirConditioner.js @@ -95,7 +95,9 @@ class AirConditioner { this.removeDryService() } - if (((this.capabilities.COOL && this.capabilities.COOL.horizontalSwing) || (this.capabilities.HEAT && this.capabilities.HEAT.horizontalSwing)) && !this.disableHorizontalSwing) { + // TODO: see if HorizontalSwing can be created via a custom characteristic, rather than a separate accessory + // https://developers.homebridge.io/HAP-NodeJS/classes/Characteristic.html + if (!this.disableHorizontalSwing && ((this.capabilities.COOL && this.capabilities.COOL.horizontalSwing) || (this.capabilities.HEAT && this.capabilities.HEAT.horizontalSwing))) { this.addHorizontalSwingSwitch() } else { this.removeHorizontalSwingSwitch() @@ -206,10 +208,13 @@ class AirConditioner { this.HeaterCoolerService.getCharacteristic(Characteristic.CurrentRelativeHumidity) .on('get', this.stateManager.get.CurrentRelativeHumidity) - if (!this.disableVerticalSwing && ((this.capabilities.COOL && this.capabilities.COOL.swing) || (this.capabilities.HEAT && this.capabilities.HEAT.swing))) { + if (!this.disableVerticalSwing && ((this.capabilities.COOL && this.capabilities.COOL.verticalSwing) || (this.capabilities.HEAT && this.capabilities.HEAT.verticalSwing))) { this.HeaterCoolerService.getCharacteristic(Characteristic.SwingMode) .on('get', this.stateManager.get.ACSwing) .on('set', this.stateManager.set.ACSwing) + } else { + this.log.easyDebug('Removing Vertical Swing (Oscillate) button') + this.HeaterCoolerService.removeCharacteristic(Characteristic.SwingMode) } if ((this.capabilities.COOL && this.capabilities.COOL.fanSpeeds) || (this.capabilities.HEAT && this.capabilities.HEAT.fanSpeeds)) { @@ -243,10 +248,12 @@ class AirConditioner { .on('get', this.stateManager.get.FanActive) .on('set', this.stateManager.set.FanActive) - if (!this.disableVerticalSwing && this.capabilities.FAN.swing) { + if (!this.disableVerticalSwing && this.capabilities.FAN.verticalSwing) { this.FanService.getCharacteristic(Characteristic.SwingMode) .on('get', this.stateManager.get.FanSwing) .on('set', this.stateManager.set.FanSwing) + } else { + this.FanService.removeCharacteristic(Characteristic.SwingMode) } if (this.capabilities.FAN.fanSpeeds) { @@ -293,10 +300,12 @@ class AirConditioner { .on('get', this.stateManager.get.TargetHumidifierDehumidifierState) .on('set', this.stateManager.set.TargetHumidifierDehumidifierState) - if (!this.disableVerticalSwing && this.capabilities.DRY.swing) { + if (!this.disableVerticalSwing && this.capabilities.DRY.verticalSwing) { this.DryService.getCharacteristic(Characteristic.SwingMode) .on('get', this.stateManager.get.DrySwing) .on('set', this.stateManager.set.DrySwing) + } else { + this.DryService.removeCharacteristic(Characteristic.SwingMode) } if (this.capabilities.DRY.fanSpeeds) { @@ -438,9 +447,9 @@ class AirConditioner { this.updateValue('HeaterCoolerService', 'HeatingThresholdTemperature', this.state.targetTemperature) this.updateValue('HeaterCoolerService', 'CoolingThresholdTemperature', this.state.targetTemperature) - // update swing for HeaterCoolerService - if (!this.disableVerticalSwing && this.capabilities[this.state.mode].swing) { - this.updateValue('HeaterCoolerService', 'SwingMode', Characteristic.SwingMode[this.state.swing]) + // update vertical swing for HeaterCoolerService + if (!this.disableVerticalSwing && this.capabilities[this.state.mode].VerticalSwing) { + this.updateValue('HeaterCoolerService', 'SwingMode', Characteristic.SwingMode[this.state.verticalSwing]) } // update horizontal swing for HeaterCoolerService @@ -497,8 +506,8 @@ class AirConditioner { this.updateValue('FanService', 'Active', 1) // update swing for FanService - if (!this.disableVerticalSwing && this.capabilities.FAN.swing) { - this.updateValue('FanService', 'SwingMode', Characteristic.SwingMode[this.state.swing]) + if (!this.disableVerticalSwing && this.capabilities.FAN.verticalSwing) { + this.updateValue('FanService', 'SwingMode', Characteristic.SwingMode[this.state.verticalSwing]) } // update fanSpeed for FanService @@ -525,8 +534,8 @@ class AirConditioner { this.updateValue('DryService', 'CurrentHumidifierDehumidifierState', Characteristic.CurrentHumidifierDehumidifierState.DEHUMIDIFYING) // update swing for FanService - if (!this.disableVerticalSwing && this.capabilities.DRY.swing) { - this.updateValue('DryService', 'SwingMode', Characteristic.SwingMode[this.state.swing]) + if (!this.disableVerticalSwing && this.capabilities.DRY.verticalSwing) { + this.updateValue('DryService', 'SwingMode', Characteristic.SwingMode[this.state.verticalSwing]) } // update fanSpeed for FanService diff --git a/homekit/StateManager.js b/homekit/StateManager.js index de5fafb..c3598e8 100644 --- a/homekit/StateManager.js +++ b/homekit/StateManager.js @@ -165,9 +165,7 @@ module.exports = (device, platform) => { }, ACSwing: (callback) => { - // const active = device.state.active - // const mode = device.state.mode - const swing = device.state.swing + const swing = device.state.verticalSwing log.easyDebug(device.name, '(GET) - AC Swing is:', swing) callback(null, Characteristic.SwingMode[swing]) @@ -217,9 +215,7 @@ module.exports = (device, platform) => { }, FanSwing: (callback) => { - // const active = device.state.active - // const mode = device.state.mode - const swing = device.state.swing + const swing = device.state.verticalSwing log.easyDebug(device.name, '(GET) - Fan Swing is:', swing) callback(null, Characteristic.SwingMode[swing]) @@ -271,9 +267,7 @@ module.exports = (device, platform) => { }, DrySwing: (callback) => { - // const active = device.state.active - // const mode = device.state.mode - const swing = device.state.swing + const swing = device.state.verticalSwing log.easyDebug(device.name, '(GET) - Dry Swing is:', swing) callback(null, Characteristic.SwingMode[swing]) @@ -433,17 +427,15 @@ module.exports = (device, platform) => { }, ACSwing: (state, callback) => { - state = state === Characteristic.SwingMode.SWING_ENABLED ? 'SWING_ENABLED' : 'SWING_DISABLED' - log.easyDebug(device.name + ' -> Setting AC Swing:', state) - device.state.swing = state - + const status = state === Characteristic.SwingMode.SWING_ENABLED ? 'SWING_ENABLED' : 'SWING_DISABLED' const lastMode = device.HeaterCoolerService.getCharacteristic(Characteristic.TargetHeaterCoolerState).value const mode = characteristicToMode(lastMode) + log.easyDebug(device.name + ' -> Setting AC Swing:', status) log.easyDebug(device.name + ' -> Setting Mode to', mode) - device.state.active = true + device.state.verticalSwing = status device.state.mode = mode - + device.state.active = true callback() }, @@ -497,13 +489,13 @@ module.exports = (device, platform) => { }, FanSwing: (state, callback) => { - state = state === Characteristic.SwingMode.SWING_ENABLED ? 'SWING_ENABLED' : 'SWING_DISABLED' - log.easyDebug(device.name + ' -> Setting Fan Swing:', state) - device.state.swing = state + const status = state === Characteristic.SwingMode.SWING_ENABLED ? 'SWING_ENABLED' : 'SWING_DISABLED' - device.state.active = true + log.easyDebug(device.name + ' -> Setting Fan Swing:', status) log.easyDebug(device.name + ' -> Setting Mode to: FAN') + device.state.verticalSwing = status device.state.mode = 'FAN' + device.state.active = true callback() }, @@ -541,13 +533,13 @@ module.exports = (device, platform) => { }, DrySwing: (state, callback) => { - state = state === Characteristic.SwingMode.SWING_ENABLED ? 'SWING_ENABLED' : 'SWING_DISABLED' - log.easyDebug(device.name + ' -> Setting Dry Swing:', state) - device.state.swing = state + const status = state === Characteristic.SwingMode.SWING_ENABLED ? 'SWING_ENABLED' : 'SWING_DISABLED' - device.state.active = true + log.easyDebug(device.name + ' -> Setting Dry Swing:', status) log.easyDebug(device.name + ' -> Setting Mode to: DRY') + device.state.verticalSwing = status device.state.mode = 'DRY' + device.state.active = true callback() }, @@ -562,9 +554,10 @@ module.exports = (device, platform) => { // HORIZONTAL SWING HorizontalSwing: (state, callback) => { - state = state ? 'SWING_ENABLED' : 'SWING_DISABLED' - log.easyDebug(device.name + ' -> Setting Horizontal Swing Swing:', state) - device.state.horizontalSwing = state + const status = state ? 'SWING_ENABLED' : 'SWING_DISABLED' + + log.easyDebug(device.name + ' -> Setting Horizontal Swing:', status) + device.state.horizontalSwing = status callback() }, diff --git a/sensibo/unified.js b/sensibo/unified.js index 3d7a064..57fd9bb 100644 --- a/sensibo/unified.js +++ b/sensibo/unified.js @@ -111,18 +111,28 @@ module.exports = { } } - // set swing - if (modeCapabilities.swing && modeCapabilities.swing.includes('rangeFull')) { - capabilities[mode].swing = true + // set vertical swing + if (modeCapabilities.swing) { + if (modeCapabilities.swing.includes('both')) { + capabilities[mode].horizontalSwing = true + capabilities[mode].verticalSwing = true + capabilities[mode].threeDimensionalSwing = true + } else { + if (modeCapabilities.swing.includes('rangeFull')) { + capabilities[mode].verticalSwing = true + } + + if (modeCapabilities.swing.includes('horizontal')) { + capabilities[mode].horizontalSwing = true + } + } } // set horizontal swing - if (modeCapabilities.horizontalSwing && modeCapabilities.horizontalSwing.includes('rangeFull')) { + if (!capabilities[mode].horizontalSwing && modeCapabilities.horizontalSwing && modeCapabilities.horizontalSwing.includes('rangeFull')) { capabilities[mode].horizontalSwing = true } - // TODO: unify how swing works with 3D - // set light if (modeCapabilities.light) { capabilities[mode].light = true @@ -162,7 +172,7 @@ module.exports = { const modeCapabilities = device.remoteCapabilities.modes[device.acState.mode] if (modeCapabilities.swing && modeCapabilities.swing.includes('rangeFull')) { - state.swing = device.acState.swing === 'rangeFull' ? 'SWING_ENABLED' : 'SWING_DISABLED' + state.verticalSwing = device.acState.verticalSwing === 'rangeFull' ? 'SWING_ENABLED' : 'SWING_DISABLED' } if (modeCapabilities.horizontalSwing && modeCapabilities.horizontalSwing.includes('rangeFull')) { @@ -237,12 +247,24 @@ module.exports = { targetTemperature: device.usesFahrenheit ? toFahrenheit(state.targetTemperature) : state.targetTemperature } - if ('swing' in device.capabilities[state.mode]) { - acState.swing = state.swing === 'SWING_ENABLED' ? 'rangeFull' : 'stopped' - } + if ('threeDimensionalSwing' in device.capabilities[state.mode]) { + if ((state.horizontalSwing === 'SWING_ENABLED') && (state.verticalSwing === 'SWING_ENABLED')) { + acState.swing = 'both' + } else if (state.verticalSwing === 'SWING_ENABLED') { + acState.swing = 'rangeFull' + } else if (state.horizontalSwing === 'SWING_ENABLED') { + acState.swing = 'horizontal' + } else { + acState.swing = 'stopped' + } + } else { + if ('verticalSwing' in device.capabilities[state.mode]) { + acState.swing = state.verticalSwing === 'SWING_ENABLED' ? 'rangeFull' : 'stopped' + } - if ('horizontalSwing' in device.capabilities[state.mode]) { - acState.horizontalSwing = state.horizontalSwing ==='SWING_ENABLED' ? 'rangeFull' : 'stopped' + if ('horizontalSwing' in device.capabilities[state.mode]) { + acState.horizontalSwing = state.horizontalSwing === 'SWING_ENABLED' ? 'rangeFull' : 'stopped' + } } if ('fanSpeeds' in device.capabilities[state.mode]) {