-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
Extend sitemap syntax for switch to support press & release buttons #4183
Conversation
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>
LGTM |
Hopefully not. Simply use string in double quotes as commands like for example "val:On":"val:Off"="my button". |
Here is where is defined the syntax of a command. It can be a number (0 for example), an id (ON for example).or a string ("val:On" for example). Even if I am sure, I will test it. |
Tested and working. |
But my new code for the sitemap generator simply splitting on ":" is probably not sufficient. I will enhance it. |
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Related to openhab/openhab-core#3822 Depends on openhab/openhab-core#4183 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Related to openhab/openhab-core#3822 Depends on openhab/openhab-core#4183 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@@ -99,6 +99,11 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan | |||
|
|||
private static final Pattern CONDITION_PATTERN = Pattern | |||
.compile("(?<item>[A-Za-z]\\w*)?\\s*(?<condition>==|!=|<=|>=|<|>)?\\s*(?<sign>\\+|-)?(?<state>.+)"); | |||
private static final Pattern COMMANDS_PATTERN1 = Pattern.compile("^\"(?<cmd1>[^\"]*)\":\"(?<cmd2>[^\"]*)\"$"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this single regex will do:
"^(?<cmd1>\"[^\"]*\"|[^\": ]*):(?<cmd2>.*)$"
You just need to strip the opening and closing double quotes from cmd1
and cmd2
after the match if any exist.
Mappings are also used in the Selection widget. As there is no differentiation in the parser, it will also create this extra field for the Selection widget. Should that be restricted (and different types of mappings created for each?). Or should it just be ignored for a Selection widget. |
My idea was to ignore the optional release command in the case of Selection widget. |
I am fighting a bit to make things work in the UI sitemap generator. The issue is that these mappings (and similarly the rules) are sent as one field to OH core. These do not contain quotes, so the splitting has always been a bit of an art. |
@mherwege : until a kind of refactoring is started in the sitemap generator to handle properly quotes, how can we proceed here to not being blocked ? As I understand, with the current implementation, I have to consider that the string will not contain quotes but then it is not possible to make a difference between a ":" being the separator between two commands and ":" being a part of a command. |
@lolodomo I would keep the syntax. I have the refactoring on the generator almost done, but need some more testing to verify it does not break anything. I am short on time at the moment so things may be a bit slow on my side. Utimately, I actually think it is a stupid thing to pass these configurations as such through the REST API, and not the fields it gets split into. That would avoid a lot of string manipulation in the generator UI as well as in this code. I may look into that in the future, but don't have time for that now, so we should leave that out. |
Ok, in that case, I am going to consider your REGEX simplification proposal. |
@lolodomo I implemented a solution in the UI, but in doing that (and allowing quotes to be saved), I also needed to modify |
@mherwege : would you like that I remove my changes in |
I can include it in #4204, but it can then only be merged after your PR. I am fine with that. |
Included in #4204, but not tested, as it will now depend on this PR. |
Changes will be done in a separate PR. Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@mherwege : change removed @openhab/core-maintainers : please review & merge this ultra small PR (5 lines). |
@J-N-K Could I ask you to take a look at this? I like the functionality, but might miss further implications of this PR.... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thanks
Related to openhab/openhab-core#3822 Depends on openhab/openhab-core#4183 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Related to openhab/openhab-core#4183 and openhab/openhab-core#3822 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Related to openhab/openhab-core#4183. Depends on openhab/openhab-core#4204. This PR implements press/release button support. Refactor code to allow proper quoting of arguments in mappings and conditions. Quotes are now preserved, and therefore they need to be removed in core at usage (openhab/openhab-core#4204). --------- Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Related to openhab/openhab-core#4183 and openhab/openhab-core#3822 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
) Related to openhab/openhab-core#4183 and openhab/openhab-core#3822 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Apply logo for free@home binding Apply logo for free@home binding Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com> * [sitemap] New Slider parameter releaseOnly (#2287) * [saicismart][renault] Add addon SVG logo for Renault and SAIG MG Cars (#2290) * [saicismart] Add addon logo for MG Cars from https://de.wikipedia.org/wiki/Datei:Mg_logo.svg Signed-off-by: dougculnane <doug@culnane.net> * [saicismart] Use SVG not PNG for addon logo Signed-off-by: dougculnane <doug@culnane.net> * [renault] Use SVG not PNG for addon logo Signed-off-by: dougculnane <doug@culnane.net> --------- Signed-off-by: dougculnane <doug@culnane.net> * Update persistence actions docs (#2289) * update persistence actions docs Signed-off-by: Mark Herwege <mark.herwege@telenet.be> * correction Signed-off-by: Mark Herwege <mark.herwege@telenet.be> * document HistoricItem Signed-off-by: Mark Herwege <mark.herwege@telenet.be> * review adjustment Signed-off-by: Mark Herwege <mark.herwege@telenet.be> --------- Signed-off-by: Mark Herwege <mark.herwege@telenet.be> * Update link to update-description-1.0.0.xsd (#2275) The link for the update-description-1.0.0.xsd is wrong. Signed-off-by: M Valla <12682715+mvalla@users.noreply.github.com> * Replace logo of free@home binding with SVG version Replace logo of free@home binding with SVG version Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com> * [sitemap] Precision for Default element leading to Slider element (#2294) Signed-off-by: Laurent Garnier <lg.hc@free.fr> * [sitemap] Press & release feature for buttons in a switch element (#2293) Related to openhab/openhab-core#4183 and openhab/openhab-core#3822 Signed-off-by: Laurent Garnier <lg.hc@free.fr> * [airgradient] Add logo for recently added binding (#2296) * [airgradient] Add logo for recently added binding * Add airgradient logo in SVG format Signed-off-by: Jørgen Austvik <jaustvik@acm.org> --------- Signed-off-by: Jørgen Austvik <jaustvik@acm.org> * [multimedia] Add record and transcribe commands (#2295) * [multimedia] Add record and transcribe commands Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com> * apply pr review Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com> * fix md errors Signed-off-by: Stefan Höhn <mail@stefanhoehn.com> --------- Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com> Signed-off-by: Stefan Höhn <mail@stefanhoehn.com> Co-authored-by: stefan-hoehn <mail@stefanhoehn.com> * Apply logo for free@home binding Apply logo for free@home binding Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com> * Replace logo of free@home binding with SVG version Replace logo of free@home binding with SVG version Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com> --------- Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com> Signed-off-by: dougculnane <doug@culnane.net> Signed-off-by: Mark Herwege <mark.herwege@telenet.be> Signed-off-by: M Valla <12682715+mvalla@users.noreply.github.com> Signed-off-by: Laurent Garnier <lg.hc@free.fr> Signed-off-by: Jørgen Austvik <jaustvik@acm.org> Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com> Signed-off-by: Stefan Höhn <mail@stefanhoehn.com> Co-authored-by: stefan-hoehn <mail@stefanhoehn.com> Co-authored-by: mueller-ma <mueller-ma@users.noreply.github.com> Co-authored-by: Doug Culnane <32482395+dougculnane@users.noreply.github.com> Co-authored-by: Mark Herwege <mherwege@users.noreply.github.com> Co-authored-by: M Valla <12682715+mvalla@users.noreply.github.com> Co-authored-by: lolodomo <lg.hc@free.fr> Co-authored-by: Jørgen Austvik <jaustvik@acm.org> Co-authored-by: GiviMAD <GiviMAD@users.noreply.github.com>
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