Skip to content

Commit

Permalink
fix an issue where Siri would return 2%
Browse files Browse the repository at this point in the history
fix an issue where speed was incorrect when becoming active again
  • Loading branch information
MichaelVdheeren committed Mar 8, 2021
1 parent cacef87 commit ce6e1e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
35 changes: 19 additions & 16 deletions abilities/two-speed-fan.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ module.exports = homebridge => {
.getCharacteristic(Characteristic.RotationSpeed)
.setProps({
minValue: 0,
maxValue: 2,
minStep: 1
maxValue: 100,
minStep: 50
})
.on('get', this.getSpeed.bind(this))
.on('set', this._targetSpeedSetHandler.bind(this))
Expand All @@ -70,9 +70,9 @@ module.exports = homebridge => {

get speed() {
if (this.device[this._speedTwoProperty]) {
return 2
return 100
} else if (this.device[this._speedOneProperty]) {
return 1
return 50
}

return 0
Expand Down Expand Up @@ -104,6 +104,8 @@ module.exports = homebridge => {
)

try {
// Always keep track of the last speed set
this._lastSpeed = value
await this._setSpeed(value)
callback()
} catch (e) {
Expand Down Expand Up @@ -144,24 +146,23 @@ module.exports = homebridge => {
}

_stateChangeHandler() {
// Always keep track of the last speed set
this._lastSpeed = this.speed

this.platformAccessory
.getService(Service.Fanv2)
.getCharacteristic(Characteristic.RotationSpeed)
.setValue(this.speed, null, 'shelly')

this.platformAccessory
.getService(Service.Fanv2)
.getCharacteristic(Characteristic.Active)
.setValue(this.active, null, 'shelly')

if (this.active > 0) {
this.platformAccessory
.getService(Service.Fanv2)
.getCharacteristic(Characteristic.RotationSpeed)
.setValue(this.speed, null, 'shelly')
}
}

async _targetActiveSetHandler(value, callback, context) {
async _targetActiveSetHandler(newValue, callback, context) {
const d = this.device

if (context === 'shelly' || this.active === value) {
if (context === 'shelly' || this.active === newValue) {
callback()
return
}
Expand All @@ -172,11 +173,13 @@ module.exports = homebridge => {
d.type,
d.id,
'to',
value
newValue
)

try {
if (value === 0) {
if (newValue === 0) {
// Always keep track of the last speed set
this._lastSpeed = this.speed
await this._setSpeed(0)
} else {
await this._setSpeed(this._lastSpeed)
Expand Down
4 changes: 2 additions & 2 deletions accessories/fan.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ module.exports = homebridge => {
await this.device.setRelay(this.index, false)
await this.device.setRelay(this.index + 1, false)
break
case 1:
case 50:
await this.device.setRelay(this.index, true)
await this.device.setRelay(this.index + 1, false)
break
case 2:
case 100:
await this.device.setRelay(this.index, false)
await this.device.setRelay(this.index + 1, true)
break
Expand Down

0 comments on commit ce6e1e5

Please sign in to comment.