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

BasicUI: display rollerblind state if required, fixes #976 #990

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
<span class="mdl-form__label">
%label%
</span>
<div class="mdl-form__control mdl-form__rollerblind" data-control-type="rollerblind" data-item="%item%">
<span class="mdl-form__value mdl-form__value--rollerblind">
%value%
</span>
<div class="mdl-form__control mdl-form__rollerblind" data-control-type="rollerblind" data-item="%item%" data-has-value="%has_value%">
<button class="mdl-button mdl-button--raised mdl-js-button mdl-js-ripple-effect mdl-form__rollerblind--up">
<!-- keyboard_arrow_up -->
<i class="material-icons">&#xe987;</i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderExcep

String snippet = getSnippet(snippetName);
State state = itemUIRegistry.getState(w);
String value = getValue(w);

snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(w));
snippet = StringUtils.replace(snippet, "%category%", getCategory(w));
snippet = StringUtils.replace(snippet, "%icon_type%", config.getIconType());
snippet = StringUtils.replace(snippet, "%state%", getState(w));
snippet = StringUtils.replace(snippet, "%value%", value);
snippet = StringUtils.replace(snippet, "%has_value%", new Boolean(value != "").toString());
snippet = StringUtils.replace(snippet, "%item%", w.getItem());
snippet = StringUtils.replace(snippet, "%label%", getLabel(w));
snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME);
Expand Down
14 changes: 14 additions & 0 deletions extensions/ui/org.eclipse.smarthome.ui.basic/web-src/smarthome.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,20 @@
_t.buttonDown = _t.parentNode.querySelector(o.rollerblind.down);
_t.buttonStop = _t.parentNode.querySelector(o.rollerblind.stop);

_t.hasValue = _t.parentNode.getAttribute("data-has-value") === "true";
_t.valueNode = _t.parentNode.parentNode.querySelector(o.formValue);
_t.setValuePrivate = function(value) {
if (!_t.hasValue) {
return;
}
if (value === "DOWN") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this already be handled by the RollershutterItem in the setState function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, for some reason there are SSE events which contain DOWN and UP as a new state. This happens if I press up or down button twice.

Copy link
Contributor

Choose a reason for hiding this comment

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

which contain DOWN and UP as a new state
@kaikreuzer I would assume this is a bug in the core framework then. Correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, the RollershutterItem defines UP/DOWN as accepted values for its state: https://github.com/eclipse/smarthome/blob/master/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/RollershutterItem.java#L42
This has been like this since the very beginning.
We can discuss whether this should be considered to be a bug and we should only allow UNDEF or a PercentType instead - it would make things indeed easier for consumers such as the Basic UI. The problem is that such a change would break the auto update feature, because this is the one which currently sends the UP update when an UP command is sent for the item.

Copy link
Contributor

Choose a reason for hiding this comment

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

My intention was not to remove the accepted state type.

The problem is that such a change would break the auto update feature, because this is the one which currently sends the UP update when an UP command is sent for the item.

I missed the auto update feature. Could you point me to the implementation?
Such a feature is used for demonstration only, or is there any other use case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I would assume this one: org.eclipse.smarthome.core.autoupdate

Copy link
Contributor

Choose a reason for hiding this comment

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

or is there any other use case?

Yes, it is always active and pro-actively assumes a state change when a command is seen on the event bus.
Bindings should be able to deactivate this (this was possible in OH1, but is an open issue for ESH, see #595)

value = "100";
} else if (value === "UP") {
value = "0";
}
_t.valueNode.innerHTML = value;
};

function emitEvent(value) {
_t.parentNode.dispatchEvent(createEvent(
"control-change", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@
&--setpoint {
padding: 0 10px 0 5px;
}
&--rollerblind {
padding: 0 10px 0 5px;
}
}
&--no-label {
.mdl-form__title {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.