-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[hue] Fix scene channel updates (API v2) #16018
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 scene channel updates (API v2) #16018
Conversation
beb9c25 to
efc42c6
Compare
| public void onResources(Collection<Resource> resources) { | ||
| boolean sceneActivated = false; | ||
| for (Resource resource : resources) { | ||
| boolean skipUpdate = sceneActivated && ResourceType.SCENE == resource.getType() |
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.
OK, if you really want to handle this perfectly then you need to process SMART_SCENE transitions as well. A room or a zone can have either a scene active, a smart scene active, or an inactive state. Therefore you need to handle transitions between all of those states.
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.
.. and yes, before you say so, I do admit that my prior PR was not handling smart scenes either ..
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.
OK, if you really want to handle this perfectly then you need to process SMART_SCENE transitions as well. A room or a zone can have either a scene active, a smart scene active, or an inactive state. Therefore you need to handle transitions between all of those states.
I think I only want to handle that if I can reproduce that, or receive payloads for verifying such issue. Using the app I found one scene which is actually a "smart scene": natural light. But it seems it will actually just transition through some "normal" scenes, so this already works. Do you know a way to create a smart scene that will appear in the payload as active/inactive?
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.
Do you know a way to create a smart scene that will appear in the payload as active/inactive?
No.
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.
I think I only want to handle that if I can reproduce that
Perhaps you can understand why @maniac103 thinks that I respond too strongly. If any suggestion is your idea, it is always perfect, no matter how much work is involved for the other party. But only if it is your idea. Whereas if I have an opinion you always say it is too difficult for you to implement, and always rule it out. Perhaps a little more flexibility, please.
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.
In response to:
If any suggestion is your idea, it is always perfect, no matter how much work is involved for the other party. But only if it is your idea. Whereas if I have an opinion you always say it is too difficult for you to implement, and always rule it out. Perhaps a little more flexibility, please.
and: #16001 (comment)
Sincerely, thanks for giving me this feedback, which will allow me to reflect and self-improve. My communication skills are definitely lacking.
This is no excuse, but just to give you some explanation. Besides the mandatory review feedback about openHAB compliance, conventions, guidelines etc. I try to give individualized reviews based on multiple factors. As an example, when reviewing a high quality contribution, I might suggest improvements I probably would not have suggested otherwise. Contributor history is also a parameter - the better I know a contributor, the better I can help by knowing how much details I should go into. Some appreciate even small comments that will give a slightly better end result, others prefer a faster merge and can get frustrated by too many comments.
I have gotten the impression that you are very detail-oriented, for example based on your review of my contributions and our discussions in general. I might therefore have made some false conclusions about your preferences. I'm sorry for that, and I'll try to recalibrate.
That said, I will also give you some personal feedback. For a long time I have felt hostility from you, and at times just plain rudeness. I'm sensitive to that, so it takes energy and motivation from me. If you have felt ignored, that might have been a consequence of me simply needing to take pauses from that, i.e. reduce interactions or "throttle down" if you will. I have also already tried to put much more consideration into how I phrase things to you, to not upset you. Sometimes it slips, especially if you have really pissed me off, to be frank. It should not, but I am human. Sorry.
Going forward, besides the recalibration I will make, on short term I can try my best to stay away as contributor and reviewer of the bindings for which you are code maintainer. That should reduce tensions, and I also need that for my mental health. I can't promise for how long, since I also enjoy working on improving these bindings. After all, this was my original motivation for becoming a contributor. So it will be a balance act.
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.
@jlaur many thanks for this apology; it seems that we may both be 'too detail oriented', and/or have mutually 'p**d each other off'; I therefore offer you also my apology (albeit not as eloquent as above).
My question now is how to proceed? Shall we continue with this PR? Or shall I adapt mine? I think the solution will ultimately be a combination of your code and mine. I have offered some code code below, so either you can take it over; or alternatively I can take over your code into my PR?
| boolean sceneActivated = false; | ||
| for (Resource resource : resources) { | ||
| boolean skipUpdate = sceneActivated && ResourceType.SCENE == resource.getType() | ||
| && resource.getSceneActive().isPresent(); |
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.
I think you need to check for !resource.getSceneActive().orElse(true)
And BTW likewise for SMART_SCENE
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.
And actually getSceneActive() resp. getSmartSceneActive() implicitly check the ResourceType internally so the ResourceType.SCENE == resource.getType() resp. ResourceType.SMART_SCENE == resource.getType() checks are not required.
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.
Just to help a bit more, getSmartSceneActive() and getSceneActive() return a tri-state result..
- Optional.ofEmpty() the resource is NOT a (smart-) scene
- Optional.of(false) the resource is a (smart-) scene and its state is inactive
- Optional.of(true) the resource is a (smart-) scene and its state is active (actually !inactive to be precise)
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.
I think you need to check for
!resource.getSceneActive().orElse(true)
Why?
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.
Because your current ifPresent() code returns true whether the next processed scene is active or inactive, whereas you only want to skip the scene if it is specifically inactive.
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.
That is intentional. There can't be more than one active scene (right?), so after reaching the first one, it doesn't make sense to process anything else.
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.
Please see my proposed code below.
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.
There can't be more than one active scene (right?)
There might be two scenes activated within one SSE package.
so after reaching the first one
We are supposed to be ignoring any IN-active messages in an SSE package, that also contains one (or more) active messages. So the suppression of the channel updates should only apply to the specifically IN-active messages.
In addition to the above, your code steps through the resources, so you may not detect a scene active until after your have received an inactive one; and thus generating the unwanted transient inactive channel state.
...ab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2ThingHandler.java
Outdated
Show resolved
Hide resolved
efc42c6 to
e696209
Compare
andrewfg
left a comment
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.
And I assume you will add Junit tests for this?
4fe6320 to
868d245
Compare
|
@jlaur your onResources() method should IMHO be as follows. EDIT: and here is some test code.. |
How would you like to proceed? You challenged/invited me to propose this alternative solution I have provided here. I can go along and add smart scene support to this PR assuming that smart scenes can be inactive exactly the same way as scenes, and that scenes and smart scenes are mutually exclusive. (It just bothers me that I can't test smart scene functionality, because I can't seem to create one) - and you can review. Or you can take over, if you think I'm too far from getting it right, and you can leave it for another maintainer if you prefer? Regarding unit test, I don't think I'll find the time for that since there is currently no coverage for the thing handler at all (I think), so it would need to be created from scratch. I don't quite understand the test code you have provided - it uses |
Yes the code I posted is not Junit capable. However I do have an idea how to create a Junit test around that. Therefore let me update my prior PR as proposed. As mentioned, I will take over your top level code from this PR, so it will be a combined effort. |
|
@jlaur I realised just now that the approach you propose in this PR is still wrong. Its aim is that if an SSE packet contains both a scene activate and a scene deactivate resource then the latter should be ignored. However this would only work if both scene resources belong to the same room or zone. By contrast if the two resources belong to different rooms or zones, then the deactivate resource should not be ignored. The more I think about this, the more I realise that this is a massive challenge, and the more I am convinced that the ‘perfect solution’ can’t make it into v4.1. My imperfect PR #16001 whilst not solving your basic requirements, would nevertheless at least allow the UI to show the correct status. So my suggestion as @maniac103 says would be to merge that one for v4.1 and get back to the perfect solution later. => WDYT? |
868d245 to
7d1c235
Compare
7d1c235 to
efbaed7
Compare
...ab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2ThingHandler.java
Show resolved
Hide resolved
efbaed7 to
e365ddc
Compare
Fixes openhab#16000 Also-by: Andrew Fiddian-Green <software@whitebear.ch> Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
e365ddc to
b6bb3a4
Compare
andrewfg
left a comment
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 (finally)
|
Thanks for all the effort and for overcoming your differences to provide us with a quick fix and a more thorough one as well as the binding in general! It‘s very much appreciated. |
lolodomo
left a comment
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, thank you
Fixes openhab#16000 Also-by: Andrew Fiddian-Green <software@whitebear.ch> Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk> Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
Fixes openhab#16000 Also-by: Andrew Fiddian-Green <software@whitebear.ch> Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This is a proposal for replacing the approach in #16001.
When receiving this payload:
[ { "creationtime": "2023-12-07T21:39:38Z", "data": [ { "id": "00000000-0000-0000-0000-000000000001", "id_v1": "/scenes/0000000000000001", "status": { "active": "static" }, "type": "scene" }, { "id": "00000000-0000-0000-0000-000000000002", "id_v1": "/scenes/0000000000000002", "status": { "active": "inactive" }, "type": "scene" } ], "id": "00000000-0000-0000-0000-000000000000", "type": "update" } ]The correct state change is triggered:
Also tested transition from
UNDEF-> scene and scene ->UNDEF.Since there is only one supported channel for resource type scene, it should be safe to skip
updateChannels()entirely for the resource:openhab-addons/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2ThingHandler.java
Lines 933 to 935 in 3814f37
Fixes #16000