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

Improve UX of WindowCovering by using motor_state #854

Merged
merged 11 commits into from
Jun 30, 2024

Conversation

burmistrzak
Copy link
Contributor

@burmistrzak burmistrzak commented Apr 28, 2024

Implements support for the optional motor_state attribute exposed by some coverings, while keeping the current behavior for all others.

📌 Unfortunately, it's not really feasible to improve HAP compliance for devices that do not support motor_state, without removing features.

Fixes #852

@burmistrzak burmistrzak marked this pull request as draft April 29, 2024 02:48
@burmistrzak
Copy link
Contributor Author

burmistrzak commented Apr 29, 2024

@itavero What about utilizing motor_state for PositionState on devices that support it?

So we're only updating CurrentPosition when motor_state != idle, and in cases where the command didn't come from Home.app, we just set TargetPosition to the corresponding max value, i.e. opening => 0; closing => 100 because we'll set the final target value anyways, once PositionState is STOPPED.

All other devices however, would be stuck with the current implementation.

Another relevant PR has been merged: Koenkk/zigbee-herdsman-converters#7470

@burmistrzak burmistrzak changed the title Improve UX of WindowCovering with Bosch BCMT-SLZ Improve UX of WindowCovering by using motor_state May 6, 2024
@burmistrzak burmistrzak marked this pull request as ready for review May 6, 2024 18:53
@burmistrzak
Copy link
Contributor Author

@itavero Did you already had time to take a look at the PR?
I personally would have preferred to check for motor_state like you did with position and tilt, but unfortunately motor_state is not part of features...

@itavero
Copy link
Owner

itavero commented May 14, 2024

Did you already had time to take a look at the PR?

Unfortunately I have not had time. Hopefully I can find a moment this week to do at least a quick check, but my schedule is still quite busy.

@burmistrzak
Copy link
Contributor Author

Unfortunately I have not had time. Hopefully I can find a moment this week to do at least a quick check, but my schedule is still quite busy.

Don't worry. 😊
Just let me know if I can help out somehow!

@burmistrzak
Copy link
Contributor Author

@itavero Would appreciate if you can already run the two workflows, so I can make any necessary changes in due time. ✌️

src/converters/cover.ts Outdated Show resolved Hide resolved
src/converters/cover.ts Outdated Show resolved Hide resolved
Copy link

codecov bot commented May 22, 2024

Codecov Report

Attention: Patch coverage is 91.22807% with 5 lines in your changes missing coverage. Please review.

Project coverage is 64.03%. Comparing base (31b0fd9) to head (62fb214).
Report is 12 commits behind head on master.

Current head 62fb214 differs from pull request most recent head d81fb3c

Please upload reports for the commit d81fb3c to get more accurate results.

Files Patch % Lines
src/converters/cover.ts 91.22% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #854      +/-   ##
==========================================
- Coverage   66.17%   64.03%   -2.14%     
==========================================
  Files          40       40              
  Lines        2903     2550     -353     
  Branches      792      659     -133     
