org.eclipse.smarthome.core.library.types.OnOffType Java Examples

The following examples show how to use org.eclipse.smarthome.core.library.types.OnOffType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SonyAudioHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void updatePowerStatus(int zone, boolean power) {
    powerCache[zone].invalidateValue();
    switch (zone) {
        case 0:
            updateState(SonyAudioBindingConstants.CHANNEL_POWER, power ? OnOffType.ON : OnOffType.OFF);
            updateState(SonyAudioBindingConstants.CHANNEL_MASTER_POWER, power ? OnOffType.ON : OnOffType.OFF);
            break;
        case 1:
            updateState(SonyAudioBindingConstants.CHANNEL_ZONE1_POWER, power ? OnOffType.ON : OnOffType.OFF);
            break;
        case 2:
            updateState(SonyAudioBindingConstants.CHANNEL_ZONE2_POWER, power ? OnOffType.ON : OnOffType.OFF);
            break;
        case 3:
            updateState(SonyAudioBindingConstants.CHANNEL_ZONE3_POWER, power ? OnOffType.ON : OnOffType.OFF);
            break;
        case 4:
            updateState(SonyAudioBindingConstants.CHANNEL_ZONE4_POWER, power ? OnOffType.ON : OnOffType.OFF);
            break;
    }
}
 
Example #2
Source File: GenericThingHandlerTests.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void handleCommandUpdateBoolean() {
    OnOffValue value = spy(new OnOffValue("ON", "OFF"));
    ChannelState channelConfig = spy(
            new ChannelState(ChannelConfigBuilder.create("stateTopic", "commandTopic").build(), textChannelUID,
                    value, thingHandler));
    doReturn(channelConfig).when(thingHandler).createChannelState(any(), any(), any());
    thingHandler.initialize();
    thingHandler.connection = connection;

    StringType updateValue = new StringType("ON");
    thingHandler.handleCommand(textChannelUID, updateValue);

    verify(value).update(eq(updateValue));
    assertThat(channelConfig.getCache().getChannelState(), is(OnOffType.ON));
}
 
Example #3
Source File: HeosBridgeHandler.java    From org.openhab.binding.heos with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
    bridgeHandlerdisposalOngoing = false;

    heos.startEventListener();
    heos.startHeartBeat(heartbeatPulse);
    logger.info("HEOS System heart beat started. Pulse time is {}s", heartbeatPulse);
    updateState(CH_ID_DYNGROUPSHAND, OnOffType.ON); // activates dynamic group handling by default

    if (thing.getConfiguration().containsKey(USERNAME) && thing.getConfiguration().containsKey(PASSWORD)) {
        logger.info("Logging in to HEOS account.");
        String name = thing.getConfiguration().get(USERNAME).toString();
        String password = thing.getConfiguration().get(PASSWORD).toString();
        api.logIn(name, password);
    } else {
        logger.warn("Can not log in. Username and Password not set");
    }
}
 
Example #4
Source File: ZonePlayerHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
public void playTrack(Command command) {
    if (command != null && command instanceof DecimalType) {
        try {
            ZonePlayerHandler coordinator = getCoordinatorHandler();

            String trackNumber = String.valueOf(((DecimalType) command).intValue());

            coordinator.setCurrentURI(QUEUE_URI + coordinator.getUDN() + "#0", "");

            // seek the track - warning, we do not check if the tracknumber falls in the boundary of the queue
            coordinator.setPositionTrack(trackNumber);

            // take the system off mute
            coordinator.setMute(OnOffType.OFF);

            // start jammin'
            coordinator.play();
        } catch (IllegalStateException e) {
            logger.debug("Cannot play track ({})", e.getMessage());
        }
    }
}
 
