Skip to content

Commit

Permalink
[Homematic] Fix "Channel not found for Datapoint"-Errors (openhab#11493)
Browse files Browse the repository at this point in the history
Signed-off-by: Flole <flole@flole.de>
  • Loading branch information
Flole998 authored and andan67 committed Nov 5, 2022
1 parent 0e51cb4 commit 2b8a18f
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,52 @@ private void doInitializeInBackground() throws GatewayNotAvailableException, Hom
}
updateConfiguration(config);

boolean channelsChanged = false;

// update thing channel list for reconfigurable channels (relies on the new value of the
// CHANNEL_FUNCTION datapoint fetched during configuration update)
List<Channel> thingChannels = new ArrayList<>(getThing().getChannels());

if (thingChannels.isEmpty()) {
for (HmChannel channel : device.getChannels()) {
for (HmDatapoint dp : channel.getDatapoints()) {
if (HomematicTypeGeneratorImpl.isIgnoredDatapoint(dp)
|| dp.getParamsetType() != HmParamsetType.VALUES) {
continue;
}
ChannelUID channelUID = UidUtils.generateChannelUID(dp, getThing().getUID());
if (containsChannel(thingChannels, channelUID)) {
// Channel is already present
continue;
}

ChannelTypeUID channelTypeUID = UidUtils.generateChannelTypeUID(dp);
ChannelType channelType = channelTypeProvider.getInternalChannelType(channelTypeUID);
if (channelType == null) {
channelType = HomematicTypeGeneratorImpl.createChannelType(dp, channelTypeUID);
channelTypeProvider.addChannelType(channelType);
}

Channel thingChannel = ChannelBuilder.create(channelUID, MetadataUtils.getItemType(dp))
.withLabel(MetadataUtils.getLabel(dp))
.withDescription(MetadataUtils.getDatapointDescription(dp)).withType(channelType.getUID())
.build();
thingChannels.add(thingChannel);

logger.debug(
"Updated value datapoints for channel {} of device '{}' (function {}), now has {} datapoints",
channel, channel.getDevice().getAddress(), channel.getCurrentFunction(),
channel.getDatapoints().size());
}
}
channelsChanged = true;
}

if (updateDynamicChannelList(device, thingChannels)) {
channelsChanged = true;
}

if (channelsChanged) {
updateThing(editThing().withChannels(thingChannels).build());
}

Expand Down

0 comments on commit 2b8a18f

Please sign in to comment.