Search in sources :

Example 56 with ChannelUID

use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.

the class ColorThingHandler method dispose.

@Override
public void dispose() {
    if (channels.size() != 0) {
        channels.get(0).removeListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_R));
        channels.get(1).removeListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_G));
        channels.get(2).removeListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_B));
    }
    channels.clear();
    currentValues.clear();
    currentColor = new HSBType();
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) HSBType(org.eclipse.smarthome.core.library.types.HSBType)

Example 57 with ChannelUID

use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.

the class DimmerThingHandler method dispose.

@Override
public void dispose() {
    if (channels.size() != 0) {
        channels.get(0).removeListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS));
        Bridge bridge = getBridge();
        if (bridge != null) {
            DmxBridgeHandler bridgeHandler = (DmxBridgeHandler) bridge.getHandler();
            if (bridgeHandler != null) {
                bridgeHandler.unregisterDmxChannels(this.thing);
                logger.debug("removing {} channels from {}", channels.size(), this.thing.getUID());
            }
        }
        channels.clear();
    }
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) DmxBridgeHandler(org.eclipse.smarthome.binding.dmx.internal.DmxBridgeHandler) Bridge(org.eclipse.smarthome.core.thing.Bridge)

Example 58 with ChannelUID

use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.

the class DimmerThingHandler method initialize.

@Override
public void initialize() {
    Configuration configuration = getConfig();
    Bridge bridge = getBridge();
    DmxBridgeHandler bridgeHandler;
    if (bridge == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "no bridge assigned");
        dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
        return;
    } else {
        bridgeHandler = (DmxBridgeHandler) bridge.getHandler();
        if (bridgeHandler == null) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "no bridge handler available");
            dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
            return;
        }
    }
    if (configuration.get(CONFIG_DMX_ID) == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "DMX channel configuration missing");
        dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
        return;
    }
    try {
        List<BaseDmxChannel> configChannels = BaseDmxChannel.fromString((String) configuration.get(CONFIG_DMX_ID), bridgeHandler.getUniverseId());
        logger.trace("found {} channels in {}", configChannels.size(), this.thing.getUID());
        for (BaseDmxChannel channel : configChannels) {
            channels.add(bridgeHandler.getDmxChannel(channel, this.thing));
        }
    } catch (IllegalArgumentException e) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
        dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
        return;
    }
    if (configuration.get(CONFIG_DIMMER_FADE_TIME) != null) {
        fadeTime = ((BigDecimal) configuration.get(CONFIG_DIMMER_FADE_TIME)).intValue();
        logger.debug("setting fadeTime to {} ms in {}", fadeTime, this.thing.getUID());
    }
    if (configuration.get(CONFIG_DIMMER_DIM_TIME) != null) {
        dimTime = ((BigDecimal) configuration.get(CONFIG_DIMMER_DIM_TIME)).intValue();
        logger.trace("setting dimTime to {} ms in {}", fadeTime, this.thing.getUID());
    }
    if (configuration.get(CONFIG_DIMMER_TURNONVALUE) != null) {
        String turnOnValueString = String.valueOf(fadeTime) + ":" + ((String) configuration.get(CONFIG_DIMMER_TURNONVALUE)) + ":-1";
        ValueSet turnOnValue = ValueSet.fromString(turnOnValueString);
        if (!turnOnValue.isEmpty()) {
            this.turnOnValue = turnOnValue;
            logger.trace("set turnonvalue to {} in {}", turnOnValue, this.thing.getUID());
        } else {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "turn-on value malformed");
            dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
            return;
        }
    }
    this.turnOnValue.setFadeTime(fadeTime);
    if (configuration.get(CONFIG_DIMMER_TURNOFFVALUE) != null) {
        String turnOffValueString = String.valueOf(fadeTime) + ":" + ((String) configuration.get(CONFIG_DIMMER_TURNOFFVALUE)) + ":-1";
        ValueSet turnOffValue = ValueSet.fromString(turnOffValueString);
        if (!turnOffValue.isEmpty()) {
            this.turnOffValue = turnOffValue;
            logger.trace("set turnoffvalue to {} in {}", turnOffValue, this.thing.getUID());
        } else {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "turn-off value malformed");
            dmxHandlerStatus = ThingStatusDetail.CONFIGURATION_ERROR;
            return;
        }
    }
    this.turnOffValue.setFadeTime(fadeTime);
    // register feedback listener
    channels.get(0).addListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS), this, ListenerType.VALUE);
    if (bridge.getStatus().equals(ThingStatus.ONLINE)) {
        updateStatus(ThingStatus.ONLINE);
        dmxHandlerStatus = ThingStatusDetail.NONE;
    } else {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
    }
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) BaseDmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) DmxBridgeHandler(org.eclipse.smarthome.binding.dmx.internal.DmxBridgeHandler) ValueSet(org.eclipse.smarthome.binding.dmx.internal.ValueSet) Bridge(org.eclipse.smarthome.core.thing.Bridge)

