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 element Colortemperaturepicker #4420

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import org.openhab.core.model.sitemap.sitemap.Buttongrid;
import org.openhab.core.model.sitemap.sitemap.Chart;
import org.openhab.core.model.sitemap.sitemap.ColorArray;
import org.openhab.core.model.sitemap.sitemap.Colortemperaturepicker;
import org.openhab.core.model.sitemap.sitemap.Condition;
import org.openhab.core.model.sitemap.sitemap.Frame;
import org.openhab.core.model.sitemap.sitemap.IconRule;
Expand Down Expand Up @@ -145,6 +146,7 @@
* @author Laurent Garnier - New widget icon parameter based on conditional rules
* @author Laurent Garnier - Added releaseCmd field for mappings used for switch element
* @author Laurent Garnier - Added support for Buttongrid as container for Button elements
* @author Laurent Garnier - Added support for new sitemap element Colortemperaturepicker
*/
@Component(service = { RESTResource.class, EventSubscriber.class })
@JaxrsResource
Expand Down Expand Up @@ -700,6 +702,10 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null
bean.maxValue = setpointWidget.getMaxValue();
bean.step = setpointWidget.getStep();
}
if (widget instanceof Colortemperaturepicker colortemperaturepickerWidget) {
bean.minValue = colortemperaturepickerWidget.getMinValue();
bean.maxValue = colortemperaturepickerWidget.getMaxValue();
}
if (widget instanceof Buttongrid buttonGridWidget) {
for (ButtonDefinition button : buttonGridWidget.getButtons()) {
MappingDTO mappingBean = new MappingDTO();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Widget:
(LinkableWidget | NonLinkableWidget);

NonLinkableWidget:
Switch | Selection | Slider | Setpoint | Video | Chart | Webview | Colorpicker | Mapview | Input | Button | Default;
Switch | Selection | Slider | Setpoint | Video | Chart | Webview | Colorpicker | Colortemperaturepicker | Mapview | Input | Button | Default;

LinkableWidget:
(Text | Group | Image | Frame | Buttongrid)
Expand Down Expand Up @@ -165,6 +165,17 @@ Colorpicker:
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);

Colortemperaturepicker:
'Colortemperaturepicker' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? &
(('icon=' icon=Icon) |
('icon=[' (IconRules+=IconRule (',' IconRules+=IconRule)*) ']') |
('staticIcon=' staticIcon=Icon))? &
('minValue=' minValue=Number)? & ('maxValue=' maxValue=Number)? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);

Input:
'Input' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? &
(('icon=' icon=Icon) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package org.openhab.core.model.sitemap.validation

import org.openhab.core.model.sitemap.sitemap.Button
import org.openhab.core.model.sitemap.sitemap.Buttongrid
import org.openhab.core.model.sitemap.sitemap.Colortemperaturepicker
import org.openhab.core.model.sitemap.sitemap.Frame
import org.openhab.core.model.sitemap.sitemap.LinkableWidget
import org.openhab.core.model.sitemap.sitemap.Setpoint
Expand Down Expand Up @@ -143,6 +144,14 @@ class SitemapValidator extends AbstractSitemapValidator {
}
}

@Check
def void checkColortemperaturepicker(Colortemperaturepicker ctp) {
if (ctp.minValue !== null && ctp.maxValue !== null && ctp.minValue > ctp.maxValue) {
error("Colortemperaturepicker on item '" + ctp.item + "' has larger minValue than maxValue",
SitemapPackage.Literals.COLORTEMPERATUREPICKER.getEStructuralFeature(SitemapPackage.COLORTEMPERATUREPICKER__MIN_VALUE));
}
}

@Check
def void checkInputHintParameter(Input i) {
if (i.inputHint !== null && !ALLOWED_HINTS.contains(i.inputHint)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.openhab.core.model.sitemap.sitemap.impl.ChartImpl;
import org.openhab.core.model.sitemap.sitemap.impl.ColorArrayImpl;
import org.openhab.core.model.sitemap.sitemap.impl.ColorpickerImpl;
import org.openhab.core.model.sitemap.sitemap.impl.ColortemperaturepickerImpl;
import org.openhab.core.model.sitemap.sitemap.impl.ConditionImpl;
import org.openhab.core.model.sitemap.sitemap.impl.DefaultImpl;
import org.openhab.core.model.sitemap.sitemap.impl.FrameImpl;
Expand Down Expand Up @@ -88,6 +89,7 @@
* @author Laurent Garnier - Added icon field for mappings
* @author Mark Herwege - Make UI provided sitemaps compatible with enhanced syntax in conditions
* @author Mark Herwege - Add support for Button element
* @author Laurent Garnier - Added support for new sitemap element Colortemperaturepicker
*/
@NonNullByDefault
@Component(service = SitemapProvider.class)
Expand Down Expand Up @@ -267,6 +269,15 @@ protected Sitemap buildSitemap(RootUIComponent rootComponent) {
ColorpickerImpl colorpickerWidget = (ColorpickerImpl) SitemapFactory.eINSTANCE.createColorpicker();
widget = colorpickerWidget;
break;
case "Colortemperaturepicker":
ColortemperaturepickerImpl colortemperaturepickerWidget = (ColortemperaturepickerImpl) SitemapFactory.eINSTANCE
.createColortemperaturepicker();
widget = colortemperaturepickerWidget;
setWidgetPropertyFromComponentConfig(widget, component, "minValue",
SitemapPackage.COLORTEMPERATUREPICKER__MIN_VALUE);
setWidgetPropertyFromComponentConfig(widget, component, "maxValue",
SitemapPackage.COLORTEMPERATUREPICKER__MAX_VALUE);
break;
case "Buttongrid":
ButtongridImpl buttongridWidget = (ButtongridImpl) SitemapFactory.eINSTANCE.createButtongrid();
addWidgetButtons(buttongridWidget.getButtons(), component);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
* @author Laurent Garnier - Support added for multiple AND conditions in labelcolor/valuecolor/visibility
* @author Laurent Garnier - new icon parameter based on conditional rules
* @author Danny Baumann - widget label source support
* @author Laurent Garnier - Consider Colortemperaturepicker element as possible default widget
*/
@NonNullByDefault
@Component(immediate = true, configurationPid = "org.openhab.sitemap", //
Expand Down Expand Up @@ -302,6 +303,9 @@ private void applyConfig(@Nullable Map<String, Object> config) {
}
if (!isReadOnly && NumberItem.class.isAssignableFrom(itemType) && hasItemTag(itemName, "Setpoint")) {
return SitemapFactory.eINSTANCE.createSetpoint();
} else if (!isReadOnly && NumberItem.class.isAssignableFrom(itemType)
&& hasItemTag(itemName, "ColorTemperature")) {
return SitemapFactory.eINSTANCE.createColortemperaturepicker();
} else {
return SitemapFactory.eINSTANCE.createText();
}
Expand Down