Example #5
Source File: Ffmpeg.java    From IpCamera with Eclipse Public License 2.0 6 votes vote down vote up
public void startConverting() {
    if (!streamRunning.isAlive()) {
        streamRunning = new StreamRunning();
        logger.debug("Starting ffmpeg with this command now:{}", ffmpegCommand);
        streamRunning.start();
        running = true;
        if (format.equals("HLS")) {
            ipCameraHandler.setChannelState(CHANNEL_START_STREAM, OnOffType.valueOf("ON"));
            if (keepAlive > -1) {
                try {
                    Thread.sleep(4500); // Used for on demand HLS to give ffmpeg time to produce the files needed.
                } catch (InterruptedException e) {
                }
            }
        }
    }
    if (keepAlive != -1) {
        keepAlive = 60;
    }
}
 
Example #6
Source File: DS2423Test.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void counterChannelTest() {
    instantiateDevice();

    List<State> returnValue = new ArrayList<>();
    returnValue.add(new DecimalType(1408));
    returnValue.add(new DecimalType(3105));

    try {
        Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
        Mockito.when(mockBridgeHandler.readDecimalTypeArray(eq(testSensorId), any())).thenReturn(returnValue);

        testDevice.configureChannels();
        testDevice.refresh(mockBridgeHandler, true);

        inOrder.verify(mockBridgeHandler, times(1)).readDecimalTypeArray(eq(testSensorId), any());
        inOrder.verify(mockThingHandler).postUpdate(eq(channelName(0)), eq(returnValue.get(0)));
        inOrder.verify(mockThingHandler).postUpdate(eq(channelName(1)), eq(returnValue.get(1)));
    } catch (OwException e) {
        Assert.fail("caught unexpected OwException");
    }
}
 
Example #7
Source File: ZonePlayerHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
public void setLed(Command command) {
    if (command != null) {
        if (command instanceof OnOffType || command instanceof OpenClosedType || command instanceof UpDownType) {
            Map<String, String> inputs = new HashMap<String, String>();

            if (command.equals(OnOffType.ON) || command.equals(UpDownType.UP)
                    || command.equals(OpenClosedType.OPEN)) {
                inputs.put("DesiredLEDState", "On");
            } else if (command.equals(OnOffType.OFF) || command.equals(UpDownType.DOWN)
                    || command.equals(OpenClosedType.CLOSED)) {
                inputs.put("DesiredLEDState", "Off");
            }

            Map<String, String> result = service.invokeAction(this, "DeviceProperties", "SetLEDState", inputs);
            Map<String, String> result2 = service.invokeAction(this, "DeviceProperties", "GetLEDState", null);

            result.putAll(result2);

            for (String variable : result.keySet()) {
                this.onValueReceived(variable, result.get(variable), "DeviceProperties");
            }
        }
    }
}
 
Example #8
Source File: TradfriLightHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void handleColorCommand(Command command) {
    if (command instanceof HSBType) {
        setColor((HSBType) command);
        setBrightness(((HSBType) command).getBrightness());
    } else if (command instanceof OnOffType) {
        setState(((OnOffType) command));
    } else if (command instanceof PercentType) {
        // PaperUI sends PercentType on color channel when changing Brightness
        setBrightness((PercentType) command);
    } else if (command instanceof IncreaseDecreaseType) {
        // increase or decrease only the brightness, but keep color
        if (state != null && state.getBrightness() != null) {
            int current = state.getBrightness().intValue();
            if (IncreaseDecreaseType.INCREASE.equals(command)) {
                setBrightness(new PercentType(Math.min(current + STEP, PercentType.HUNDRED.intValue())));
            } else {
                setBrightness(new PercentType(Math.max(current - STEP, PercentType.ZERO.intValue())));
            }
        } else {
            logger.debug("Cannot handle inc/dec for color as current brightness is not known.");
        }
    } else {
        logger.debug("Can't handle command {} on channel {}", command, CHANNEL_COLOR);
    }
}
 
Example #9
Source File: SceneHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    BridgeHandler dssBridgeHandler = getBridgeHandler();
    if (dssBridgeHandler == null) {
        logger.debug("BridgeHandler not found. Cannot handle command without bridge.");
        return;
    }

    if (channelUID.getId().equals(DigitalSTROMBindingConstants.CHANNEL_ID_SCENE)) {
        if (command instanceof OnOffType) {
            if (OnOffType.ON.equals(command)) {
                this.bridgeHandler.sendSceneComandToDSS(scene, true);
            } else {
                this.bridgeHandler.sendSceneComandToDSS(scene, false);
            }
        }
    } else {
        logger.warn("Command sent to an unknown channel id: {}", channelUID);
    }

}
 
