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

Sitemap Events provide item states in a format that matches map entries #3332

Merged
merged 6 commits into from
May 3, 2017

Conversation

triller-telekom
Copy link
Contributor

BasicUI converted an item state to a switch On/Off type, but ClassicUI did not.
ItemUiRegistry now takes care of such a state conversions for Widgets of type Switch and Slider.

Fixes #866

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

…ntries

Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
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.

Some inline commens.

And: please also put a regression test for this behavior into ItemUIRegistryImplTest

@@ -32,6 +32,7 @@ Import-Package: javax.imageio,
org.eclipse.smarthome.model.core,
org.eclipse.smarthome.model.items,
org.eclipse.smarthome.model.sitemap,
org.eclipse.smarthome.model.sitemap.impl,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, somehow slipped from testing into my commit...

@@ -72,6 +76,7 @@
*
* @author Kai Kreuzer - Initial contribution and API
* @author Chris Jackson
* @author Stefan Triller - convertState(Widget, State)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please state here what you did

private State convertState(Widget w, State s) {
State returnState = null;

if (w instanceof SwitchImpl) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check for the interfaces here, not the implementations.

if (s instanceof PercentType) { // catches also HSBType etc
returnState = ((PercentType) s).as(PercentType.class);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these the only widget types that potentially need conversion? How about e.g. the Colorpicker?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, Colorpicker is expecting a HSBType, so that might be a good idea to try a conversion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For colopicker, a OFF or 0 could be converted to (0,0,0) but how will be converted a ON or a value > 0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Colorpicker only makes sense for a Color item and this does have a HSBType state anyway. Why would anyone want to attach a ColorPicker to a Switch or Dimmer item for example? What would be the use case? I don't see any, which is why I added no conversion for the ColorPicker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right.
The real usage is more the reverse, that is using a switch or a dimmer for a color item for example and it is what ypu have covered.

State returnState = null;

if (w instanceof SwitchImpl) {
if (s instanceof PercentType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to check for a specific type here - just use s instanceof Convertible so we keep the knowledge of what can be converted to what in a single place.

@triller-telekom triller-telekom changed the title Sitemap Events provide item states in a format that matches map entries WIP: Sitemap Events provide item states in a format that matches map entries Apr 28, 2017
Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
if (w instanceof SwitchImpl) {
if (s instanceof PercentType) {
if (w instanceof Switch) {
if (s instanceof Convertible) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just: returnState = s.getStateAs(OnOffType.class);
This call is doing the test with Covertible.

@lolodomo
Copy link
Contributor

I have not tested this PR but it makes really sense and will help all UIs.

@@ -476,6 +480,34 @@ public State getState(Widget w) {
}

/**
* Converts an item state to the type the widget supports (if possible)
*
* @param w - Widget in sitemap that shows the state
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the "-" between the parameter name and the comment?

Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
@triller-telekom triller-telekom changed the title WIP: Sitemap Events provide item states in a format that matches map entries Sitemap Events provide item states in a format that matches map entries May 2, 2017
Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
@lolodomo
Copy link
Contributor

lolodomo commented May 2, 2017

LGTM

@sjsf sjsf merged commit 8ba0e7c into eclipse-archived:master May 3, 2017
@sjsf
Copy link
Contributor

sjsf commented May 3, 2017

To mee to. Thanks!

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.

5 participants