openhab / openhab-core

Core framework of openHAB
https://www.openhab.org/
Eclipse Public License 2.0
922 stars 423 forks source link

ProfileTypeBuilder.withSupportedChannelTypeUIDs is ignored by StateProfileTypeImpl #4293

Open obones opened 3 months ago

obones commented 3 months ago

When writing an addon that provides a transformation profile one will most likely use ProfileTypeBuilder to get an instance of ProfileType to be returned by the ProfileTypeProvider.getProfileTypes implementation.

This is can be done with code like this:

            return ProfileTypeBuilder
                    .newState(uid, "Label")
                    .build();

With the code above, the transformation profile is usable for any item and any channel, which may not be desirable and so one may want to call withSupportedChannelTypeUIDs to limit the transformation profile to a given channel type.

Expected Behavior

When withSupportedChannelTypeUIDs has been called on ProfileTypeBuilder, the created transformation profile should only appear on item links that are between any item and a channel only of the given type UID.

Current Behavior

Sadly, the profile above is shown for links on any channel, there are no filtering done. This is because ProfileTypeBuilder.newState sets up a callback that ignores leSupportedChannelTypeUIDs at this line

Possible Solution

I would suggest changing StateProfileTypeImpl to accept supportedChannelTypeUIDs in its constructor and override getSupportedChannelTypeUIDs just like TriggerProfileTypeImpl does. Note that this would only fix the current issue, but I believe both StateProfileTypeImpl and TriggerProfileTypeImpl should override the three possible filtering sources, not two each like now.

Steps to Reproduce (for Bugs)

  1. Create an addon that implements a ProfileTypeProvider service
  2. Use ProfileTypeBuilder.newState alongside withSupportedChannelTypeUIDs
  3. See that the transformation profile is not filtered out and available on all channel links

Context

I'm currently trying to offer transformation profiles for Air Quality Indicator channels in my OpenMeteo binding and would like them to be limited to channels they apply to.

Your Environment

J-N-K commented 3 months ago

I see your use-case. I think there never was a discussion about filtering StateProfiles by ChannelTypeUID. I would vote for adding that.

J-N-K commented 3 months ago

Can you prepare a pull request?

openhab-bot commented 3 months ago

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/cant-compile-openhab-core-no-versions-available-for-org-eclipse-emf-org-eclipse-emf-ecore-2-35-0-3-0-0-within-specified-range/157329/1

obones commented 3 months ago

I have submitted PR #4325, I hope it's fine as I could not find any related unit tests.