-
-
Notifications
You must be signed in to change notification settings - Fork 431
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
[WIP] Fix thing creation for updated XML #1027
Conversation
…sFromThingTypeDefinition` to only create channels, that are actually defined in the XML. This allows updated XML descriptions for already existing things to be taken into account. Signed-off-by: André Füchsel <[email protected]>
Just FTR: Possible solution for eclipse-archived/smarthome#2555. |
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.
Thanks for working on this feature. Very much appreciated.
configDescriptionRegistry); | ||
|
||
ThingBuilder thingBuilder = editThing(); | ||
thingBuilder.withChannels(channels); |
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.
IIRC this method clears the list of all existing channels. We have to filter the list of new channels to add only non existing ones. On the other hand we have to deal with removal of channels and changes in channel types too.
Be aware there currently is an issue regarding the withoutChannels
for the BridgeBuilder
- it returns a ThingBuilder
instance - see https://github.com/openhab/openhab-core/pull/908/files#diff-44fdf6ebca4daa065ec6088297fb2859R82.
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.
We have to filter the list of new channels to add only non existing ones
Why ? (What if there are also channels removed from the XML ?)
Indeed this method clears all channels on the thing and replaces them with the one declared in the XML, but once the handler is initialized again - all other channels (added dynamically) will be re-added (it will behave just like if the thing is paired for a very first time)
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.
Yes, exactly but please keep in mind that channels can have a user specific configuration. You will throw away any of them when you re-add all the channels. We should try to keep them.
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.
and there are channel that can be added by user interaction -- so manually per request. That information will be lost, too.
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.
Yes - I know - this is already mentioned in the description in the PR.
Few questions on that topic:
How are actually those channels used ?
How are the stated updated if the handler doesn't know about them.
How commands sent to those channels handled ?
Signed-off-by: André Füchsel <[email protected]>
Hmm, not sure why the build failed. Just pushed an update to my branch... |
I think it failed because there are merge conflicts due to my recent builder refactoring (see #908). |
Maybe, but after a rebase I am not sure how to fix my code, because |
A builder should build independent instances of an entity each time you call its The solution for your approach is to add an internal list of things to the |
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.
@afuechsel Do you have an idea how to continue?
I did some tests with your implementation and it looks very good. I did the rebase like this: afuechsel@a5f55bb.
@@ -101,4 +102,13 @@ public BridgeBuilder withLocation(@Nullable String location) { | |||
return (BridgeBuilder) super.withLocation(location); | |||
} | |||
|
|||
public BridgeBuilder withThings(@Nullable List<Thing> things) { | |||
BridgeImpl bridge = ((BridgeImpl) thing); |
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.
Some additional stuff:
-
validateThingUID(thing)
- makes sure the thing belongs to the bridge -
ensureUniqueThing(thing)
- ensures the thing will be added only once
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.
Bear with me - I am short of time. I think, the only issue left open is the removal of channels during editThing
, that are not defined in XML and therefore must not be removed. I have no clear idea yet, how to solve this.
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.
It might help to add a field to the Channel
class for tracking the origin. Then it can be removed if it was created from the ThingType definition.
There are also some other corner cases:
- The new ThingType defines a channel that was already created by the user. In that case the user channel and configuration might get lost because it is replaced with that defined in the ThingType.
- An existing channel is renamed. If the channel has configuration parameters its values will be lost when the old channel is removed.
I'm fine with skipping those corner cases for now because I think they won't occur often and the changes in this PR would do more good than harm. :-)
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.
It might help to add a field to the Channel class for tracking the origin.
Yes, that is true. But I am afraid it is not possible until we found a solution for #731.
btw: I prepared a new rebase for these changes including some unit tests. master...cweitkamp:pr-1027
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/openhab-unstable-after-upgrade-to-2-5/87861/65 |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/system-started-triggered-every-minute-with-2-5-0-stable/89970/19 |
How are things coming along with this PR? Any chance this could be added to the OH 3.0 backlog? Is that the intent of this project... https://github.com/orgs/openhab/projects/3? |
Done. I absolutely vote for it. |
Just a comment on this - we also need to handle changes to channels. Channels have At some point in the past I had proposed to add a version number to the thing definition so that it was explicit that the definition had changed rather than trying to detect the all changes which might be problematic. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: |
Another year done and still no solution to it. The longer it takes, the more I am convinced that my original idea with versioned thing-types and upgrade-logic within the binding is a better and more viable solution than this general approach. |
@J-N-K Unfortunately it does not. I tried several times with your original solution and I was not able to get it to work completely. I was not able to get all tests green nor did the newly created tests work out well. In the runtime it only worked sometimes. This was due to the dynamics of the thing handler creation and their conflict with the ready marker triggers. Also the introduction of a queue of all not YET resolved thing types did not work out well. I have a 95% solution still as a branch. Therefore we decided to go with the now shown solution here and it worked out pretty well (with some modifications not yet part of this PR). In our solution that is still based on the frozen old ESH code base we now have a working implementation of it. I also tried to address the openHAB issue with user-created channels, something we don´t have in our solution. The easiest way was the introduction of a flag in the channels that indicate whether or not they have been created by the XMLs. Although I am not actively contributing to openHAB I was hoping I could eventually finish this PR but it seems I am lacking the time to. May be I could find some time to at least push the latest changes from our code base which works for us.. The problem now is that openHAB evolved over the time but we are still based on plain ESH which is slightly different. Sorry for that. |
@afuechsel my original idea was implemented in the OneWire binding in ESH, before it got merged and removed during review. It simply had a property |
@J-N-K Feel free to revert the changes here and go with your idea. Maybe I made a mistake since the update with your implementation never worked for me. As I said, I have unfortunately not enough time to deal deeper with openHAB. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: |
IMO removing this from OH3 backlog is a big step backwards. It's now more than four years that we have to delete and re-create things after each update that adds new features. |
@J-N-K What do you mean? It is no step backward, it is just no step forward. |
It‘s a step backward to remove it from the backlog. Previously this was accepted as an issue to be solved for OH3. |
Keeping it in the backlog won't fix it, though. If you can come up with a PR and a fix for it in time for 3.0, I'll happily put it back. |
(moved comment to #1924) |
Signed-off-by: Ben Clark <[email protected]>
Hello @afuechsel, do you think you will find time to continue working on this PR? |
Unfortunately I no more time to work for openHAB. Feel free to close this PR or someone else could continue with it. It’s rather old now. |
Thanks for letting us know @afuechsel! 👍 I've archived your branch in my own repo, so someone can pick this up in the future as it certainly looked like this was the most promising approach so far. |
This is a new approach to solve the problem that I was trying to solve in #628 that in turn was based on another PR of @J-N-K (#527).
It works as long as there are no user-defined channels, therefore it's still work in progress. I'd like to ask for our comments about this approach.
ThingManager#doInitializeHandler
callsBaseThingHandler#setChannelsFromThingTypeDefinition
to only create channels, that are actually defined in the XML. This allows updated XML descriptions for already existing things to be taken into account.Signed-off-by: André Füchsel [email protected]