Example #10
Source File: DS1923Test.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void temperatureChannel() {
    instantiateDevice();

    try {
        Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
        Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));

        testDevice.enableChannel(CHANNEL_TEMPERATURE);
        testDevice.configureChannels();
        inOrder.verify(mockThingHandler).getThing();
        testDevice.refresh(mockBridgeHandler, true);

        inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
        inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_TEMPERATURE), eq(new QuantityType<>("10.0 °C")));

        inOrder.verifyNoMoreInteractions();
    } catch (OwException e) {
        Assert.fail("caught unexpected OwException");
    }
}
 
Example #11
Source File: ZonePlayerHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
public void setMute(Command command) {
    if (command != null) {
        if (command instanceof OnOffType || command instanceof OpenClosedType || command instanceof UpDownType) {
            Map<String, String> inputs = new HashMap<String, String>();
            inputs.put("Channel", "Master");

            if (command.equals(OnOffType.ON) || command.equals(UpDownType.UP)
                    || command.equals(OpenClosedType.OPEN)) {
                inputs.put("DesiredMute", "True");
            } else if (command.equals(OnOffType.OFF) || command.equals(UpDownType.DOWN)
                    || command.equals(OpenClosedType.CLOSED)) {
                inputs.put("DesiredMute", "False");
            }

            Map<String, String> result = service.invokeAction(this, "RenderingControl", "SetMute", inputs);

            for (String variable : result.keySet()) {
                this.onValueReceived(variable, result.get(variable), "RenderingControl");
            }
        }
    }
}
 
Example #12
Source File: ItemUIRegistryImplTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void getLabel_groupLabelWithValue() {
    String testLabel = "Label [%d]";

    when(widget.getLabel()).thenReturn(testLabel);
    when(item.getState()).thenReturn(OnOffType.ON);
    when(item.getStateAs(DecimalType.class)).thenReturn(new DecimalType(5));
    String label = uiRegistry.getLabel(widget);
    assertEquals("Label [5]", label);
}
 
Example #13
Source File: DimmerThingHandlerTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDynamicTurnOnValue() {
    long currentTime = System.currentTimeMillis();
    int testValue = 75;

    // turn on with arbitrary value
    dimmerThingHandler.handleCommand(CHANNEL_UID_BRIGHTNESS, new PercentType(testValue));
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, TEST_FADE_TIME);

    waitForAssert(() -> {
        assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS,
                state -> assertThat(((PercentType) state).doubleValue(), is(closeTo(testValue, 1.0))));
    });

    // turn off and hopefully store last value
    dimmerThingHandler.handleCommand(CHANNEL_UID_BRIGHTNESS, OnOffType.OFF);
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, TEST_FADE_TIME);

    waitForAssert(() -> {
        assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS,
                state -> assertEquals(OnOffType.OFF, state.as(OnOffType.class)));
    });

    // turn on and restore value
    dimmerThingHandler.handleCommand(CHANNEL_UID_BRIGHTNESS, OnOffType.ON);
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, TEST_FADE_TIME);

    waitForAssert(() -> {
        assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS,
                state -> assertThat(((PercentType) state).doubleValue(), is(closeTo(testValue, 1.0))));
    });
}
 
