-
-
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
removed ThingLinkManager and with it the auto-linking feature and "Simple Mode" #1385
Conversation
…mple Mode" Signed-off-by: Kai Kreuzer <kai@openhab.org>
Signed-off-by: Kai Kreuzer <kai@openhab.org>
Signed-off-by: Kai Kreuzer <kai@openhab.org>
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 and thanks!
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/channels-not-responding/96712/11 |
FYI - I was looking for the calls of |
@splatch That's interesting. I guess you are right, I removed a bit too much with this PR - I thought that the class only deals with "Thing links", while it also covered parts of the "Item links". Will see how to best revert that part... |
I managed to get notifications back via registry listener, however I have impression that it is not a valid way. First of all - it is not attached to Thing and its handler lifecycle but to the link presence. @Component(immediate = true)
public class ChannelLinkNotifier implements RegistryChangeListener<ItemChannelLink> {
private final Logger logger = LoggerFactory.getLogger(ChannelLinkNotifier.class);
private final ItemChannelLinkRegistry itemChannelLinkRegistry;
private final ThingRegistry thingRegistry;
@Activate
public ChannelLinkNotifier(@Reference ItemChannelLinkRegistry itemChannelLinkRegistry, @Reference ThingRegistry thingRegistry) {
this.itemChannelLinkRegistry = itemChannelLinkRegistry;
this.thingRegistry = thingRegistry;
// registry do not dispatch notifications about existing links to listeners
itemChannelLinkRegistry.getAll().forEach(this::added);
itemChannelLinkRegistry.addRegistryChangeListener(this);
}
@Override
public void added(ItemChannelLink element) {
ChannelUID channelUID = element.getLinkedUID();
ThingUID thingUID = channelUID.getThingUID();
call(thingUID, handler -> handler.channelLinked(channelUID), "channelLinked");
}
@Override
public void removed(ItemChannelLink element) {
ChannelUID channelUID = element.getLinkedUID();
ThingUID thingUID = channelUID.getThingUID();
call(thingUID, handler -> handler.channelUnlinked(channelUID), "channelUnlinked");
}
protected void call(ThingUID thingUID, Consumer<ThingHandler> consumer, String method) {
// Nullability checks can't understand Java 8 Optional semantics.. in 2020! What a shame!
Thing thing = thingRegistry.get(thingUID);
if (thing != null) {
ThingHandler handler = thing.getHandler();
if (handler != null && ThingHandlerHelper.isHandlerInitialized(handler)) {
consumer.accept(handler);
} else {
logger.info("Skipping notification to thing {} handler {} method call, as it is not initialized",
thingUID, method);
}
}
}
@Override
public void updated(ItemChannelLink oldElement, ItemChannelLink element) {
removed(oldElement);
added(element);
}
} |
@splatch I quite like your ChannelLinkNotifier - what problems do you see with it that you call it "not a valid way"? Basing it on the lifecycle of the links sounds like a good approach to me. |
@kaikreuzer from what I have observed it is not called when thing/thing handler is restarted. This leaves a gap in case of configuration updates. It gets triggered only if link is recreated. Essentially this listener needs to be a combined one. |
Hm, right, I remember. The ThingLinkManager was implemented as a tracker, i.e. it pushed ALL linked channels to newly appearing listeners (thing handlers). This was mainly for the initialization and results in a "REFRESH" command being sent for every linked channel at startup (by the default implementation of Thinking about it, I really wonder if we need to keep that behavior in place. It would somehow make more sense to me to only call ´channelLinked` on active handlers and not for all already linked channels at startup. I haven't really experienced any bindings that rely on this behavior in any way, but I also cannot tell, what might break if we leave it away. But there's also the chance that it even improves the overall behavior as far less REFRESH commands will be flying around during startup... @openhab/core-maintainers What are your thoughts on this? Shall we dare to change this behaviour? |
Why not remove the default implementation which creates the |
The default implementation definitely has to stay as it is required for any active handler - I am very certain that many of not most bindings will break if we remove it and I also do not see a reason for it to be removed. |
I didn't mean to actually remove the method itself, I meant just to remove the call to REFRESH - that would allow bindings to implement a refresh if they need, but not force it. Anyway, that aside I did misread this - I thought it was about removing the call completely which would definitely not be good. I'm ok with it not being called on startup. |
It's worth a try. I haven't looked at the code, but if handlers only implement refresh commands and not channellinked calls the data may not be properly refreshed. |
I use it in our bacnet v2 binding to start polling for data so I rely on old behavior. I see no issues migrating to new behavior, once it is defined. |
I think we can omit the On the other hand changing the |
@cweitkamp Just to clarify again: As mentioned above, the suggestion here is merely to change the behaviour at handler startup and omit sending REFRESH commands for every linked channel. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/moving-from-oh-this-is-no-rant/112194/42 |
…mple Mode" (openhab#1385) * removed ThingLinkManager and with it the auto-linking feature and "Simple Mode" Signed-off-by: Kai Kreuzer <kai@openhab.org> * removed feature from REST API as well Signed-off-by: Kai Kreuzer <kai@openhab.org> * removed tests Signed-off-by: Kai Kreuzer <kai@openhab.org> GitOrigin-RevId: 857679f
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/zwave-polling-unlinked-channels/152554/3 |
@ghys has added great support in the new UI for link management without requiring this feature, which caused a lot of problems in 2.x.
Signed-off-by: Kai Kreuzer kai@openhab.org