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

[Sitemap] Add new color keyword "itemValue" #3453

Merged
merged 1 commit into from
Mar 16, 2023

Conversation

lolodomo
Copy link
Contributor

Closes #3429

Signed-off-by: Laurent Garnier lg.hc@free.fr

@lolodomo lolodomo requested a review from a team as a code owner March 13, 2023 11:59
@lolodomo
Copy link
Contributor Author

lolodomo commented Mar 13, 2023

With this item:

Color TestColor "Test color [%s]"

and this sitemap:

{
        Frame label="Using itemValue" {
                Text item=TestColor label="Color RGB [%rgb%]" icon="if:mdi:lightbulb" iconcolor=["itemValue"] labelcolor=["itemValue"] valuecolor=["itemValue"]
                Colorpicker item=TestColor icon="if:mdi:lightbulb" iconcolor=["itemValue"] labelcolor=["itemValue"] valuecolor=["itemValue"]
        }
        Frame label="Using color names" {
                Text item=TestColor icon="if:mdi:lightbulb" iconcolor=["pink"] labelcolor=["orange"] valuecolor=["purple"]
        }
        Frame label="Using color codes" {
                Text item=TestColor icon="if:mdi:lightbulb" iconcolor=["#ff0000"] labelcolor=["#00FF00"] valuecolor=["#0000ff"]
        }
}

here is the result in Basic UI after selecting a color with the picker:
image

REST sitemap API is adjusted:
image

@mherwege
Copy link
Contributor

What item color is being used when the color is with a condition? Would it pick the color of the item being shown, or the color of the item on which the condition applies?

@lolodomo
Copy link
Contributor Author

the color of the item being shown

lolodomo added a commit to lolodomo/openhab-webui that referenced this pull request Mar 13, 2023
Depends on openhab/openhab-core#3453

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
lolodomo added a commit to lolodomo/openhab-webui that referenced this pull request Mar 13, 2023
Depends on openhab/openhab-core#3453

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@lolodomo lolodomo force-pushed the sitemap_itemValue branch from 832f56b to d3e4b89 Compare March 13, 2023 18:28
mueller-ma added a commit to mueller-ma/openhab-docs that referenced this pull request Mar 13, 2023
openhab/openhab-core#3453
Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>
Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

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

Thanks, otherwise LGTM.

Comment on lines 619 to 620
if (item instanceof ColorItem && item.getState() instanceof HSBType) {
HSBType hsbState = (HSBType) item.getState();
itemRGBHexCode = "#" + Integer.toHexString(hsbState.getRGB()).substring(2);
}
Copy link
Member

@J-N-K J-N-K Mar 13, 2023

Choose a reason for hiding this comment

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

Suggested change
if (item instanceof ColorItem && item.getState() instanceof HSBType) {
HSBType hsbState = (HSBType) item.getState();
itemRGBHexCode = "#" + Integer.toHexString(hsbState.getRGB()).substring(2);
}
if (item.getState() instanceof HSBType hsbState) {
itemRGBHexCode = "#" + Integer.toHexString(hsbState.getRGB()).substring(2);
}

If the state is of HSBType it must be a ColorItem. You can further reduce code by using pattern matching.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your proposal will lead to a NPE when item is null.
But I could have a State as parameter rather than an Item if we consider that a test on HSBType is sufficient.

Copy link
Member

@J-N-K J-N-K Mar 13, 2023

Choose a reason for hiding this comment

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

item != null would then be sufficient. But does it make sense to call the method at all if the item is null? If you need to add a check for each call, then I would prefer to add item != null here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed. I am now passing as argument the item state.

Closes openhab#3429

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@lolodomo lolodomo force-pushed the sitemap_itemValue branch from d3e4b89 to 15760ac Compare March 14, 2023 08:47
lolodomo added a commit to lolodomo/openhab-webui that referenced this pull request Mar 14, 2023
Depends on openhab/openhab-core#3453

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@lolodomo
Copy link
Contributor Author

@J-N-K : gentle ping

Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

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

LGTM,thanks,

@J-N-K J-N-K merged commit 52e36a0 into openhab:main Mar 16, 2023
@J-N-K J-N-K added enhancement An enhancement or new feature of the Core sitemap labels Mar 16, 2023
@J-N-K J-N-K added this to the 4.0 milestone Mar 16, 2023
@lolodomo lolodomo deleted the sitemap_itemValue branch March 16, 2023 19:59
kaikreuzer pushed a commit to openhab/openhab-webui that referenced this pull request Mar 17, 2023
Depends on openhab/openhab-core#3453

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
stefan-hoehn pushed a commit to openhab/openhab-docs that referenced this pull request Mar 18, 2023
* [Sitemap] Add color 'itemValue'

openhab/openhab-core#3453
Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>

* update

Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>

---------

Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>
@jlaur
Copy link
Contributor

jlaur commented Mar 20, 2023

@lolodomo - should this be mentioned in the documentation?

@lolodomo
Copy link
Contributor Author

@lolodomo - should this be mentioned in the documentation?

Doc has been updated.
openhab/openhab-docs#2032

splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 12, 2023
Closes openhab#3429

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
GitOrigin-RevId: 52e36a0
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 sitemap
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Sitemap] Add new color keyword "itemValue"
4 participants