Example #14
Source File: SitemapResourceTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void whenGetPageData_ShouldReturnPageBean() throws ItemNotFoundException {
    item.setState(new PercentType(50));
    configureItemUIRegistry(item.getState(), OnOffType.ON);

    // Disable long polling
    when(headers.getRequestHeader(HTTP_HEADER_X_ATMOSPHERE_TRANSPORT)).thenReturn(null);

    Response response = sitemapResource.getPageData(headers, null, SITEMAP_MODEL_NAME, SITEMAP_NAME, null);

    PageDTO pageDTO = (PageDTO) response.getEntity();
    assertThat(pageDTO.id, is(SITEMAP_NAME));
    assertThat(pageDTO.title, is(SITEMAP_TITLE));
    assertThat(pageDTO.leaf, is(true));
    assertThat(pageDTO.timeout, is(false));

    assertThat(pageDTO.widgets, notNullValue());
    assertThat((Collection<?>) pageDTO.widgets, hasSize(2));

    assertThat(pageDTO.widgets.get(0).widgetId, is(WIDGET1_ID));
    assertThat(pageDTO.widgets.get(0).label, is(WIDGET1_LABEL));
    assertThat(pageDTO.widgets.get(0).labelcolor, is("GREEN"));
    assertThat(pageDTO.widgets.get(0).valuecolor, is("BLUE"));
    assertThat(pageDTO.widgets.get(0).state, nullValue());
    assertThat(pageDTO.widgets.get(0).item, notNullValue());
    assertThat(pageDTO.widgets.get(0).item.name, is(ITEM_NAME));
    assertThat(pageDTO.widgets.get(0).item.state, is("50"));

    assertThat(pageDTO.widgets.get(1).widgetId, is(WIDGET2_ID));
    assertThat(pageDTO.widgets.get(1).label, is(WIDGET2_LABEL));
    assertThat(pageDTO.widgets.get(1).labelcolor, nullValue());
    assertThat(pageDTO.widgets.get(1).valuecolor, nullValue());
    assertThat(pageDTO.widgets.get(1).state, is("ON"));
    assertThat(pageDTO.widgets.get(1).item, notNullValue());
    assertThat(pageDTO.widgets.get(1).item.name, is(ITEM_NAME));
    assertThat(pageDTO.widgets.get(1).item.state, is("50"));
}
 
Example #15
Source File: WemoLightHandlerOSGiTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void handleONcommandForBRIGHTNESSchannel()
        throws MalformedURLException, URISyntaxException, ValidationException {
    Command command = OnOffType.ON;
    String channelID = WemoBindingConstants.CHANNEL_BRIGHTNESS;

    // Command ON for this channel sends the following data to the device
    String action = SET_ACTION;
    // ON is equal to brightness value of 255
    String value = "255:0";
    String capitability = "10008";

    assertRequestForCommand(channelID, command, action, value, capitability);
}
 
Example #16
Source File: DigitalIoConfig.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
public State convertState(Boolean rawValue) {
    if (ioLogic == DigitalIoLogic.NORMAL) {
        return rawValue ? OnOffType.ON : OnOffType.OFF;
    } else {
        return rawValue ? OnOffType.OFF : OnOffType.ON;
    }
}
 
Example #17
Source File: GenericItemProvider2Test.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGroupItemChangesBaseItem() {
    GenericItemProvider gip = new GenericItemProvider();

    GroupItem g1 = new GroupItem("testGroup", new SwitchItem("test"),
            new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF));
    GroupItem g2 = new GroupItem("testGroup", new NumberItem("test"),
            new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF));

    assertTrue(gip.hasItemChanged(g1, g2));
}
 
Example #18
Source File: SonyAudioHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
public void handlePowerCommand(Command command, ChannelUID channelUID, int zone) throws IOException {
    if (command instanceof RefreshType) {
        try {
            logger.debug("handlePowerCommand RefreshType {}", zone);
            Boolean result = powerCache[zone].getValue();
            updateState(channelUID, result ? OnOffType.ON : OnOffType.OFF);
        } catch (CompletionException ex) {
            throw new IOException(ex.getCause());
        }
    }
    if (command instanceof OnOffType) {
        logger.debug("handlePowerCommand set {} {}", zone, command);
        connection.setPower(((OnOffType) command) == OnOffType.ON, zone);
    }
}
 
