Add inputHint parameter to sitemap Input element (#3418)

* Add inputHint param to sitemap Input element

Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
pull/3488/head
Mark Herwege 2023-03-26 11:15:56 +02:00 committed by GitHub
parent 4cbc0e613e
commit 850a9239de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 5 deletions

View File

@ -54,7 +54,7 @@ Image:
Video:
'Video' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? &
('url=' url=(STRING)) & ('encoding=' encoding=(STRING))? &
('url=' url=STRING) & ('encoding=' encoding=STRING)? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
@ -62,7 +62,7 @@ Video:
Chart:
'Chart' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? &
('service=' service=(STRING))? & ('refresh=' refresh=INT)? & ('period=' period=ID) &
('service=' service=STRING)? & ('refresh=' refresh=INT)? & ('period=' period=ID) &
('legend=' legend=BOOLEAN_OBJECT)? & ('forceasitem=' forceAsItem=BOOLEAN_OBJECT)? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
@ -72,7 +72,7 @@ Chart:
Webview:
'Webview' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? &
('height=' height=INT)? & ('url=' url=(STRING)) &
('height=' height=INT)? & ('url=' url=STRING) &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
@ -129,6 +129,7 @@ Colorpicker:
Input:
'Input' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? &
('inputHint=' inputHint=STRING)? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
@ -146,7 +147,7 @@ Mapping:
cmd=Command '=' label=(ID | STRING);
VisibilityRule:
(item=ID) (condition=("==" | ">" | "<" | ">=" | "<=" | "!=")) (sign=('-' | '+'))? (state=XState);
(item=ID) (condition=('==' | '>' | '<' | '>=' | '<=' | '!=')) (sign=('-' | '+'))? (state=XState);
ItemRef:
ID;
@ -158,7 +159,7 @@ Icon returns ecore::EString:
STRING | ID;
ColorArray:
((item=ID)? (condition=("==" | ">" | "<" | ">=" | "<=" | "!="))? (sign=('-' | '+'))? (state=XState) '=')?
((item=ID)? (condition=('==' | '>' | '<' | '>=' | '<=' | '!='))? (sign=('-' | '+'))? (state=XState) '=')?
(arg=STRING);
Command returns ecore::EString:
@ -170,6 +171,7 @@ Number returns ecore::EBigDecimal:
XState returns ecore::EString:
INT | ID | STRING | FLOAT;
@Override
terminal ID:
('^'? ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')*) |
(('0'..'9')+ ('a'..'z' | 'A'..'Z' | '_') ('0'..'9' | 'a'..'z' | 'A'..'Z' | '_')*);

View File

@ -23,6 +23,9 @@ import org.openhab.core.model.sitemap.sitemap.SitemapPackage
import org.openhab.core.model.sitemap.sitemap.Widget
import org.eclipse.xtext.validation.Check
import java.math.BigDecimal
import org.openhab.core.model.sitemap.sitemap.Input
import org.eclipse.xtext.nodemodel.INode
import org.eclipse.xtext.nodemodel.util.NodeModelUtils
//import org.eclipse.xtext.validation.Check
/**
@ -32,6 +35,8 @@ import java.math.BigDecimal
*/
class SitemapValidator extends AbstractSitemapValidator {
val ALLOWED_HINTS = #["text", "number", "date", "time", "datetime"]
@Check
def void checkFramesInFrame(Frame frame) {
for (Widget w : frame.children) {
@ -102,4 +107,14 @@ class SitemapValidator extends AbstractSitemapValidator {
SitemapPackage.Literals.SETPOINT.getEStructuralFeature(SitemapPackage.SETPOINT__MIN_VALUE));
}
}
@Check
def void checkInputHintParameter(Input i) {
if (i.inputHint !== null && !ALLOWED_HINTS.contains(i.inputHint)) {
val node = NodeModelUtils.getNode(i)
val line = node.getStartLine()
error("Input on item '" + i.item + "' has invalid inputHint '" + i.inputHint + "' at line " + line,
SitemapPackage.Literals.INPUT.getEStructuralFeature(SitemapPackage.INPUT__INPUT_HINT))
}
}
}