Extend sitemap syntax for switch to support press & release buttons (#4183)

* Extend sitemap syntax for switch to support press & release buttons

Mappings attribute for switch element now accepts one or two commands for each button.
If only one command is provided, the button is a click button, the command is sent to the item when the button is clicked.
If two commands are provided (separated by ":"), the button is a press & release button, the first command is sent to the item when the button is pressed and the second when the button is released.

Syntax example for a click button: Switch item=DemoSwitch mappings=[ ON="ON" ]
Syntax example for a press & release button: Switch item=DemoSwitch mappings=[ ON:OFF="ON" ]

Related to #3822

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2024-05-05 09:45:24 +02:00 committed by GitHub
parent 6aed435c77
commit b40e6db514
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 1 deletions

View File

@ -18,12 +18,14 @@ package org.openhab.core.io.rest.sitemap.internal;
* @author Kai Kreuzer - Initial contribution
* @author Laurent Garnier - New fields position and icon
* @author Laurent Garnier - Replace field position by fields row and column
* @author Laurent Garnier - New field releaseCommand
*/
public class MappingDTO {
public Integer row;
public Integer column;
public String command;
public String releaseCommand;
public String label;
public String icon;

View File

@ -141,6 +141,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
* @author Laurent Garnier - Added icon field for mappings used for switch element
* @author Laurent Garnier - Support added for multiple AND conditions in labelcolor/valuecolor/visibility
* @author Laurent Garnier - New widget icon parameter based on conditional rules
* @author Laurent Garnier - Added releaseCmd field for mappings used for switch element
*/
@Component(service = { RESTResource.class, EventSubscriber.class })
@JaxrsResource
@ -635,6 +636,7 @@ public class SitemapResource
for (Mapping mapping : switchWidget.getMappings()) {
MappingDTO mappingBean = new MappingDTO();
mappingBean.command = mapping.getCmd();
mappingBean.releaseCommand = mapping.getReleaseCmd();
mappingBean.label = mapping.getLabel();
mappingBean.icon = mapping.getIcon();
bean.mappings.add(mappingBean);

View File

@ -204,7 +204,7 @@ Button:
row=INT ':' column=INT ':' cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?;
Mapping:
cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?;
cmd=Command (':' releaseCmd=Command)? '=' label=(ID | STRING) ('=' icon=Icon)?;
VisibilityRule:
conditions+=Condition ('AND' conditions+=Condition)*;