How to determine if a channel is readonly

In my handleCommand method, I want to know if the channel is readonly. I can see there’s an isReadOnly() method on the ChannelType class, but I’m just not seeing how to get a ChannelType object given a ChannelUID. I’m sure I’m missing something obvious…

Try channelType.getState().isReadOnly().

Ok. I see that. But how do I get the channelType object using the ChannelUID passed into handleCommand?

Below is based on my memory.

If you inherit from base thing handlers available in framework then getChannel(channelUID).getType or getThing().getChannel(...) to switch from handler to model layer.

That’s what I was hoping… But getThing().getChannel(channelUID) returns a Channel object. From there I can get the ChannelTypeUID. But I still don’t see a way to get the ChannelType.

Do I need a ChannelTypeProvider? If so, how do I get one of those?

You’re right - I went over IDE just now and it seems you need to make an extra mile with ChannelTypeRegistry which will allow you to exchange channel type uid for its model instance.

1 Like

That was it. Need to inject that into the thing handler. Works perfectly! Thanks!!!