-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[hdpowerview] Update positions after triggering scene/scene group #11768
[hdpowerview] Update positions after triggering scene/scene group #11768
Conversation
Fixes openhab#11697 Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Jacob Laursen <[email protected]>
I think equals() and == compile to the same thing. ?? |
Also wondering if you should replace the pollshades() calls with scheduler.submit([ -> | pollshades()]) ?? |
See https://stackoverflow.com/questions/1750435/comparing-java-enum-members-or-equals So it's faster and safer at compile-time as well as runtime. |
Signed-off-by: Jacob Laursen <[email protected]>
Done. |
@jlaur, thanks for putting this together. It all looks good to me. Do you have a JAR available so that I can try using it? |
@jlaur, thanks for sharing the JAR. I tested it out on my machine, and it worked great. Similar to your testing, I saw that the shade positions got updated in ~4 seconds after triggering a scene, rather than up to 1 min like before. I didn't see any issues. Thanks again for this fix. |
...ew/src/main/java/org/openhab/binding/hdpowerview/internal/handler/HDPowerViewHubHandler.java
Outdated
Show resolved
Hide resolved
...ew/src/main/java/org/openhab/binding/hdpowerview/internal/handler/HDPowerViewHubHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Jacob Laursen <[email protected]>
@andrewfg - please see thread from @lolodomo's comment. Decided to revert and go back to synchronous HTTP call for simplicity. Only difference is that we have two sync calls where previously we had one. With the previous changes we would have one sync and one async, and it became messy. |
I don’t agree. I am not so much concerned about an extra HTTP call. What concerns me is that you are making re-entrant calls to the OH core; whilst you are still within handleCommand() for one channel, you run pollShades which makes multiple updateChannel callbacks to the core; in fact one call back from each channel and each shade in your system. So your handleCommand could potentially cause the OH core to block on itself. Not good. |
Ahh - thanks for this explanation. New approach needed, marking PR as draft. |
Perhaps your prior attempt was overkill; I understand why you had to wrap the asynch pollShades call in an exception handler, but perhaps it is easier to let the existing code do the heavy lifting rather than reinventing the wheel; so after handleCommand triggered the scene, you could just 'submit' a call to
|
and we need only one of them. Still, it would be much simpler like you described, so could be refactored into something like that. My concern is that if we schedule a fire-and-forget call like that, we might have a problem in case |
Perhaps we could reschedule existing future as a compromise? We would still fetch everything, but at least we would postpone next ordinary poll for another minute:
And we would have the future cancelled from |
I think there is no need to worry about that: firstly the sheduler is part of the core, so if the core is shutting down, it will do so cleanly (it won't start un-run tasks, and it won't interrupt already running ones); and secondly the poll method is marked as synchronized so it cannot be called in parrallel. Obviously if you unpack the poll() method, you will need to think carefully about placing the synchronized marker on any of its parts, since you would be introducing a risk of self blocking between regular polls and this special poll. In summary I would still just submit poll; who cares if its updating other channels? It is essentially just doing another regular poll a bit earlier than the normal polling cycle would do so.. |
Yes, that would work. |
Signed-off-by: Jacob Laursen <[email protected]>
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
int id = Integer.parseInt(channelUID.getIdWithoutGroup()); | ||
if (sceneChannelTypeUID.equals(channel.getChannelTypeUID()) && OnOffType.ON.equals(command)) { | ||
if (sceneChannelTypeUID.equals(channel.getChannelTypeUID()) && OnOffType.ON == command) { | ||
webTargets.activateScene(id); | ||
} else if (sceneGroupChannelTypeUID.equals(channel.getChannelTypeUID()) && OnOffType.ON.equals(command)) { | ||
// Reschedule soft poll for immediate shade position update. | ||
scheduleSoftPoll(0); | ||
} else if (sceneGroupChannelTypeUID.equals(channel.getChannelTypeUID()) && OnOffType.ON == command) { | ||
webTargets.activateSceneCollection(id); | ||
// Reschedule soft poll for immediate shade position update. | ||
scheduleSoftPoll(0); | ||
} else if (automationChannelTypeUID.equals(channel.getChannelTypeUID())) { | ||
webTargets.enableScheduledEvent(id, OnOffType.ON.equals(command)); | ||
webTargets.enableScheduledEvent(id, OnOffType.ON == command); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…enhab#11768) * Update positions after triggering scene/scene group. * Compare enum values directly with == * Fix re-entrant calls. Fixes openhab#11697 Signed-off-by: Jacob Laursen <[email protected]>
…enhab#11768) * Update positions after triggering scene/scene group. * Compare enum values directly with == * Fix re-entrant calls. Fixes openhab#11697 Signed-off-by: Jacob Laursen <[email protected]> Signed-off-by: Nick Waterton <[email protected]>
…enhab#11768) * Update positions after triggering scene/scene group. * Compare enum values directly with == * Fix re-entrant calls. Fixes openhab#11697 Signed-off-by: Jacob Laursen <[email protected]> Signed-off-by: Michael Schmidt <[email protected]>
…enhab#11768) * Update positions after triggering scene/scene group. * Compare enum values directly with == * Fix re-entrant calls. Fixes openhab#11697 Signed-off-by: Jacob Laursen <[email protected]>
…enhab#11768) * Update positions after triggering scene/scene group. * Compare enum values directly with == * Fix re-entrant calls. Fixes openhab#11697 Signed-off-by: Jacob Laursen <[email protected]>
…enhab#11768) * Update positions after triggering scene/scene group. * Compare enum values directly with == * Fix re-entrant calls. Fixes openhab#11697 Signed-off-by: Jacob Laursen <[email protected]> Signed-off-by: Andras Uhrin <[email protected]>
When triggering a scene or scene group, some shades will have new positions. These new positions are available in the hub immediately after triggering the scene or scene group, i.e. before the shades will reach those new positions.
Previously it would take up to one minute to have the positions refreshed. Now it will happen a few seconds after the scene or scene group has been triggered.
Fixes #11697
Signed-off-by: Jacob Laursen [email protected]
Test documentation
Before change:
After change:
And back: