Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

afuechsel
Copy link
Contributor

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 calls BaseThingHandler#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]

…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]>
@cweitkamp cweitkamp added the work in progress A PR that is not yet ready to be merged label Sep 14, 2019
@cweitkamp
Copy link
Contributor

Just FTR: Possible solution for eclipse-archived/smarthome#2555.

Copy link
Contributor

@cweitkamp cweitkamp left a 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);
Copy link
Contributor

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.

Copy link

@ivivanov-bg ivivanov-bg Sep 16, 2019

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)

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link

@ivivanov-bg ivivanov-bg Sep 16, 2019

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]>
@afuechsel
Copy link
Contributor Author

Hmm, not sure why the build failed. Just pushed an update to my branch...

@cweitkamp
Copy link
Contributor

I think it failed because there are merge conflicts due to my recent builder refactoring (see #908).

@afuechsel
Copy link
Contributor Author

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 BridgeBuilder now cannot access the thing. I studied your PR about changing builders but I do not completely understand, why this change was necessary and what exactly is the improvement.

@cweitkamp
Copy link
Contributor

A builder should build independent instances of an entity each time you call its build() method. This was not the case before my refactoring (e.g. if you built a thing once and called withLabel(...) a second time on the builder it should not change the label of the previous created thing).

The solution for your approach is to add an internal list of things to the BridgeBuilder. You can move the logic to add things to the bridge into the build() method. Is that a possible solution for you?

Copy link
Contributor

@cweitkamp cweitkamp left a 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);
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Member

@wborn wborn Oct 23, 2019

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. :-)

Copy link
Contributor

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

@openhab-bot
Copy link
Collaborator

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

@openhab-bot
Copy link
Collaborator

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

@5iver
Copy link

5iver commented Feb 6, 2020

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?

@cweitkamp
Copy link
Contributor

Any chance this could be added to the OH 3.0 backlog?

Done. I absolutely vote for it.

@cdjackson
Copy link
Contributor

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.

Just a comment on this - we also need to handle changes to channels. Channels have properties and we need to manage changes in these as well.

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.

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/how-should-i-upgrade-existing-things-when-i-update-my-binding/94842/4

@J-N-K
Copy link
Member

J-N-K commented Apr 13, 2020

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.

@afuechsel
Copy link
Contributor Author

afuechsel commented Apr 14, 2020

@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.

@J-N-K
Copy link
Member

J-N-K commented Apr 14, 2020

@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 thingTypeVersion for each thing-type, a number that has to be increased by the developer each time changes to the thing type are done. The thing handlers check the version number during initialization and upgrade the thing when necessary. Since the developer knows what changed, he can make the correct decision which channels need to be added, changed or removed and what needs to be kept.

@afuechsel
Copy link
Contributor Author

@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.

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/solved-openweathermap-binding-no-difference-between-condition-id-and-icon-id/99829/9

@J-N-K
Copy link
Member

J-N-K commented Dec 13, 2020

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.

@kaikreuzer
Copy link
Member

@J-N-K What do you mean? It is no step backward, it is just no step forward.

@wborn wborn linked an issue Dec 13, 2020 that may be closed by this pull request
@J-N-K
Copy link
Member

J-N-K commented Dec 13, 2020

It‘s a step backward to remove it from the backlog. Previously this was accepted as an issue to be solved for OH3.

@kaikreuzer
Copy link
Member

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.

@J-N-K
Copy link
Member

J-N-K commented Dec 13, 2020

(moved comment to #1924)

Rosi2143 pushed a commit to Rosi2143/openhab-core that referenced this pull request Dec 26, 2020
@afuechsel afuechsel requested a review from a team as a code owner December 28, 2020 08:22
Base automatically changed from master to main January 18, 2021 20:04
@wborn wborn added the stale As soon as a PR is marked stale, it can be removed 6 months later. label Nov 19, 2021
@wborn
Copy link
Member

wborn commented Nov 19, 2021

Hello @afuechsel, do you think you will find time to continue working on this PR?

@afuechsel
Copy link
Contributor Author

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.

@wborn
Copy link
Member

wborn commented Nov 20, 2021

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.

@wborn wborn closed this Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core stale As soon as a PR is marked stale, it can be removed 6 months later. work in progress A PR that is not yet ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update existing Things for definition changes
10 participants