Skip to content

Commit

Permalink
Extend sitemap syntax for switch to support press & release buttons
Browse files Browse the repository at this point in the history
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 openhab#3822

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo committed Apr 13, 2024
1 parent cbb458e commit 393d998
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
* @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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
* @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
Expand Down Expand Up @@ -565,6 +566,7 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,14 @@ private void addWidgetMappings(EList<Mapping> mappings, UIComponent component) {
for (Object sourceMapping : (Collection<?>) sourceMappings) {
if (sourceMapping instanceof String) {
String[] splitMapping = sourceMapping.toString().split("=");
String cmd = splitMapping[0].trim();
String[] splitCmd = splitMapping[0].trim().split(":");
String cmd = splitCmd[0].trim();
String releaseCmd = splitCmd.length < 2 ? null : splitCmd[1].trim();
String label = splitMapping[1].trim();
String icon = splitMapping.length < 3 ? null : splitMapping[2].trim();
MappingImpl mapping = (MappingImpl) SitemapFactory.eINSTANCE.createMapping();
mapping.setCmd(cmd);
mapping.setReleaseCmd(releaseCmd);
mapping.setLabel(label);
mapping.setIcon(icon);
mappings.add(mapping);
Expand Down

0 comments on commit 393d998

Please sign in to comment.