Example #19
Source File: ColorValue.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates a non initialized color value.
 *
 * @param isRGB True if this is an RGB color value instead of a HSB one.
 * @param onValue The ON value string. This will be compared to MQTT messages.
 * @param offValue The OFF value string. This will be compared to MQTT messages.
 * @param onBrightness When receiving a ON command, the brightness percentage is set to this value
 */
public ColorValue(boolean isRGB, @Nullable String onValue, @Nullable String offValue, int onBrightness) {
    super(CoreItemFactory.COLOR,
            Stream.of(OnOffType.class, PercentType.class, StringType.class).collect(Collectors.toList()));

    if (onBrightness > 100) {
        throw new IllegalArgumentException("Brightness parameter must be <= 100");
    }

    this.isRGB = isRGB;
    this.onValue = onValue == null ? "ON" : onValue;
    this.offValue = offValue == null ? "OFF" : offValue;
    this.onBrightness = onBrightness;
}
 
Example #20
Source File: RuleExecutionTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testMemberUpdateEventTrigger() throws Exception {
    String model = "rule Test " + //
            "when " + //
            "    Member of TestGroup received update " + //
            "then " + //
            "    TestResult.send(ON) " + //
            "end ";

    assertExecutionWith(model, ItemEventFactory.createStateEvent("TestSwitch", OnOffType.ON), TriggerTypes.UPDATE);
}
 
Example #21
Source File: DS1923Test.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void humidityChannel() {
    instantiateDevice();

    try {
        Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
        Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));

        testDevice.enableChannel(CHANNEL_HUMIDITY);
        testDevice.enableChannel(CHANNEL_ABSOLUTE_HUMIDITY);
        testDevice.enableChannel(CHANNEL_DEWPOINT);
        testDevice.configureChannels();
        inOrder.verify(mockThingHandler).getThing();
        testDevice.refresh(mockBridgeHandler, true);

        inOrder.verify(mockBridgeHandler, times(2)).readDecimalType(eq(testSensorId), any());
        inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_HUMIDITY), eq(new QuantityType<>("10.0 %")));
        inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_ABSOLUTE_HUMIDITY),
                eq(new QuantityType<>("0.9381970824113001000 g/m³")));
        inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_DEWPOINT),
                eq(new QuantityType<>("-20.31395053870025 °C")));

        inOrder.verifyNoMoreInteractions();
    } catch (OwException e) {
        Assert.fail("caught unexpected OwException");
    }
}
 
Example #22
Source File: HeosChannelHandlerMute.java    From org.openhab.binding.heos with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void handleCommandGroup() {
    if (command.equals(OnOffType.ON)) {
        api.muteGroupON(id);
    } else if (command.equals(OnOffType.OFF)) {
        api.muteGroupOFF(id);
    }
}
 
Example #23
Source File: SystemFollowProfileTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testPostCommand() {
    SystemFollowProfile profile = new SystemFollowProfile(mockCallback);
    profile.onCommandFromHandler(OnOffType.ON);

    verify(mockCallback).sendCommand(eq(OnOffType.ON));
    verifyNoMoreInteractions(mockCallback);
}
 
Example #24
Source File: SystemDefaultProfileTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testOnCommand() {
    SystemDefaultProfile profile = new SystemDefaultProfile(mockCallback);

    profile.onCommandFromItem(OnOffType.ON);

    verify(mockCallback).handleCommand(eq(OnOffType.ON));
    verifyNoMoreInteractions(mockCallback);
}
 
Example #25
Source File: HeosChannelHandlerFavoriteSelect.java    From org.openhab.binding.heos with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void handleCommandBridge() {
    if (command.equals(OnOffType.ON)) {
        ArrayList<String[]> selectedPlayerList = bridge.getSelectedPlayerList();
        if (!selectedPlayerList.isEmpty()) {
            for (int i = 0; i < selectedPlayerList.size(); i++) {
                String pid = selectedPlayerList.get(i)[0];
                String mid = channelUID.getId(); // the channel ID represents the MID of the favorite
                api.playStation(pid, FAVORIT_SID, null, mid, null);
            }
        }
        bridge.resetPlayerList(channelUID);
    }
}
 
