Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent PositionableAbility.targetPosition from being set to 0% or 100% unless the Shelly has been manually controlled #325

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions abilities/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ module.exports = homebridge => {
this._setPositionTimeout = null
this._targetPosition = null
this._targetPositionTimeout = null
this._prevStopPosition = 0
}

/**
Expand Down Expand Up @@ -164,11 +165,15 @@ module.exports = homebridge => {

callback()

if (this.targetPosition === newValue ||
this._setPositionTimeout !== null) {
if (this.targetPosition === newValue) {
return
}

if (this._setPositionTimeout !== null) {
clearTimeout(this._setPositionTimeout)
this.__setPositionTimeout = null
}

this._setPositionTimeout = setTimeout(async () => {
this.log.debug(
'Setting',
Expand Down Expand Up @@ -229,10 +234,6 @@ module.exports = homebridge => {
newValue
)

this.service
.getCharacteristic(Characteristic.CurrentPosition)
.setValue(this.position)

this._updateTargetPositionDebounced()
}

Expand Down Expand Up @@ -261,11 +262,17 @@ module.exports = homebridge => {

if (state === 'stop') {
targetPosition = position
} else if (state === 'open' && this.targetPosition <= position) {
this._prevStopPosition = position

this.service
.getCharacteristic(Characteristic.CurrentPosition)
.setValue(position)

} else if (state === 'open' && this.targetPosition === this._prevStopPosition) {
// we don't know what the target position is here, but we set it
// to 100 so that the interface shows that the roller is opening
targetPosition = 100
} else if (state === 'close' && this.targetPosition >= position) {
} else if (state === 'close' && this.targetPosition === this._prevStopPosition) {
// we don't know what the target position is here, but we set it
// to 0 so that the interface shows that the roller is closing
targetPosition = 0
Expand Down