[Homematic] Fix "Channel not found for Datapoint"-Errors (#11493)

Signed-off-by: Flole <flole@flole.de>
This commit is contained in:
Flole998 2021-12-11 17:02:27 +01:00 committed by GitHub
parent 374a89a9fb
commit 145bd0ec97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -147,10 +147,52 @@ public class HomematicThingHandler extends BaseThingHandler {
}
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());
}