Example 59 with ChannelUID

use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.

the class TunableWhiteThingHandler method dispose.

@Override
public void dispose() {
    if (channels.size() != 0) {
        channels.get(0).removeListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_CW));
        channels.get(1).removeListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_WW));
    }
    Bridge bridge = getBridge();
    if (bridge != null) {
        DmxBridgeHandler bridgeHandler = (DmxBridgeHandler) bridge.getHandler();
        if (bridgeHandler != null) {
            bridgeHandler.unregisterDmxChannels(this.thing);
            logger.debug("removing {} channels from {}", channels.size(), this.thing.getUID());
        }
    }
    channels.clear();
    currentValues.clear();
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) DmxBridgeHandler(org.eclipse.smarthome.binding.dmx.internal.DmxBridgeHandler) Bridge(org.eclipse.smarthome.core.thing.Bridge)

Example 60 with ChannelUID

use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.

the class ChaserThingHandlerTest method runningChaser.

@Test
public void runningChaser() {
    initializeTestBridge();
    thingProperties.put(CONFIG_CHASER_STEPS, TEST_STEPS_REPEAT);
    initialize();
    long currentTime = System.currentTimeMillis();
    chaserThingHandler.handleCommand(new ChannelUID(chaserThing.getUID(), CHANNEL_SWITCH), OnOffType.ON);
    // step I
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, 1000);
    waitForAssert(() -> assertThat(dmxBridgeHandler.getDmxChannelValue(100), is(equalTo(115))));
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, 1000);
    waitForAssert(() -> assertThat(dmxBridgeHandler.getDmxChannelValue(100), is(equalTo(115))));
    // step II
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, 1000);
    waitForAssert(() -> assertThat(dmxBridgeHandler.getDmxChannelValue(100), is(equalTo(210))));
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, 1000);
    waitForAssert(() -> assertThat(dmxBridgeHandler.getDmxChannelValue(100), is(equalTo(210))));
    // step I (repeated)
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, 1000);
    waitForAssert(() -> assertThat(dmxBridgeHandler.getDmxChannelValue(100), is(equalTo(115))));
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, 1000);
    waitForAssert(() -> assertThat(dmxBridgeHandler.getDmxChannelValue(100), is(equalTo(115))));
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Test(org.junit.Test)

Aggregations

ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)69 Test (org.junit.Test)31 Thing (org.eclipse.smarthome.core.thing.Thing)24 Channel (org.eclipse.smarthome.core.thing.Channel)16 JavaTest (org.eclipse.smarthome.test.java.JavaTest)14 Configuration (org.eclipse.smarthome.config.core.Configuration)10 Bridge (org.eclipse.smarthome.core.thing.Bridge)9 ThingBuilder (org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder)9 Item (org.eclipse.smarthome.core.items.Item)7 Command (org.eclipse.smarthome.core.types.Command)7 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)7 DmxBridgeHandler (org.eclipse.smarthome.binding.dmx.internal.DmxBridgeHandler)6 StringItem (org.eclipse.smarthome.core.library.items.StringItem)6 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)6 BaseThingHandler (org.eclipse.smarthome.core.thing.binding.BaseThingHandler)6 ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)6 ItemChannelLink (org.eclipse.smarthome.core.thing.link.ItemChannelLink)6 NonNull (org.eclipse.jdt.annotation.NonNull)5 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)5 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)5