openhab / org.openhab.ui.habpanel

OUTDATED repo - HABPanel has moved to the openhab-webui repo!
https://github.com/openhab/openhab-webui
Eclipse Public License 1.0
97 stars 93 forks source link

[enhancement] Selection Widget, additional source for comma-separated list of choices #285

Open mhilbush opened 6 years ago

mhilbush commented 6 years ago

The Selection Widget currently has two sources for the choices:

I'd like to propose another alternative for supplying the comma-separated list of choices.

Let's say I have two Items:

String FavoritePlay
String FavoriteChoices

The FavoritePlay Item is linked to a channel on the music player Thing that's used to tell the music player to play a Favorite from it's internal list of Favorites. FavoritePlay would populate the openHAB Item in the Selection Widget settings.

The FavoriteChoices Item is linked to another channel on the music player Thing that populates a comma-separated list of Favorites from the music player's internal list of Favorites, like this:

35caffa2.1=Rock,35caffa2.2=Folk,35caffa2.3=Classic Alternative

It would nice if I could specify FavoriteChoices as a source for the comma-separated list of choices. Then, once a selection is made from the list of choices, the value (e.g. 35caffa2.1) can be used to play that Favorite on the music server using the FavoritePlay Item.

So, basically, instead of specifying the comma-separated list as you do here, I'd like to provide an Item from which the comma-separated list can be sourced. capture

Edit: I should add that this would make it much easier to maintain the list of choices in HABpanel as Favorites are added/changed/removed on the music player (i.e. there would be no maintenance required at all)

ghys commented 6 years ago

Sounds reasonable! Do you expect the list of choices to change while the widget is running? For simplicity reasons it might be better to load them only when it's initializing and don't tie them to the item afterwards - could otherwise lead to issues i.e. when the current state isn't an available choice anymore and becomes invalid.

mhilbush commented 6 years ago

Do you expect the list of choices to change while the widget is running?

Ideally, yes. Updating the choices on the fly would reflect updates (add/change/delete) made to the Favorites on the music player. Let's say the music player Thing has a channel for the favorites choices, and that channel is linked to the FavoriteChoices item. Also, the music player Thing updates the favorites choices periodically (like every minute or so). When the channel receives an update, the choices in the Selection Widget would reflect the most current state of the favorites on the player. Given such an update frequency, it would be very unlikely that the choices in HABpanel would be out of sync with the music player.

Edit: Reference my post on the forum here

mhilbush commented 6 years ago

A couple other questions on this, :-)

In the comma-separated list of choices, is there a reason you also don't allow the RHS to be wrapped in single and/or double quotes? For example:

1="Multiword Choice",2="Choice, With an Embedded Comma",3="Choice3"

Without the quoting, is there a way to escape a comma embedded in the choice?

mhilbush commented 6 years ago

@ghys In the above reference, we're discussing how to dynamically update the state options at runtime to hold the favorites list. This approach likely will work for SqeezeeBox and Sonos. As it uses HABpanel's existing Selection widget functionality (server-provided item options), the above functionality may not be needed.

However, my one question at this point is whether HABpanel detects that the item's state options have changed at runtime, and automatically updates those options in the Selection widget.

ghys commented 6 years ago

Looks good @mhilbush! Feel free to update this issue as the discussions on the ESH side evolve.

However, my one question at this point is whether HABpanel detects that the item's state options have changed at runtime, and automatically updates those options in the Selection widget.

No it doesn't, because of this check it will only retrieve and populate the choices the first time: https://github.com/openhab/org.openhab.ui.habpanel/blob/2f4164adc62b019a80536deab96aa523314ee57e/web/app/widgets/selection/selection.widget.js#L52 We can safely remove that check and update the list of options every time the modal window is displayed.

In the comma-separated list of choices, is there a reason you also don't allow the RHS to be wrapped in single and/or double quotes? For example: Without the quoting, is there a way to escape a comma embedded in the choice?

No reason, I didn't expect choices to include a comma honestly :) The implementation is pretty simplistic: https://github.com/openhab/org.openhab.ui.habpanel/blob/2f4164adc62b019a80536deab96aa523314ee57e/web/app/widgets/selection/selection.widget.js#L60