Example #26
Source File: HeosChannelHandlerDynGroupHandling.java    From org.openhab.binding.heos with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void handleCommandBridge() {
    if (command.equals(OnOffType.ON)) {
        bridge.setHandleGroups(true);
    } else {
        bridge.setHandleGroups(false);
    }
}
 
Example #27
Source File: IpCameraHandler.java    From IpCamera with Eclipse Public License 2.0 5 votes vote down vote up
void snapshotIsFfmpeg() {
    bringCameraOnline();
    snapshotUri = "";// ffmpeg is a valid option. Simplify further checks.
    if (updateImageEvents.equals("1")) {
        updateImageChannel = false;
        logger.info(
                "Binding has no snapshot url. Using your CPU and FFmpeg (must be manually installed) to create snapshots.");
        ffmpegSnapshotGeneration = true;
        if (!rtspUri.equals("")) {
            setupFfmpegFormat("SNAPSHOT");
            updateState(CHANNEL_UPDATE_IMAGE_NOW, OnOffType.valueOf("ON"));
        }
    }
}
 
Example #28
Source File: ColorThingHandlerTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testOnOffCommand() {
    // on
    long currentTime = System.currentTimeMillis();

    dimmerThingHandler.handleCommand(CHANNEL_UID_COLOR, OnOffType.ON);
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, TEST_FADE_TIME);

    waitForAssert(() -> {
        assertChannelStateUpdate(CHANNEL_UID_COLOR, state -> assertEquals(OnOffType.ON, state.as(OnOffType.class)));
        assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS_R, state -> assertEquals(PercentType.HUNDRED, state));
        assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS_G,
                state -> assertThat(((PercentType) state).doubleValue(), is(closeTo(50.0, 0.5))));
        assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS_B, state -> assertEquals(PercentType.ZERO, state));
    });

    // off
    dimmerThingHandler.handleCommand(CHANNEL_UID_COLOR, OnOffType.OFF);
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, TEST_FADE_TIME);

    waitForAssert(() -> {
        assertChannelStateUpdate(CHANNEL_UID_COLOR,
                state -> assertEquals(OnOffType.OFF, state.as(OnOffType.class)));
        assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS_R, state -> assertEquals(PercentType.ZERO, state));
        assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS_G, state -> assertEquals(PercentType.ZERO, state));
        assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS_B, state -> assertEquals(PercentType.ZERO, state));
    });
}
 
Example #29
Source File: ItemEventFactoryTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testCreateEvent_ItemStateEvent_OnOffType() throws Exception {
    Event event = factory.createEvent(ITEM_STATE_EVENT_TYPE, ITEM_STATE_EVENT_TOPIC, ITEM_STATE_EVENT_PAYLOAD,
            SOURCE);

    assertEquals(ItemStateEvent.class, event.getClass());
    ItemStateEvent itemStateEvent = (ItemStateEvent) event;
    assertEquals(ITEM_STATE_EVENT_TYPE, itemStateEvent.getType());
    assertEquals(ITEM_STATE_EVENT_TOPIC, itemStateEvent.getTopic());
    assertEquals(ITEM_STATE_EVENT_PAYLOAD, itemStateEvent.getPayload());
    assertEquals(ITEM_NAME, itemStateEvent.getItemName());
    assertEquals(SOURCE, itemStateEvent.getSource());
    assertEquals(OnOffType.class, itemStateEvent.getItemState().getClass());
    assertEquals(ITEM_STATE, itemStateEvent.getItemState());
}
 
Example #30
Source File: RawButtonToggleSwitchProfileTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testColorItem() {
    TriggerProfile profile = new RawButtonToggleSwitchProfile(mockCallback);
    verifyAction(profile, UnDefType.NULL, OnOffType.ON);
    verifyAction(profile, HSBType.WHITE, OnOffType.OFF);
    verifyAction(profile, HSBType.BLACK, OnOffType.ON);
    verifyAction(profile, new HSBType("0,50,50"), OnOffType.OFF);
}