I started working on new bacent binding and I have dynamic list of channels. Bacnet is quite abstract, there is network, device and it's properties. I mapped network to bridge, device to thing and properties to channels. I'm not sure if I've done that properly cause I fetch bacnet device properties when related ThingHandler.bridgeHandlerInitialized method is called.
In same method I start thread which fetch present values and post channel updates, but these are ignored:
2016-07-05 10:50:26.673 [DEBUG] [home.core.internal.items.ItemUpdater] - Received update for non-existing item: Item 'bacnet_device_2251_0_ANALOG_VALUE_34' could not be found in the item registry
(gist with same code https://gist.github.com/splatch/657492703d452aab5214005552077cfc)
@Override
public void bridgeHandlerInitialized(ThingHandler thingHandler, Bridge bridge) {
if (thingHandler instanceof BacNetBridgeHandler) {
this.client = ((BacNetBridgeHandler) thingHandler).getClient();
BacNetDeviceConfiguration configuration = getConfigAs(BacNetDeviceConfiguration.class);
// hardcode network number temporary to 0
this.device = new Device(configuration.id, configuration.ip, configuration.port, 0);
final List<Property> deviceProperties = client.getDeviceProperties(device);
List<Channel> channels = new ArrayList<>();
for (Property property : deviceProperties) {
ChannelUID channelUID = new ChannelUID(getThing().getUID(),
property.getType().name() + "#" + property.getId());
ChannelBuilder builder = null;
switch (property.getType()) {
case ANALOG_INPUT:
builder = ChannelBuilder.create(channelUID, BacNetBindingConstants.CHANNEL_ANALOG_INPUT);
break;
case ANALOG_OUTPUT:
builder = ChannelBuilder.create(channelUID, BacNetBindingConstants.CHANNEL_ANALOG_OUTPUT);
break;
case ANALOG_VALUE:
builder = ChannelBuilder.create(channelUID, BacNetBindingConstants.CHANNEL_ANALOG_VALUE);
break;
case BINARY_VALUE:
builder = ChannelBuilder.create(channelUID, BacNetBindingConstants.CHANNEL_BINARY_VALUE);
break;
case BINARY_OUTPUT:
builder = ChannelBuilder.create(channelUID, BacNetBindingConstants.CHANNEL_BINARY_OUTPUT);
break;
}
if (builder == null) {
logger.warn("Unsupported type of property {}", property.getType());
continue;
}
builder.withLabel(property.getName()).withDescription(property.getDescription())
.withProperties(ImmutableMap.of("id", Integer.toString(property.getId())));
channels.add(builder.build());
}
ThingBuilder thingBuilder = editThing().withChannels(channels);
updateThing(thingBuilder.build());
updateStatus(ThingStatus.ONLINE);
executor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
for (Property<?, Object> property : deviceProperties) {
String uid = property.getType().name() + "#" + property.getId();
// if (isLinked(uid.getAsString())) {
Object value = client.getPropertyValue(property);
if (value instanceof Integer) {
updateState(uid, new DecimalType((Integer) value));
} else if (value instanceof Boolean) {
updateState(uid, ((Boolean) value) ? OnOffType.ON : OnOffType.OFF);
} else if (value instanceof Float) {
updateState(uid, new DecimalType((Float) value));
} else {
logger.info("Unsupported return type {} for property {}", value, property);
}
}
}
}, 0, 30, TimeUnit.SECONDS);
}
}
Do I miss anything in my code to get linking done? In GUI these channels are displayed properly: