Skip to content

State machine to model lights in Thing handlers - #4995

Merged
holgerfriedrich merged 74 commits into
openhab:mainfrom
andrewfg:light-helpers
Mar 29, 2026
Merged

State machine to model lights in Thing handlers#4995
holgerfriedrich merged 74 commits into
openhab:mainfrom
andrewfg:light-helpers

Conversation

@andrewfg

@andrewfg andrewfg commented Aug 29, 2025

Copy link
Copy Markdown
Contributor

Resolves #4994

This PR adds a comprehensive state machine class for modelling the state of lights within Thing handlers by introducing a new LightModel state machine for managing light properties like brightness, color, and color temperature.

Key changes include:

  • Implementation of a complete light state model with flexible capability configuration
  • Support for various light types from simple on/off to full RGB with color temperature
  • Command handling for different openHAB command types (HSB, OnOff, PercentType, etc.)
  • Handles inter- dependencies between on/off and brightness commands and status, and the 'B' part of HSB
  • Handles inter- dependencies between color temperature commands and status, and the 'HS' part of HSB

Signed-off-by: Andrew Fiddian-Green software@whitebear.ch

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@andrewfg
andrewfg requested a review from a team as a code owner August 29, 2025 17:45
@andrewfg
andrewfg marked this pull request as draft August 29, 2025 17:45
@andrewfg

Copy link
Copy Markdown
Contributor Author

Ping @lsiepel ..

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@wborn
wborn requested a review from Copilot August 31, 2025 10:42

This comment was marked as outdated.

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@andrewfg
andrewfg requested a review from Copilot August 31, 2025 14:57

This comment was marked as outdated.

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@andrewfg andrewfg changed the title Additional utility methods for lighting New class for modelling the state of lights in Thing handlers Aug 31, 2025
@andrewfg
andrewfg requested a review from Copilot August 31, 2025 15:20

This comment was marked as outdated.

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@andrewfg andrewfg changed the title New class for modelling the state of lights in Thing handlers New class to model the state of lights in Thing handlers Aug 31, 2025
@andrewfg andrewfg changed the title New class to model the state of lights in Thing handlers Utility class to model the state of lights in Thing handlers Aug 31, 2025
@jimtng

jimtng commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

I don't quite understand the background for this. Why not just add whatever is missing into ColorUtils, or into HSBType, or ColorItem?

- add support for RGBW
- add support for RGB(W) linked to HSB 'B' part
- various refactoring
- documentation
- extended test cases

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@andrewfg

Copy link
Copy Markdown
Contributor Author

PS I think the CI build error is due to something outside of this PR..

@andrewfg
andrewfg requested a review from Nadahar January 25, 2026 23:56
@Nadahar

Nadahar commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

PS I think the CI build error is due to something outside of this PR..

It's only the Java 25 build that fails, I'm pretty sure that it's unrelated.

@andrewfg

Copy link
Copy Markdown
Contributor Author

It's only the Java 25 build that fails, I'm pretty sure that it's unrelated.

Apparently the Java 21 build also fails, .. , but, .. , I'm pretty sure that it's unrelated.

@Nadahar

Nadahar commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Apparently the Java 21 build also fails, .. , but, .. , I'm pretty sure that it's unrelated.

It was only Java 25 when I wrote the comment, but yes, now it's both. I also have a PR that I rebased to an updated main that now fail on both, so yeah, pretty sure it's unrelated to the actual PR.

@andrewfg

andrewfg commented Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

I opened an issue #5314 to report it.

@andrewfg

Copy link
Copy Markdown
Contributor Author

After resynching the branch, the build did succeed.

@Nadahar

Nadahar commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

After resynching the branch, the build did succeed.

Yes, I just found that I think my failures are indeed related to my PR 😞 (at least now - not sure if that was always the case)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 12 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bundles/org.openhab.core/src/main/java/org/openhab/core/util/LightModel.java Outdated
Comment thread bundles/org.openhab.core/src/main/java/org/openhab/core/util/LightModel.java Outdated
Comment thread bundles/org.openhab.core/src/main/java/org/openhab/core/util/LightModel.java Outdated
Comment thread bundles/org.openhab.core/src/main/java/org/openhab/core/util/LightModel.java Outdated
Comment thread bundles/org.openhab.core/src/test/java/org/openhab/core/util/LightModelTest.java Outdated
@lsiepel

lsiepel commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

@andrewfg if you can look at the copilot comments, we can try to move this forward. I think Holger is also looking into this.

@andrewfg

Copy link
Copy Markdown
Contributor Author

^
I will address the Copilot issues tomorrow.

@holgerfriedrich

Copy link
Copy Markdown
Member

Yes, I have looked at this yesterday. It took way too much time - sorry for that - and I must admit that I somehow overlooked this PR (especially once it moved to page 2 of the open PRs).

I like the approach, as it will simplify and hopefully unify the handling in the bindings.
Copilot had some findings I would have likely overlooked. 😮

You can expect a merge soon.

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@holgerfriedrich
holgerfriedrich requested a review from Copilot March 29, 2026 11:32
@andrewfg

Copy link
Copy Markdown
Contributor Author

@holgerfriedrich I have addressed the copilot issues..

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bundles/org.openhab.core/src/test/java/org/openhab/core/util/LightModelTest.java Outdated
Comment thread bundles/org.openhab.core/src/main/java/org/openhab/core/util/LightModel.java Outdated
@holgerfriedrich

Copy link
Copy Markdown
Member

@andrewfg sorry, Copilot is sometimes picky. Please decide if you want to change something and feel free to set to resolved if you think it can stay as it is.

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>

@holgerfriedrich holgerfriedrich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks Andrew

@holgerfriedrich
holgerfriedrich merged commit a51e7f9 into openhab:main Mar 29, 2026
5 checks passed
@holgerfriedrich holgerfriedrich added this to the 5.2 milestone Mar 29, 2026
@holgerfriedrich holgerfriedrich added the enhancement An enhancement or new feature of the Core label Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An enhancement or new feature of the Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide some more core utility classes for lighting

8 participants