-
Notifications
You must be signed in to change notification settings - Fork 779
BasicUI: Treat Switch on NumberItem not as ON/OFF Switch #3493
BasicUI: Treat Switch on NumberItem not as ON/OFF Switch #3493
Conversation
Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
I think it is not the appropriate fix. |
A switch with mappings is not really a switch but more like a selection. |
If I create a Switch in the items file and in the Sitemap a Switch with mappings for that item. items:
sitemap:
and then I want to update this item with a value in the mapping I get:
Which is correct because the item is a Switch that does not understand the values in the sitemap mappings, i.e. they are wrong. If I change the sitemap to react on the correct values of the item, which is
then it works as expected. Where exactly do you think it doesn't work? |
Your example is of course wrong becase you cannot use a number value as state for a switch item. The switch element in sitemap is in fact very similar to the selection element; the difference is mainly how it is rendered by UI. The user can switch between "switch" and "selection" easily. The switch element with mappings in the sitemap can be attached more or less to any kind of items, a switch item, a number item, a contact item, ... etc. |
Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
Thank you for the long explanation, I agree that checking for mappings is the right way to go because the conversion should only be for plain on/off type switches and for all others just return whatever state they have. |
LGTM Before merging, someone should check if there is a valid reason for failing travis checks. |
Don't know how valid the reason is, but definitely can't stay like that:
|
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.
.
Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
The test is using a mock for SwitchImpl and thus could not call getMappings(). So it was a bug in the test. Lets wait for travis and then it can be merged. |
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.
This time you even had to touch a test, but still did not think of implementing a regression test for your assumption "only convert plain switches with no mappings".
With all the regressions that you are facing right know after attempting to bug in the UI layer you should know best how valuable it would have been if there were any such tests. I really don't get it... 😢
@@ -499,7 +499,10 @@ private State convertState(Widget w, Item i) { | |||
if (w instanceof Slider || (w instanceof Switch && i instanceof RollershutterItem)) { | |||
returnState = i.getStateAs(PercentType.class); | |||
} else if (w instanceof Switch) { | |||
returnState = i.getStateAs(OnOffType.class); | |||
Switch sw = (Switch) w; | |||
if (sw.getMappings().size() == 0) { // only convert plain switches with no mappings |
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.
Such a comment is completely useless: It is dead and only states the obvious!
Next time you feel the urge to write such a comment: Pleeeeease write a regression test case instead!!!
Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
Thank you! |
* master: (335 commits) Voice: send feedback to an item when listening for a command (eclipse-archived#3451) Scheduler: fix ConcurrentModificationException (eclipse-archived#3511) [Scheduler] Dropped usage of SimpleDateFormat for trace logging (eclipse-archived#3508) Use % sign as default for dimmer items (eclipse-archived#3525) updated ThingHandler javadoc added regression tests ensure thingUdpated cannot be called in parallel with initialize moving handler intiialization back to the caller thread use decicated locks instead of syncrhonization by object add PaperUI setup to IDE setup tasks, adopt documentation (eclipse-archived#3515) Bug fix: things not showing on control page (eclipse-archived#3517) remove "Type" postfix in item events, fixes 3282. (eclipse-archived#3494) use toFullString when creating GroupItemStateChangeEvent (eclipse-archived#3409) Made item’s state text consistent + refactored code (eclipse-archived#3466) Refactored CoreItemFactory: (eclipse-archived#3507) Add CoreItemFactoryTest, in addition to eclipse-archived#3507 (eclipse-archived#3509) fix ConcurrentModificationException in AbstractWatchServiceTest (eclipse-archived#3499) BasicUI: Treat Switch on NumberItem not as ON/OFF Switch (eclipse-archived#3493) An Interface method should not allow for throwing a generic Exception (eclipse-archived#3467) Fix eclipse-archived#2902 for Basic UI (eclipse-archived#3496) ... # Conflicts: # bundles/io/org.eclipse.smarthome.io.transport.dbus/.classpath # bundles/io/org.eclipse.smarthome.io.transport.dbus/META-INF/MANIFEST.MF # extensions/binding/pom.xml
Fixes #3472
Signed-off-by: Stefan Triller stefan.triller@telekom.de