openhab-core: The channelLinked method is not called after restart

If a channel is dynamically added to a thing, on restart of openHAB the channelLinked method doesn’t get called after initial linking of the item to the channel.

If items are defined in a .items file, the channelLinked method will get called if the file is edited or touched after OH3 is up and running.

This is a regression from OH2 and is similar to https://github.com/openhab/openhab-core/issues/1596

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 35 (23 by maintainers)

Commits related to this issue

Most upvoted comments

I will try and find some time to look at this for ZWave and ZigBee on Thursday or Friday.

OH2 was buggy by calling this method unnecessarily often

Maybe, but that’s not relevant. If I understand correctly, the only buggy part is that the REFRESH command got called too many times. I think we can agree that shouldn’t be the case, but that is not related to this issue.

a couple of bindings unfortunately decided to rely on that behavior

You make out like binding developers are doing something wrong, but in the past, even if not now, this was the case that this that this call WAS meant to be called after initialisation -:

image

https://github.com/eclipse-archived/smarthome/pull/1890

It should be pretty easy for any thing handler to iterate over the list of linked channels within the initialize() method.

True, but that requires a change to the way things work, and as we see, it has broken things, and adding code to loads of bindings which doesn’t seem sensible.

Wrt the docs, they state “This method is only called, if the thing has been initialized” - it nowhere states that it is called retro-actively for any event that happened before initialization

Maybe it doesn’t now, but as I showed above - it looks like it used to - you even implemented this yourself.

I tried @wborn suggestion and it works. Specifically, I added something like:

getThing().getChannels().forEach(channel -> {
    if (isLinked(channel.getUID())) {
        channelLinked(channel.getUID());
    }
});

I hope the decision is to fix this, not fixing it feels wrong. Also, at a minimum, the channelLinked javadoc will need to be updated to indicate that this might not get called and can not be relied on.