[SOLVED] Polling only for linked channels

Hi,

I am quite new to openhab development and after struggling a lot with setting up de dev environment (again, after migration of the build system) I come now to a real question:

How do I find out which channels of a thing a linked?

Background: I need to poll the data via a serial line and would like to avoid polling data that is afterwards not used. Or in case I completely misunderstood the concept of channels and items?

Ah and there is RefreshType in the command parameter of handleCommand. Would that be the key and there is some general configuration that I did not yet find which ensures that a channel is refreshed at least each XXX minutes?

I’m pretty sure any polling is entirely down to binding author.

How/if your binding implements REFRESH is up to you too, I think. I understand OH will attempt REFRESH at reboot, but there is no automatic poll otherwise.
Users could of course construct their own polling with timers and REFRESH.

Astro binding Azimuth channels I think are examples of channels that only invoke some processing when actually linked, maybe there is something to learn there.

thanks for tehe quick answer. So to recap: I have to do the refresh in the binding. Ok. Now, as external traffic is involved and the device I want to talk to has a LOT of channels which are only interesting in some rare use cases I want to prevent polling the data for the channels that are not even linked to items.

Any idea how to find out whether a channel is linked?

Astro binding Azimuth channels I think are examples of channels that only invoke some processing when actually linked, maybe there is something to learn there.

1 Like

In the thing handler there is a method isLinked that takes a channel uid as argument.
In general the scheduler protected field is used to schedule a polling task.

1 Like

@hilbrand that is exactly what I was looking for. Thanks a lot, it works like a charm!
@rossko57 - your tip is leading the very same solution :slight_smile: astro binding is using ThingHandler.isLinked()