Skip to content

Commit

Permalink
verticalSwing changes - rename swing parameter to verticalSwing where…
Browse files Browse the repository at this point in the history
… possible

add support for 3D swing (vertical+horizontal) and made to existing controls
remove swingMode characteristic from services when verticalSwing disabled in config
  • Loading branch information
benwebbbenwebb committed Jan 4, 2023
1 parent eef9d21 commit 44c5b2c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 49 deletions.
31 changes: 20 additions & 11 deletions homekit/AirConditioner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
45 changes: 19 additions & 26 deletions homekit/StateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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()
},

Expand Down Expand Up @@ -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()
},

Expand Down Expand Up @@ -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()
},

Expand All @@ -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()
},

Expand Down
46 changes: 34 additions & 12 deletions sensibo/unified.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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]) {
Expand Down

0 comments on commit 44c5b2c

Please sign in to comment.