[homematic] Fix UI enumeration of HM-MOD-EM-8 channels (#10907)

The set of available HM-MOD-EM-8 channels varies depending on the
function a given channel is configured to use, which is why for those
devices we can't determine a static ThingType, but instead must populate
the thing channels on initialization. The existing code already handled
that case, but missed registering channel types for the dynamically
generated channels, which is why those channels were not shown in main
UI.

Signed-off-by: Danny Baumann <dannybaumann@web.de>
This commit is contained in:
maniac103
2021-07-17 23:33:08 +02:00
committed by GitHub
parent f7331d366e
commit d8aacd86a0
3 changed files with 21 additions and 5 deletions

View File

@@ -41,6 +41,7 @@ import org.openhab.binding.homematic.internal.model.HmDatapointConfig;
import org.openhab.binding.homematic.internal.model.HmDatapointInfo;
import org.openhab.binding.homematic.internal.model.HmDevice;
import org.openhab.binding.homematic.internal.model.HmParamsetType;
import org.openhab.binding.homematic.internal.type.HomematicChannelTypeProvider;
import org.openhab.binding.homematic.internal.type.HomematicTypeGeneratorImpl;
import org.openhab.binding.homematic.internal.type.MetadataUtils;
import org.openhab.binding.homematic.internal.type.UidUtils;
@@ -57,6 +58,8 @@ import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.type.ChannelType;
import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
@@ -70,12 +73,14 @@ import org.slf4j.LoggerFactory;
*/
public class HomematicThingHandler extends BaseThingHandler {
private final Logger logger = LoggerFactory.getLogger(HomematicThingHandler.class);
private final HomematicChannelTypeProvider channelTypeProvider;
private Future<?> initFuture;
private final Object initLock = new Object();
private volatile boolean deviceDeletionPending = false;
public HomematicThingHandler(Thing thing) {
public HomematicThingHandler(Thing thing, HomematicChannelTypeProvider channelTypeProvider) {
super(thing);
this.channelTypeProvider = channelTypeProvider;
}
@Override
@@ -196,10 +201,17 @@ public class HomematicThingHandler extends BaseThingHandler {
Map<String, String> channelProps = new HashMap<>();
channelProps.put(propertyName, expectedFunction);
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))
.withProperties(channelProps).withLabel(MetadataUtils.getLabel(dp))
.withDescription(MetadataUtils.getDatapointDescription(dp))
.withType(UidUtils.generateChannelTypeUID(dp)).build();
.withDescription(MetadataUtils.getDatapointDescription(dp)).withType(channelType.getUID())
.build();
thingChannels.add(thingChannel);
changed = true;
}

View File

@@ -17,6 +17,7 @@ import static org.openhab.binding.homematic.internal.HomematicBindingConstants.*
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.openhab.binding.homematic.internal.type.HomematicChannelTypeProvider;
import org.openhab.binding.homematic.internal.type.HomematicTypeGenerator;
import org.openhab.core.io.net.http.HttpClientFactory;
import org.openhab.core.net.NetworkAddressService;
@@ -40,13 +41,16 @@ import org.osgi.service.component.annotations.Reference;
public class HomematicThingHandlerFactory extends BaseThingHandlerFactory {
private final HomematicTypeGenerator typeGenerator;
private final HomematicChannelTypeProvider channelTypeProvider;
private final NetworkAddressService networkAddressService;
private final HttpClient httpClient;
@Activate
public HomematicThingHandlerFactory(@Reference HomematicTypeGenerator typeGenerator,
@Reference HomematicChannelTypeProvider channelTypeProvider,
@Reference NetworkAddressService networkAddressService, @Reference HttpClientFactory httpClientFactory) {
this.typeGenerator = typeGenerator;
this.channelTypeProvider = channelTypeProvider;
this.networkAddressService = networkAddressService;
this.httpClient = httpClientFactory.getCommonHttpClient();
}
@@ -62,7 +66,7 @@ public class HomematicThingHandlerFactory extends BaseThingHandlerFactory {
return new HomematicBridgeHandler((Bridge) thing, typeGenerator,
networkAddressService.getPrimaryIpv4HostAddress(), httpClient);
} else {
return new HomematicThingHandler(thing);
return new HomematicThingHandler(thing, channelTypeProvider);
}
}
}

View File

@@ -250,7 +250,7 @@ public class HomematicTypeGeneratorImpl implements HomematicTypeGenerator {
/**
* Creates the ChannelType for the given datapoint.
*/
private ChannelType createChannelType(HmDatapoint dp, ChannelTypeUID channelTypeUID) {
public static ChannelType createChannelType(HmDatapoint dp, ChannelTypeUID channelTypeUID) {
ChannelType channelType;
if (dp.getName().equals(DATAPOINT_NAME_LOWBAT) || dp.getName().equals(DATAPOINT_NAME_LOWBAT_IP)) {
channelType = DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_LOW_BATTERY;