Search in sources :

Example 1 with ThingBuilder

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

the class ThingBuilderTest method testWithChannel_wrongThing.

@Test(expected = IllegalArgumentException.class)
public void testWithChannel_wrongThing() {
    ThingBuilder thingBuilder = ThingBuilder.create(THING_TYPE_UID, THING_UID);
    thingBuilder.withChannel(ChannelBuilder.create(new ChannelUID(new ThingUID(THING_TYPE_UID, "wrong"), "channel1"), "").build());
}
Also used : ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Test(org.junit.Test)

Example 2 with ThingBuilder

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

the class ThingBuilderTest method testWithChannels_duplicatesCollections.

@Test(expected = IllegalArgumentException.class)
public void testWithChannels_duplicatesCollections() {
    ThingBuilder thingBuilder = ThingBuilder.create(THING_TYPE_UID, THING_UID);
    thingBuilder.withChannels(// 
    Arrays.asList(// 
    ChannelBuilder.create(new ChannelUID(THING_UID, "channel1"), "").build(), ChannelBuilder.create(new ChannelUID(THING_UID, "channel1"), "").build()));
}
Also used : ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Test(org.junit.Test)

Example 3 with ThingBuilder

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

the class ThingBuilderTest method testWithChannels_duplicatesVararg.

@Test(expected = IllegalArgumentException.class)
public void testWithChannels_duplicatesVararg() {
    ThingBuilder thingBuilder = ThingBuilder.create(THING_TYPE_UID, THING_UID);
    // 
    thingBuilder.withChannels(// 
    ChannelBuilder.create(new ChannelUID(THING_UID, "channel1"), "").build(), ChannelBuilder.create(new ChannelUID(THING_UID, "channel1"), "").build());
}
Also used : ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Test(org.junit.Test)

Example 4 with ThingBuilder

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

the class DeviceHandler method checkSensorChannel.

private void checkSensorChannel() {
    List<Channel> channelList = new LinkedList<Channel>(this.getThing().getChannels());
    boolean channelListChanged = false;
    // if sensor channels with priority never are loaded delete these channels
    if (!channelList.isEmpty()) {
        Iterator<Channel> channelInter = channelList.iterator();
        while (channelInter.hasNext()) {
            Channel channel = channelInter.next();
            String channelID = channel.getUID().getId();
            if (channelID.startsWith(DsChannelTypeProvider.BINARY_INPUT_PRE)) {
                DeviceBinarayInputEnum devBinInput = getBinaryInput(channelID);
                if (device.getBinaryInput(devBinInput) != null) {
                    addLoadedSensorChannel(channelID);
                } else {
                    logger.debug("remove {} binary input channel", channelID);
                    channelInter.remove();
                    channelListChanged = removeLoadedSensorChannel(channelID);
                }
            } else {
                SensorEnum sensorType = getSensorEnum(channelID);
                if (sensorType != null) {
                    if (SensorEnum.isPowerSensor(sensorType)) {
                        if (device.checkPowerSensorRefreshPriorityNever(sensorType)) {
                            logger.debug("remove {} sensor channel", channelID);
                            channelInter.remove();
                            channelListChanged = removeLoadedSensorChannel(channelID);
                        } else {
                            addLoadedSensorChannel(channelID);
                        }
                    } else {
                        if (device.supportsSensorType(sensorType)) {
                            addLoadedSensorChannel(channelID);
                        } else {
                            logger.debug("remove {} sensor channel", channelID);
                            channelInter.remove();
                            removeLoadedSensorChannel(channelID);
                            channelListChanged = true;
                        }
                    }
                }
            }
        }
    }
    for (SensorEnum sensorType : device.getPowerSensorTypes()) {
        if (!device.checkPowerSensorRefreshPriorityNever(sensorType) && !isSensorChannelLoaded(getSensorChannelID(sensorType))) {
            logger.debug("create {} sensor channel", sensorType.toString());
            channelList.add(getSensorChannel(sensorType));
            channelListChanged = addLoadedSensorChannel(getSensorChannelID(sensorType));
        }
    }
    if (device.hasClimateSensors()) {
        for (SensorEnum sensorType : device.getClimateSensorTypes()) {
            if (!isSensorChannelLoaded(getSensorChannelID(sensorType))) {
                logger.debug("create {} sensor channel", sensorType.toString());
                channelList.add(getSensorChannel(sensorType));
                channelListChanged = addLoadedSensorChannel(getSensorChannelID(sensorType));
            }
        }
    }
    if (device.isBinaryInputDevice()) {
        for (DeviceBinaryInput binInput : device.getBinaryInputs()) {
            DeviceBinarayInputEnum binInputType = DeviceBinarayInputEnum.getdeviceBinarayInput(binInput.getInputType());
            if (binInputType != null && !isSensorChannelLoaded(getBinaryInputChannelID(binInputType))) {
                logger.debug("create {} sensor channel", binInputType.toString());
                channelList.add(getBinaryChannel(binInputType));
                channelListChanged = addLoadedSensorChannel(getBinaryInputChannelID(binInputType));
            }
        }
    }
    if (channelListChanged) {
        logger.debug("load new channel list");
        ThingBuilder thingBuilder = editThing();
        thingBuilder.withChannels(channelList);
        updateThing(thingBuilder.build());
    }
}
Also used : ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) DeviceBinaryInput(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceBinaryInput) SensorEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum) DeviceBinarayInputEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.DeviceBinarayInputEnum) Channel(org.eclipse.smarthome.core.thing.Channel) LinkedList(java.util.LinkedList)

Example 5 with ThingBuilder

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

the class ZoneTemperatureControlHandler method loadChannel.

private synchronized void loadChannel() {
    List<Channel> newChannelList = new ArrayList<Channel>(1);
    if (currentChannelID != null) {
        newChannelList.add(ChannelBuilder.create(new ChannelUID(this.getThing().getUID(), currentChannelID), DsChannelTypeProvider.getItemType(currentChannelID)).withType(new ChannelTypeUID(BINDING_ID, currentChannelID)).build());
    }
    ThingBuilder thingBuilder = editThing();
    thingBuilder.withChannels(newChannelList);
    updateThing(thingBuilder.build());
    logger.debug("load channel: {} with item: {}", currentChannelID, DsChannelTypeProvider.getItemType(currentChannelID));
}
Also used : ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) ArrayList(java.util.ArrayList)

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