==========================================
- Hits         1921     1633     -288     
+ Misses        883      747     -136     
- Partials       99      170      +71     
Flag Coverage Δ
tests 64.03% <91.22%> (-2.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@burmistrzak burmistrzak requested a review from itavero May 22, 2024 01:59
src/converters/cover.ts Outdated Show resolved Hide resolved
@burmistrzak
Copy link
Contributor Author

@itavero Alright, I've completely reworked how we're checking for the presence of motor_state, should now also work with multiple endpoints. 😅

src/converters/cover.ts Outdated Show resolved Hide resolved
src/converters/cover.ts Outdated Show resolved Hide resolved
src/converters/cover.ts Outdated Show resolved Hide resolved
CoverHandler.generateIdentifier(m.endpoint) === CoverHandler.generateIdentifier(e.endpoint) &&
m.type === ExposesKnownTypes.ENUM &&
m.name === 'motor_state' &&
exposesHasEnumProperty(m) &&
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also check if it is published by Zigbee2MQTT.

Suggested change
exposesHasEnumProperty(m) &&
exposesIsPublished(m) &&
exposesHasEnumProperty(m) &&

src/converters/cover.ts Outdated Show resolved Hide resolved
src/converters/cover.ts Outdated Show resolved Hide resolved
src/converters/cover.ts Outdated Show resolved Hide resolved
src/converters/cover.ts Outdated Show resolved Hide resolved
@itavero
Copy link
Owner

itavero commented May 23, 2024

Should probably also mention this in the changelog and the docs for the window covering, but I can also do that before merging the code.

@burmistrzak
Copy link
Contributor Author

@itavero Implemented the changes you've suggested. Based on my testing, everything still works! 😅

@burmistrzak
Copy link
Contributor Author

@itavero I've been dog-fooding this PR for the past few days, and it's working quite nicely. So from my side, we should be ready for takeoff. 🛫

Copy link
Owner

@itavero itavero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a glance at the other changes and they seem fine. Hopefully I'll have time to do a proper review in the next few days and get this thing merged.

Sonarcloud is also complaining about the complexity of scaleAndUpdateCurrentPosition, but I think I can live with that for now.

src/converters/cover.ts Outdated Show resolved Hide resolved
@burmistrzak
Copy link
Contributor Author

@itavero Alright, our robot overlords 🤖 should now be pleased. 😅

@burmistrzak burmistrzak requested a review from itavero May 30, 2024 16:31
@itavero
Copy link
Owner

itavero commented Jun 13, 2024

@burmistrzak Sorry that I didn't get around to merging and releasing this. I've been busy moving my home office to another room, which is taking a bit more time than I hoped. I will try to wrap this PR up in the coming week. 🤞

@burmistrzak
Copy link
Contributor Author

@itavero That's alright. Having a good workplace setup is quite important. 👌

@burmistrzak
Copy link
Contributor Author

@itavero Are there any blocking issues you want me to take a look at?
Would be great if we can get this out the door before the next Zigbee2MQTT release, because I still need some time to validate recent changes to the relevant Bosch converters. 😊

@itavero
Copy link
Owner

itavero commented Jun 19, 2024

Sorry. Haven't gotten around to it yet.
I have some time off from work next week, so I hope to merge and release it during that time or before.

@burmistrzak
Copy link
Contributor Author

Sorry. Haven't gotten around to it yet. I have some time off from work next week, so I hope to merge and release it during that time or before.

Would be great timing!
I'll be starting work on #882 in the meantime then. ✌️

@burmistrzak
Copy link
Contributor Author

@itavero Do you think we'll be able to finish this up before tomorrow's Zigbee2MQTT release? 🤞

switch (this.motorState) {
case CoverHandler.MOTOR_STATE_CLOSING:
newPositionState = hap.Characteristic.PositionState.DECREASING;
newTargetPosition = 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@burmistrzak Just wondering, did you also check the UX by setting a target position from the app to a value less than 100 or greater than 0?

I'm curious if these fixed values of 0 and 100 for newTargetPosition are okay, or if they may also lead to weird behavior.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge it for now. We can always improve it later, if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itavero Well, that's how certified accessories do it. 😅
We only update the target position when the command is not coming from HomeKit (e.g. a physical switch, etc.), because the HAP controller doesn't already know about the new target.
So in case of a physical switch, setting the max value makes total sense, IMHO.

However, when e.g. MQTT is used to set a new target position, we can't really distinguish between a new target position and the current position. That's a quirk of Zigbee2MQTT, that I might have to address upstream.

Copy link

sonarcloud bot commented Jun 30, 2024

Copy link
Contributor

🆗 Published SonarCloud and code coverage data.

@itavero itavero merged commit 8374850 into itavero:master Jun 30, 2024
5 checks passed
@itavero
Copy link
Owner

itavero commented Jun 30, 2024

Part of release 1.11.0-beta.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] TargetPosition of WindowCovering shouldn't update while in motion
2 participants