Skip to content
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

Use the ChannelUID to retrieve the Channel from a Thing #4067

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private Recommendation shouldAutoUpdate(Item item) {
for (ChannelUID channelUID : linkedChannelUIDs) {
Thing thing = thingRegistry.get(channelUID.getThingUID());
if (thing == null //
|| thing.getChannel(channelUID.getId()) == null //
|| thing.getChannel(channelUID) == null //
|| thing.getHandler() == null //
|| !ThingStatus.ONLINE.equals(thing.getStatus()) //
) {
Expand All @@ -223,7 +223,7 @@ private Recommendation shouldAutoUpdate(Item item) {
continue;
}
AutoUpdatePolicy policy = AutoUpdatePolicy.DEFAULT;
Channel channel = thing.getChannel(channelUID.getId());
Channel channel = thing.getChannel(channelUID);
if (channel != null) {
AutoUpdatePolicy channelpolicy = channel.getAutoUpdatePolicy();
if (channelpolicy != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private ProfileCallback createCallback(ItemChannelLink link) {
return null;
}

channel = thing.getChannel(link.getLinkedUID().getId());
channel = thing.getChannel(link.getLinkedUID());
if (channel == null) {
return null;
}
Expand Down Expand Up @@ -399,7 +399,7 @@ private <T extends Type> void handleEvent(String itemName, T type, @Nullable Str
ThingUID thingUID = channelUID.getThingUID();
Thing thing = thingRegistry.get(thingUID);
if (thing != null) {
Channel channel = thing.getChannel(channelUID.getId());
Channel channel = thing.getChannel(channelUID);
if (channel != null) {
if (thing.getHandler() != null) {
// fix QuantityType/DecimalType, leave others as-is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public ThingConfigDescriptionAliasProvider(final @Reference ThingRegistry thingR
return null;
}

Channel channel = thing.getChannel(channelUID.getId());
Channel channel = thing.getChannel(channelUID);
if (channel == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public ChannelBuilder createChannelBuilder(ChannelUID channelUID, ChannelTypeUID

@Override
public ChannelBuilder editChannel(Thing thing, ChannelUID channelUID) {
Channel channel = thing.getChannel(channelUID.getId());
Channel channel = thing.getChannel(channelUID);
if (channel == null) {
throw new IllegalArgumentException(
String.format("Channel '%s' does not exist for thing '%s'", channelUID, thing.getUID()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void addThingTracker(ThingTracker thingTracker) {
ThingUID thingUID = channelUID.getThingUID();
Thing thing = get(thingUID);
if (thing != null) {
return thing.getChannel(channelUID.getId());
return thing.getChannel(channelUID);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Collection<ConfigDescription> getConfigDescriptions(@Nullable Locale loca
if (thing == null) {
return null;
}
Channel channel = thing.getChannel(link.getLinkedUID().getId());
Channel channel = thing.getChannel(link.getLinkedUID());
if (channel == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ public void setup() {

when(onlineThingMock.getHandler()).thenReturn(handlerMock);
when(onlineThingMock.getStatus()).thenReturn(ThingStatus.ONLINE);
when(onlineThingMock.getChannel(eq(CHANNEL_UID_ONLINE_1.getId())))
when(onlineThingMock.getChannel(eq(CHANNEL_UID_ONLINE_1)))
.thenAnswer(answer -> ChannelBuilder.create(CHANNEL_UID_ONLINE_1, CoreItemFactory.STRING)
.withAutoUpdatePolicy(policies.get(CHANNEL_UID_ONLINE_1)).build());
when(onlineThingMock.getChannel(eq(CHANNEL_UID_ONLINE_2.getId())))
when(onlineThingMock.getChannel(eq(CHANNEL_UID_ONLINE_2)))
.thenAnswer(answer -> ChannelBuilder.create(CHANNEL_UID_ONLINE_2, CoreItemFactory.STRING)
.withAutoUpdatePolicy(policies.get(CHANNEL_UID_ONLINE_2)).build());

when(offlineThingMock.getHandler()).thenReturn(handlerMock);
when(offlineThingMock.getStatus()).thenReturn(ThingStatus.OFFLINE);
when(offlineThingMock.getChannel(eq(CHANNEL_UID_OFFLINE_1.getId())))
when(offlineThingMock.getChannel(eq(CHANNEL_UID_OFFLINE_1)))
.thenAnswer(answer -> ChannelBuilder.create(CHANNEL_UID_OFFLINE_1, CoreItemFactory.STRING)
.withAutoUpdatePolicy(policies.get(CHANNEL_UID_OFFLINE_1)).build());

Expand Down