-
-
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
[hue] Fix multiple state updates (API v2) #15905
[hue] Fix multiple state updates (API v2) #15905
Conversation
@jlaur I only just noticed this PR today. At first glance I would say that this is NOT a solution. Because I think there is actually NOT a problem that could or should be 'solved' within OH. As mentioned elsewhere the Hue system handles different DTOs orthogonally, and IMHO the binding must also handle them orthogonally. And attempting to munge one or more orthogonal DTOs into a common state change is not correct. |
^
Also as said before there are three ways that the bridge can send multiple events .. namely
Your 'solution' only tries to address 2. above. |
^ |
Hi @andrewfg, thanks for your feedback. Let me first make it clear that the provided draft is only in PoC/experimental state. I shared it to show that I'm working on this, and to possibly get early feedback - it worked. 😉 All your comments will be considered and addressed. Your good points about different types of events are quite important. It's clear to me now that this fix should be limited in scope to specifically address problems related to color, brightness and on/off, i.e. values that are separated on the API side and combined into the
This is already working correctly.
This is what I aim to fix with this PR.
I don't think there is anything to fix here, i.e. this is also working correctly already. When we receive completely separate events, we'll naturally (fully) process them one by one as we receive them. Going back to the issue... when we receive this payload (payload A): [
{
"creationtime": "2023-10-05T19:32:40Z",
"data": [
{
"id": "00000000-0000-0000-0000-000000000001",
"id_v1": "/lights/40",
"on": {
"on": true
},
"owner": {
"rid": "00000000-0000-0000-0000-000000000000",
"rtype": "device"
},
"type": "light"
},
{
"dimming": {
"brightness": 100.0
},
"id": "00000000-0000-0000-0000-000000000001",
"id_v1": "/lights/40",
"owner": {
"rid": "00000000-0000-0000-0000-000000000000",
"rtype": "device"
},
"type": "light"
}
],
"id": "00000000-0000-0000-0000-000000000002",
"type": "update"
}
] the bridge is telling us:
These are separate attributes, but we need to merge them into one
Now, if we would instead receive this payload (payload B) in step 4: [
{
"creationtime": "2023-10-05T19:32:40Z",
"data": [
{
"id": "00000000-0000-0000-0000-000000000001",
"id_v1": "/lights/40",
"on": {
"on": true
},
"dimming": {
"brightness": 100.0
},
"owner": {
"rid": "00000000-0000-0000-0000-000000000000",
"rtype": "device"
},
"type": "light"
}
],
"id": "00000000-0000-0000-0000-000000000002",
"type": "update"
}
] we could replay the example like this:
Therefore, I would clearly consider it a bug that payload A is currently handled like this when receiving a single event:
This causes flickering in the UI (because of two state updates), and can also cause issues in rules, like the one I have described in the linked issue. And it can be mitigated by merging the attributes before merging with the cache, i.e. in some sort of pre-processor logic. This way we'll reach the same final state, but without the intermediate "temporary" state causing the mentioned issues. As mentioned in my introduction, it should only apply to color, brightness and on/off. |
Ok. That makes sense. But I would ask that the Maybe just to point out one thing (in case you overlooked it): in your examples above you imply that the 'cache' is the channel HSBType value, which is not strictly true .. the cache actually comprises an XY pair, a Dimming, and an on-off attribute .. and as you imply (particularly when 'B' is close to zero, or when 'XY' is close to the edge of the Gamut) there will be round trip conversion issues between 'XY' and 'HS' .. and perhaps also between 'D', 'B', and on-off (particularly when 'D' is close to the minimum dimming level) .. so I advise that the pre-processing should cache and merge the 'XYDO' values (rather than the HSBType value) i.e. you should only make a one way final conversion 'XYDO' => 'HSB' when you actually set the HSBType on the channel. |
539157d
to
0ec236b
Compare
@andrewfg - are you still providing backports to 3.4.x? |
No. |
57610f9
to
489bff0
Compare
eb2b7ce
to
e8e885c
Compare
@wborn - does the integration test failure mean anything to you? EDIT: Sorry, I found the issue a few minutes after asking. That's how it works. 😉 |
174cf48
to
3897f06
Compare
@jlaur a few things..
|
3897f06
to
477a0fb
Compare
See last line of description. I found a bug causing auto update policy to be ignored when defined at channel level. This directly impacts this PR, unfortunately.
Yes, finally. 🙂
The scope should be what the title currently says. The only thing is that the issue turned out to have two different root causes. I tried to explain the thoroughly in the description, but please let me know if you need anything else. The linked issue only mentions one of those root causes, but they both have similar consequences. Therefore I decided to extend the original scope. It was a long way for me to get it to the current state, with a lot of testing and head banging, and also with a lot of changes now reverted. One thing that took me a while to understand is that all thing handlers receive all resources and maintain their own caches. Each has its own |
8ea3917
to
661b1d5
Compare
...binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/helper/Setters.java
Outdated
Show resolved
Hide resolved
...binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/helper/Setters.java
Outdated
Show resolved
Hide resolved
...binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/helper/Setters.java
Outdated
Show resolved
Hide resolved
...binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/helper/Setters.java
Outdated
Show resolved
Hide resolved
...binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/helper/Setters.java
Show resolved
Hide resolved
...b.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2BridgeHandler.java
Show resolved
Hide resolved
...enhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/Resource.java
Outdated
Show resolved
Hide resolved
...enhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/Resource.java
Outdated
Show resolved
Hide resolved
1de1f80
to
fb191d5
Compare
Since I am not able to progress with openhab/openhab-core#3888, I have extracted the auto update policy part into #15984. |
...binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/helper/Setters.java
Show resolved
Hide resolved
...binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/helper/Setters.java
Outdated
Show resolved
Hide resolved
...binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/helper/Setters.java
Outdated
Show resolved
Hide resolved
b4b3472
to
c2e36cc
Compare
...enhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/Resource.java
Outdated
Show resolved
Hide resolved
2a7d62a
to
fcecded
Compare
Fixes openhab#15700 Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
fcecded
to
5afad62
Compare
@jlaur I am a bit confused. You seem to have deleted some of your comments and my responses. (Probably a good thing). But can you please just update me on where you stand with the scope of this PR? I assume that you want to just handle the merge of multiple SSE events in this PR? And handle the other topic elsewhere? Is that correct? In which case I will do a final review of the PR on that basis. Is it all ready for my final review. And concerning the other topic, how do you want to proceed? As before I am willing to propose some code if you like. |
Not intentionally at least, but I resolved the comment we used for discussing today, since that is now a separate issue.
Yes.
Yes, see #15905 (comment).
You are welcome to propose. |
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
Yes I prefer it that way. I mean no criticism, but the process seems more fruitful when I write the code, and you review for compliance, and test case resolution. It also means the merge process can be faster. |
@jlaur I will create the PR tomorrow.. |
@lolodomo - we have three different Hue bugfixes at the moment, all concerning some quite related symptoms with undesired state updates. #15984 is blocked by a dependency towards a bugfix in core. #15999 needs test and review, so also not ready. However, this one is ready. Any chance of a quick review? 😉 That would help testing and managing the combined fix which is really needed, and therefore would be much appreciated. Most of the lines are test coverage. |
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.
Thanks for reviewing @andrewfg!
I just did a quick sanity check and guess we can merge. 👍
Thanks for the sanity check and merge, @kaikreuzer. 🙂 |
Fixes openhab#15700 Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk> Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
The overall goal of this pull request is to address issues with unneeded state updates that can happen under certain circumstances.
This can cause:
Three root causes have been identified:
Given an initial brightness of 0 and this command:
openhab> openhab:send Brightness 100 Command has been sent successfully.
Yielding this payload:
will result in the following events:
The reason for the state update back to 0 is that this part of the message is fully processed with channel update:
before processing the next message:
This means that the already cached brightness will be applied rather than the brightness received in the separate message. The final state will be correct, but an additional update is made.
Testing
In addition to the tests documented above, some manual regression tests performed:
Fixes #15700
Related to #15983