-
-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slider and Setpoint with Number:Temperature broken after upgrading to OpenHAB 3.4.0 #1605
Comments
There was no change about that directly in Basic UI in OH 3.4 I am aware. Maybe this is related to the stuff with UoM done in the core framework. @J-N-K : do you thing |
I don't see anything in the code that could have changed, and actually I don't see how |
@goligo : can you show what you got inside events.log (filtering on your item) before opening BasicUI and when moving the slider with BasicUI. The only explanation I can find is that for an unknown reason, your item state contains '%unit%" when opening the page in BasicUI. |
Ok so we have to understand how "%unit%" appeared in the item state. If you say it should never happen, there is nothing to change in BasicUI. |
%unit% does not appear in the label, it is not shown on the UI, the value is formatted as expected as "19 °C". Only when moving the slider the payload sent back to the server does contain %unit% instead of the actual unit. I don't know whether it already was sent like this before, but the server could handle it, or whether it was sent as °C before. |
What is certain is that it is not BasicUI that adds "%unit%" by itself. BasicUI just extracts the unit and saves it to uses it letter when sending a command. |
This item is handled by what binding ? |
Item is linked to targetTemp channel of the Shelly binding. I don't do any custom unit handling. |
I can confirm the issue is not specific to the slider widget, but happens with any widget trying to modify the value. Unit %unit% is taken from data-unit="%unit%" attribute in the rendered HTML of the widget. |
Seems to be the same issue as or related to #765 |
In fact it is the |
As far I understand the issue, @J-N-K recently made a change, to return null for getUnit, when the state description contains the default unit placeholder The Slider and Setpoint renderers contain code to not replace the unit placeholder, if the unit symbol is null Lines 72 to 74 in eab99f0
So %unit% stays in the data-unit attribute and is later concatenated to the value, before it is sent back to the server. Ah, the response from J-N-K came in while I was writing mine. So how it should be fixed? Which unit should be used by the basic UI and where does it get it? |
@J-N-K So if %unit% means "the unit of the state", shouldn't getUnit not return this unit, instead of null? |
What do you return if the state is UNDEF? In that case Another issue (I‘m not 100% sure here): if you do not reload the page, the widget will not change its unit. But with %unit% this can happen with every state update (900 m / 1 km). The correct solution would be to dynamically change the unit depending on the actual state (this obviously has to be done by the UI, since the item is asked only once) or show no unit at all. To fix it for now, set the unit in the state description instead of |
Yes, I could fix it locally by setting the unit explicitly in the state description. However your change basically broke every basic UI Setpoint and Slider using a Number type with dimension. While I understand your example for units of distance, mass or volume, it does not apply to temperatures. Dependent on where you live, you either want °C or °F. If the state is UNDEF, and the pattern doesn't contain an explicit unit, it should return the default unit for the type. |
My change did not break anything. It was BasicUI relying on erratic behavior of core. Zhat aside: your proposal would break a lot of things inside openHAB. |
This is a little too simple, isn't it? I fully agree that there is an issue is in the basic UI renderer, but that doesn't change the fact that it did work before, and due to your change UIs are now broken. Despite of that, in OpenHAB 3.3.0 getUnit did return the system default unit, and this was the expected behaviour in many or most cases. I don't see how this would break a lot of things? Let aside the UNDEF case - why can't getUnit not return the same unit it did use for formatting the value? |
How should the basic UI find out which unit to use, if it does not get it from the item? Can it just omit the unit completely and you will then assign the default unit on the server side? |
From the state, as the user requested by setting Returning the system unit is wrong. I don’t see why we should revert a fix to re-introduce a bug. Also there is a discussion on the forum about UoM handling where everybody agrees that presentation (from state description) and item unit should be separated and I believe that this will be the case in OH4. |
I don't have enough insight to argue about architectural decisions in OpenHAB. I just see that many UIs are broken now, the issue is not easy to understand and a lot of work to fix for people. What do you mean with "from the state"? When the current state is "19 °C", then you want the UI to parse the unit from the string themselves? Although you exactly know the unit, as you used it to format the string? Would it be an option to provide an additional getter for the default unit, so in case the the state is UNDEF, the UI still has a unit it can use? |
BTW, there might be an additional issue - if I understand the code correctly, if I don't have a state description and provide no pattern, it should return the default unit from the UnitProvider. However, if my item doesn't have a state description, I still have the same issue. |
Indeed, and that proves that unit handling is required in the UI anyway. |
Ok, finally I understand, the "%unit%" in the snippet code is not replaced because the method now returns null rather than a unit.
Maybe the impact to our official OH components of such change in core framework should have been at least evaluated ?! |
I guess it's impossible to know that other code depends on bugs to work. Probably that would have been found if there was proper test code. Unfortunately besides openhab-core we have very little tests, neither unit tests nor integration tests. |
The front code is updating the widget unit at each new received state update (when the page is opened).
If I correctly understand what you say, this is already done in my opinion. I just still do not understand why null was returned when the page is opened while it was said in the provided example that the item state was "19 °C ? |
Just a grep of the updated method in UI repo should have be sufficient to identify a probable impact. |
This situation would also already be that case in 3.3 for dimensions that did not have a default unit (e.g. flow rate). I must admit that not many people may control the flow of something from openHAB with a slider, but if someone had tried, he would have run into the same issue. The fix was in a private method which is used in public methods. |
I am ok to propose a fix in Basic UI but I would really like to understand why the method is returning null while the item state was "19 °C" ? A simple fix would be to replace "%unit" by an empty string in the snippet when the method returns null. |
To handle |
Understood. I will check again in details but for me the unit is correctly updated when receiving a state update while the page is opened. The problem would be only when opening the page and the first initialization of the unit. Rather than setting unit to "", I will try to extract the unit from the item state. |
Now that all the code has moved to Java 17, I have no idea if I can continue with a Java 11 dev env. If not, what are the steps to update our dev env ? |
No. If you look at the forum discussion about OH4 UoM handling (https://community.openhab.org/t/uom-default-units-and-consequences/142360) there is broad majority supporting that the state description should not be taken into account when determining the unit of the item (but add a new metadata to configure that). This is also what is implemented in openhab/openhab-core#3248. Regarding the dev environment: If you create the branch from the last 3.4.0 commit (i.e. immediately before the release) you can continue working with JDK 11. If you compile a jar then, it's usable in OH 3.4. What you need to update to use JDK 17 depends on your setup. I had to install JDK17 and change the project SDK in IntelliJ. |
First, I want to push quickly a fix for all OH3.4 users (in the patch 1). We can see later what to change for OH4. |
If this is better, I will push my fix directly in the 3.4.x branch. |
Searching where is used |
My guess would be that |
If null, I will try to find the unit in item state. First trying to switch to branch 3.4.x and build, hopping I can then run and test in Eclipse... |
The fix should not be too much difficult to implement but I am first fighting since several hours to have Eclipse consider my code changes ! |
Looking again what is done for slider and setpoint widgets in the frontend (JavaScript):
The way it is done for slider widget looks better but there will be still a particular case to consider: %unit% was in the state pattern, the item state was NULL or UNDEF when the page was opened, the item state is then updated (with a unit) while the page is opened. The frontend code has then to save the received unit but it must take the one in label and not in item state. Edit: in fact, it looks like the updated state is first converted by the framework to the unit mentioned in the state pattern or the default unit if no unit defined in state pattern. Only exception is if state pattern contains "%unit%". In that last case, there is no conversion as it is expected. So the way it is handled for the setpoint widget looks finally better to me. |
While I am not succeeding to test in Eclipse, I tested by replacing BasicUI bundle directly in my production environment. For setpoint widget, I succeeded to get the item state with the unit and so the problem is solved. For slider widget, the problem is that the core framework includes a specific code in ItemUIRegistryImpl that returns a DecimalType rather than a QuantityType in method convertState called by method getState(Widgetw): So if the state pattern contains "%unit%", with my current new code, no unit is then considered, the slider will generate a command without unit and then the unit is added by the core framework:
This could be a problem if the default unit does not match the real item state. |
IIRC the The change in unit has always been a problem when %unit% was used, maybe it was even worse, because it would not have ben detected for sliders at all. |
pattern In OH3.4, getUnitForWidget(Widget w) now returns null when the state pattern contains "%unit%". In that case, the unit must be searched in the item state. Fix openhab#1605 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
pattern In OH3.4, getUnitForWidget(Widget w) now returns null when the state pattern contains "%unit%". In that case, the unit must be searched in the item state. Fix openhab#1605 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
jar testet on my installation - does work for items without state description/pattern as well as items with pattern containing %unit%. |
@J-N-K sorry to bother you again, but can you quickly explain, why it is useful that each UI layer does implement this fallback logic to the state by itself, with the possibility to do it slightly different or introduce new bugs, instead of implementing it once properly on the item? |
Closed by #1612 |
Which UI are you reporting an issue for?
The problem
After updating to OpenHAB 3.4.0 the slider widgets for controlling the target temperature do no longer work. Moving the slider has no effect, the temperature is neither updated on the UI, nor is any event for changing the item state shown in the event log.
The reason is that request triggered by the slider is receiving a "400 Bad Request" response. When checking the request payload, I saw that the slider is sending "19 %unit%" as the update value. This seems to be causing the error, when I change the pattern on the item explicitely to "%.1f °C", the issue does no longer occur.
Expected behavior
When moving the slider, the item state should be updated and the target temperature should be changed.
Steps to reproduce
Your environment
Browser console
Browser network traffic
Additional information
Slider was working fine with OpenHAB 3.3.0, issue only occured after upgrading to 3.4.0
The text was updated successfully, but these errors were encountered: