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

[Homematic] Fix "Channel not found for Datapoint" errors #11493

Merged
merged 1 commit into from Dec 11, 2021

Conversation

Flole998
Copy link
Member

@Flole998 Flole998 commented Nov 1, 2021

@Flole998
Copy link
Member Author

Flole998 commented Nov 1, 2021

@FStolte @gerrieg @mdicke2s Can anybody review please?

@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/homematic-binding-channel-not-found-for-datapoint-errors-for-definitely-existing-channels/26209/134

@maniac103
Copy link
Contributor

maniac103 commented Nov 5, 2021

What still irks me about this is that this change is just a workaround for what should be a bug elsewhere. Did you try adding some breakpoints in ThingFactory or BaseThingHandlerFactory to check the state of the ThingType at thing creation time?
AFAICT, the flow is

  • inbox contains thing UID and thing type UID
  • inbox calls ThingFactory.createThing(), passing thing UID, thing type UID, and bridge UID
  • ThingFactory.createThing() tries to lookup a ThingHandlerFactory based on the thing type UID; if this fails, no thing is created
  • ThingFactory.craeteThing() calls createThing() in the found factory (here, it's HomematicThingHandlerFactory)
  • HomematicThingHandlerFactory.createThing (or rather the base class implementation in BaseThingHandlerFactory) looks up the ThingType by the thing type UID via ThingTypeRegistry, which in turn looks through all registered ThingTypeProviders. In our case, HomematicThingTypeProviderImpl should match. If no ThingType can be found, no thing is created.
  • ThingFactory.createThing is called, passing in the found ThingType, which in turn calls ThingFactoryHelper.createChannels
  • ThingFactoryHelper.createChannels loops over thingType.getChannelDefinitions(), calling ThingFactoryHelper.createChannel for each one, which in turn calls ThingFactoryHelper.createChannelBuilder
  • That one looks up a ChannelType from the channel type UID in the channel definition using a call to ChannelTypeRegistry.getChannelType()
  • That one looks through all ChannelTypeProviders (here: HomematicChannelTypeProviderImpl) for a matching channel type
  • EDIT: HomematicChannelTypeProviderImpl should return the channel type which was added at HomematicTypeGeneratorImpl.generate() time

AFAICT, the only case where a thing can be created without channels is if the channel type lookup fails, so it would be great if you could verify this actually being the case (maybe start by overriding and adding some debug statements to HomematicThingHandlerFactory.createThing() and HomematicChannelTypeProviderImpl.getChannelType()). If it is, we need to check what's off in channel type registration. Unfortunately it's hard to follow git history due to the code being moved between repositories several times.

@Flole998
Copy link
Member Author

Flole998 commented Nov 6, 2021

The reason this is necessary is, that (at least) when using text based config it could happen that things are created before the bridge is online or the thing type has been populated with the channels. In that case an empty thing type is used and the thing is missing the channels as when a thing type is updated the things that use it aren't automatically. So this will add the channels in that case.

@maniac103
Copy link
Contributor

So this essentially means that createThing() is called before generate() is called, right?

@Flole998
Copy link
Member Author

Flole998 commented Nov 7, 2021

Yes iirc that was the issue. I also tried to re-create (basically reload) the thing if the channels are empty and that created the channels as well (but caused other issues).

If you ask me the current attempt is a wrong approach anyways as there's another Limit: If there are multiple versions of the same device with different channels it will cause issues. It would be better to request the channels for each thing and populate them on initialization.

Signed-off-by: Flole <flole@flole.de>
@Flole998
Copy link
Member Author

@maniac103 I just fixed the 2 things you commented.

@wborn wborn added the bug An unexpected problem or unintended behavior of an add-on label Nov 27, 2021
@fwolter fwolter merged commit 145bd0e into openhab:main Dec 11, 2021
@fwolter
Copy link
Member

fwolter commented Dec 11, 2021

The sign-off message should contain your real name. For the next contribution...

@fwolter fwolter added this to the 3.2 milestone Dec 11, 2021
@wborn wborn changed the title [Homematic] Fix "Channel not found for Datapoint"-Errors [Homematic] Fix "Channel not found for Datapoint" errors Dec 18, 2021
@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/homematic-binding-channel-not-found-for-datapoint-errors-for-definitely-existing-channels/26209/136

NickWaterton pushed a commit to NickWaterton/openhab-addons that referenced this pull request Dec 30, 2021
Signed-off-by: Flole <flole@flole.de>
Signed-off-by: Nick Waterton <n.waterton@outlook.com>
mischmidt83 pushed a commit to mischmidt83/openhab-addons that referenced this pull request Jan 9, 2022
Signed-off-by: Flole <flole@flole.de>
Signed-off-by: Michael Schmidt <mi.schmidt.83@gmail.com>
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this pull request Jan 28, 2022
volkmarnissen pushed a commit to volkmarnissen/openhab-addons that referenced this pull request Mar 3, 2022
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this pull request May 5, 2022
andan67 pushed a commit to andan67/openhab-addons that referenced this pull request Nov 6, 2022
andrasU pushed a commit to andrasU/openhab-addons that referenced this pull request Nov 12, 2022
Signed-off-by: Flole <flole@flole.de>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Homematic] Race condition causing items without channels to be created
5 participants