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;
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;
*/
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
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;
}
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;
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();
}
return new HomematicBridgeHandler((Bridge) thing, typeGenerator,
networkAddressService.getPrimaryIpv4HostAddress(), httpClient);
} else {
- return new HomematicThingHandler(thing);
+ return new HomematicThingHandler(thing, channelTypeProvider);
}
}
}