-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
Channels once more displayed in correct order in Main UI #3448
Conversation
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
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.
LGTM
A unit test for checking the order would also be nice to prevent such regressions. |
Ok. Coming up. |
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Oops. I realise that the current version of my test has 4 channels only so it has a 1 in 24 chance of passing by random. So I will add some more channels to reduce that risk. |
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
I think |
itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/ThingChannelsTest.java
Outdated
Show resolved
Hide resolved
itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/ThingChannelsTest.java
Outdated
Show resolved
Hide resolved
The |
Yes that is my impression too. And in my actual testing, I can confirm that (using LinkedHashMap) the ordering does indeed persist over a restart (because LinkedHashMap properly serialises to, and deserialises from, a List..) |
Will it also reapply the order according to how they are ordered in the Thing Type after deserialization? Channels could get rearranged in newer OH versions or new channels may get added in between existing channels. |
Makes me also wonder what happens wrt new channels during a binding update when the update instructions are applied. Will the update instructions result in the new channels being added to the end of the list of channels versus a new installation of the binding which will put the new channels wherever the developer put them in the thing xml? |
AFAIK, if you call ‘editThing’ you get the original channels as a List, and recreate the Thing via ‘.withChannels’ you supply the new channels as a List. So maintaining the sequence of entries in the List is the critical point. And if new channels are added via ‘List.add’ they are added at the end of the List, etc. |
AFAIK the channel order is defined by thing.xml when the thing is first instantiated. Thereafter the channel order should be serialised and deserialised in the same order on each restart. I am not 100% sure but I think that if a new binding version changes the order in thing.xml, that change is NOT directly applied to already defined things, so you have to delete and recreate the thing to get the new order. And it’s probably different for things defined via ‘.things’ file. |
Sorry, I was referring to a new feature in 4.0 that let's you (the developer) provide instructions that indicate, new, changed, or deleted channels, which are applied to the thing without the need to delete/recreate the thing. For example, see this PR. In this case, the new channels were added to the end of the channels in thing-types.xml. However, what if the new channels were inserted into the middle of the list of channels in thing-types.xml? In the case of a newly created thing, the order would be as the channels are defined in thing-types.xml. But in the case of an existing thing that's updated as a consequence of the update instructions, I assume the new channels would be added at the end of the list. I don't think this is a really big deal. But it is behavior that we want to understand so that we know what to expect. So for example, let's say I have two things of the same thing type. One thing was newly created and one was an existing thing that was updated according to the update instructions. I'm assuming the order of the channels shown in the UI might be different depending on where the new channels appear in the channel list in thing-types.xml. |
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@mhilbush thanks for putting me on the right track. I think your concern is not directly impacting the PR. This PR is essentially just about ensuring that whatever channels are created in a thing shall remain consistently in the same order in which they were originally added. i.e. both
|
Yes, I agree. Since your original issue had to do with the order of channels in the UI, I just wanted to raise awareness that there may still be some cases where the order of channels presented in the UI may not exactly match the order of channels in the thing xml. |
@mhilbush digging into the OH core channel modification instruction code, it looks like there are (currently) two supported instructions, namely Line 84 in 0894d25
|
Right. So this is the case I was contemplating. Original thing.xml channels
New thing.xml channels with update instructions to add
A newly created thing would show in the UI as this, correct?
What would an existing thing look like in the UI after the update instructions were applied? (I ask this as a question because I'm not sure what will actually happen)
|
I think you are wrong. An add instruction will append the new channel to the existing list. It will not insert into the middle of an existing list. |
I'm sorry for not being clear. Yes, that's exactly what I'm trying to say. In my example above, the channels of a newly created thing will be in the order in which the channels appear in the thing.xml. In that example, the developer inserted new channels The channels of a thing updated by the update instructions will not be in the order in which the channels appear in the thing.xml because the new channels will be appended. So for those two things, won't the order of the channels in the UI be different? |
Yes, that would be the case. But I don't think there is an easy way around it. While it may be possible to add something like |
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.
LGTM, thanks.
@J-N-K Yep, I agree completely. Like I said earlier, I just wanted to bring some awareness to the behavior for when someone asks why their channels are "out of order." 😉 |
* Fix sort order of Things in UI * Add itest for channel order Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch> GitOrigin-RevId: 73b8a3a
Fixes #3442
As described in #3442 "we switched from a
List<Channel>
to aMap<ChannelUID, Channel>
which does not necessarily preserve the order" -- with the consequence that in the Main UI, Thing Channels were no longer displayed in the order in which they were declared in thething.xml
file.This PR uses
LinkedHashMap<ChannelUID, Channel>
instead ofHashMap<ChannelUID, Channel>
so that Thing Channels are once more displayed in the order in which they were declared in thething.xml
file.Signed-off-by: Andrew Fiddian-Green software@whitebear.ch