Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

BasicUI: Treat Switch on NumberItem not as ON/OFF Switch #3493

Merged
merged 4 commits into from
May 22, 2017

Conversation

triller-telekom
Copy link
Contributor

Fixes #3472
Signed-off-by: Stefan Triller stefan.triller@telekom.de

Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
@lolodomo
Copy link
Contributor

I think it is not the appropriate fix.
For a.normal switch in the sitemap, the conversion is not a bad idea.
What we have to avoid is I think any conversion when the switch has mappings, whatever the kind of item.

@lolodomo
Copy link
Contributor

A switch with mappings is not really a switch but more like a selection.

@triller-telekom
Copy link
Contributor Author

If I create a Switch in the items file and in the Sitemap a Switch with mappings for that item.

items:

Switch Ventilation_Fan_Level "Fan [%d]" {comfoair="fan_level"}

sitemap:

Switch item=Ventilation_Fan_Level label="Fan" mappings=[1="A", 2="1", 3="2", 4="3"]

and then I want to update this item with a value in the mapping I get:

smarthome update Ventilation_Fan_Level 3
Error: State '3' is not valid for item 'Ventilation_Fan_Level'
Valid data types are: ( OnOffType UnDefType )

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 Switch like this:

Switch item=Ventilation_Fan_Level label="Fan" mappings=[ON="An", OFF="Aus"]

then it works as expected.

Where exactly do you think it doesn't work?

@lolodomo
Copy link
Contributor

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.
When you have a switch with mappings, you should not convert the item state to OnOffType and so you retrieve as key for your mappings, a number or why not OPEN/CLOSE for a contact item.

Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
@triller-telekom
Copy link
Contributor Author

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.

@lolodomo
Copy link
Contributor

LGTM

Before merging, someone should check if there is a valid reason for failing travis checks.

@sjsf
Copy link
Contributor

sjsf commented May 19, 2017

Don't know how valid the reason is, but definitely can't stay like that:

testStateConversionForSwitchWidgetThroughGetState(org.eclipse.smarthome.ui.internal.items.ItemUIRegistryImplTest)  Time elapsed: 0.021 sec  <<< ERROR!
java.lang.NullPointerException: null
	at org.eclipse.smarthome.ui.internal.items.ItemUIRegistryImpl.convertState(ItemUIRegistryImpl.java:509)
	at org.eclipse.smarthome.ui.internal.items.ItemUIRegistryImpl.getState(ItemUIRegistryImpl.java:485)
	at org.eclipse.smarthome.ui.internal.items.ItemUIRegistryImplTest.testStateConversionForSwitchWidgetThroughGetState(ItemUIRegistryImplTest.java:332)

Copy link
Contributor

@sjsf sjsf left a 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>
@triller-telekom
Copy link
Contributor Author

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.

Copy link
Contributor

@sjsf sjsf left a 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
Copy link
Contributor

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>
@sjsf
Copy link
Contributor

sjsf commented May 22, 2017

Thank you!

@sjsf sjsf merged commit 1b2ab9f into eclipse-archived:master May 22, 2017
@triller-telekom triller-telekom deleted the fix3472numberSwitch branch May 22, 2017 15:03
cdjackson added a commit to cdjackson/smarthome that referenced this pull request Jun 3, 2017
* 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
@kaikreuzer kaikreuzer modified the milestone: 0.9.0 Jun 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants