Search in sources :

Example 11 with ThingBuilder

use of org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder in project smarthome by eclipse.

the class ConnectedBluetoothHandler method activateChannel.

protected void activateChannel(@Nullable BluetoothCharacteristic characteristic, ChannelTypeUID channelTypeUID, @Nullable String name) {
    if (characteristic != null) {
        String channelId = name != null ? name : characteristic.getGattCharacteristic().name();
        if (channelId == null) {
            // use the type id as a fallback
            channelId = channelTypeUID.getId();
        }
        if (getThing().getChannel(channelId) == null) {
            // the channel does not exist yet, so let's add it
            ThingBuilder updatedThing = editThing();
            Channel channel = ChannelBuilder.create(new ChannelUID(getThing().getUID(), channelId), "Number").withType(channelTypeUID).build();
            updatedThing.withChannel(channel);
            updateThing(updatedThing.build());
            logger.debug("Added channel '{}' to Thing '{}'", channelId, getThing().getUID());
        }
        deviceCharacteristics.add(characteristic);
        device.enableNotifications(characteristic);
        if (isLinked(channelId)) {
            device.readCharacteristic(characteristic);
        }
    } else {
        logger.debug("Characteristic is null - not activating any channel.");
    }
}
Also used : ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel)

Aggregations

ThingBuilder (org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder)11 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)9 Test (org.junit.Test)6 Channel (org.eclipse.smarthome.core.thing.Channel)4 LinkedList (java.util.LinkedList)2 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)2 ArrayList (java.util.ArrayList)1 DeviceBinarayInputEnum (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.DeviceBinarayInputEnum)1 SensorEnum (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum)1 DeviceBinaryInput (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceBinaryInput)1 Configuration (org.eclipse.smarthome.config.core.Configuration)1 Bridge (org.eclipse.smarthome.core.thing.Bridge)1 Thing (org.eclipse.smarthome.core.thing.Thing)1 ChannelDTO (org.eclipse.smarthome.core.thing.dto.ChannelDTO)1 BridgeImpl (org.eclipse.smarthome.core.thing.internal.BridgeImpl)1 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)1