[insteon] Rebuild all channels during thing initialization (#18698)

Signed-off-by: Jeremy Setton <jeremy.setton@gmail.com>
pull/18753/head
Jeremy 2025-06-03 16:01:16 -04:00 committed by GitHub
parent 12e472ac9d
commit 1f7183b7fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 15 deletions

View File

@ -42,6 +42,7 @@ import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingStatusInfo; import org.openhab.core.thing.ThingStatusInfo;
import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.thing.binding.ThingHandlerCallback; import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.type.ChannelKind; import org.openhab.core.thing.type.ChannelKind;
import org.openhab.core.thing.type.ChannelTypeUID; import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.types.Command; import org.openhab.core.types.Command;
@ -255,7 +256,8 @@ public abstract class InsteonBaseThingHandler extends BaseThingHandler implement
protected void initializeChannels(Device device) { protected void initializeChannels(Device device) {
DeviceType deviceType = device.getType(); DeviceType deviceType = device.getType();
if (deviceType == null) { ThingHandlerCallback callback = getCallback();
if (deviceType == null || callback == null) {
return; return;
} }
@ -272,13 +274,9 @@ public abstract class InsteonBaseThingHandler extends BaseThingHandler implement
deviceTypeName); deviceTypeName);
} else { } else {
String channelId = featureNameToChannelId(featureName); String channelId = featureNameToChannelId(featureName);
Channel channel = createChannel(channelId); Channel channel = createChannel(channelId, callback);
if (channel != null) { logger.trace("adding channel {}", channel.getUID());
logger.trace("adding channel {}", channel.getUID()); channels.add(channel);
channels.add(channel);
} else {
logger.warn("unable to create channel {} for {}", channelId, deviceTypeName);
}
// add existing custom channels with the same channel type id but different channel id // add existing custom channels with the same channel type id but different channel id
for (Channel customChannel : getCustomChannels(channelId)) { for (Channel customChannel : getCustomChannels(channelId)) {
logger.trace("adding custom channel {}", customChannel.getUID()); logger.trace("adding custom channel {}", customChannel.getUID());
@ -290,16 +288,16 @@ public abstract class InsteonBaseThingHandler extends BaseThingHandler implement
updateThing(editThing().withChannels(channels).build()); updateThing(editThing().withChannels(channels).build());
} }
private @Nullable Channel createChannel(String channelId) { private Channel createChannel(String channelId, ThingHandlerCallback callback) {
ChannelUID channelUID = new ChannelUID(getThing().getUID(), channelId); ChannelUID channelUID = new ChannelUID(getThing().getUID(), channelId);
ChannelTypeUID channelTypeUID = new ChannelTypeUID(BINDING_ID, channelId); ChannelTypeUID channelTypeUID = new ChannelTypeUID(BINDING_ID, channelId);
Channel channel = getThing().getChannel(channelUID); ChannelBuilder channelBuilder = callback.createChannelBuilder(channelUID, channelTypeUID);
ThingHandlerCallback callback = getCallback(); Channel oldChannel = getThing().getChannel(channelUID);
// create channel if not already available if (oldChannel != null) {
if (channel == null && callback != null) { channelBuilder.withConfiguration(oldChannel.getConfiguration());
channel = callback.createChannelBuilder(channelUID, channelTypeUID).build(); channelBuilder.withProperties(oldChannel.getProperties());
} }
return channel; return channelBuilder.build();
} }
private List<Channel> getCustomChannels(String channelId) { private List<Channel> getCustomChannels(String channelId) {