Search in sources :

Example 16 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class BoseSoundTouchHandler method refreshPresetChannel.

public void refreshPresetChannel() {
    List<StateOption> stateOptions = presetContainer.getAllPresets().stream().map(e -> e.toStateOption()).sorted(Comparator.comparing(StateOption::getValue)).collect(Collectors.toList());
    stateOptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_PRESET), stateOptions);
}
Also used : ChannelUID(org.openhab.core.thing.ChannelUID) StateOption(org.openhab.core.types.StateOption)

Example 17 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class LxControlTest method testChannel.

void testChannel(LxControl ctrl, String itemType, String namePostFix, BigDecimal min, BigDecimal max, BigDecimal step, String format, Boolean readOnly, List<StateOption> options, Set<String> tags) {
    assertNotNull(ctrl);
    Channel c = getChannel(getExpectedName(ctrl.getLabel(), ctrl.getRoom().getName(), namePostFix), ctrl);
    assertNotNull(c);
    assertNotNull(c.getUID());
    assertNotNull(c.getDescription());
    assertEquals(itemType, c.getAcceptedItemType());
    assertEquals(ChannelKind.STATE, c.getKind());
    StateDescription d = handler.stateDescriptions.get(c.getUID());
    if (readOnly != null || min != null || max != null || step != null || format != null || options != null) {
        assertNotNull(d);
        assertEquals(min, d.getMinimum());
        assertEquals(max, d.getMaximum());
        assertEquals(step, d.getStep());
        assertEquals(format, d.getPattern());
        assertEquals(readOnly, d.isReadOnly());
        List<StateOption> opts = d.getOptions();
        if (options == null) {
            assertTrue(opts.isEmpty());
        } else {
            assertNotNull(opts);
            assertEquals(options.size(), opts.size());
            options.forEach(o -> {
                String label = o.getLabel();
                long num = opts.stream().filter(f -> label != null && label.equals(f.getLabel()) && o.getValue().equals(f.getValue())).collect(Collectors.counting());
                assertEquals(1, num);
            });
        }
    } else {
        assertNull(d);
    }
    if (tags != null) {
        assertThat(c.getDefaultTags(), hasItems(tags.toArray(new String[0])));
    } else {
        assertThat(c.getDefaultTags(), empty());
    }
}
Also used : LxContainer(org.openhab.binding.loxone.internal.types.LxContainer) LxUuid(org.openhab.binding.loxone.internal.types.LxUuid) Command(org.openhab.core.types.Command) Collection(java.util.Collection) State(org.openhab.core.types.State) Matchers(org.hamcrest.Matchers) Set(java.util.Set) StateDescription(org.openhab.core.types.StateDescription) IOException(java.io.IOException) StateOption(org.openhab.core.types.StateOption) Collectors(java.util.stream.Collectors) BigDecimal(java.math.BigDecimal) Channel(org.openhab.core.thing.Channel) List(java.util.List) Type(java.lang.reflect.Type) ChannelKind(org.openhab.core.thing.type.ChannelKind) Map(java.util.Map) LxState(org.openhab.binding.loxone.internal.types.LxState) Assertions(org.junit.jupiter.api.Assertions) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LxCategory(org.openhab.binding.loxone.internal.types.LxCategory) Channel(org.openhab.core.thing.Channel) StateOption(org.openhab.core.types.StateOption) StateDescription(org.openhab.core.types.StateDescription)

Example 18 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class LxControlLightControllerV2Test method loadMoodList1.

private void loadMoodList1() {
    String list = loadMoodList("MoodList1.json");
    changeLoxoneState("moodlist", list);
    List<StateOption> options = new ArrayList<>();
    options.add(new StateOption("2", "Side Lights"));
    options.add(new StateOption("3", "Play Lights"));
    options.add(new StateOption("4", "Study Only"));
    options.add(new StateOption("5", "Low Lights"));
    options.add(new StateOption("777", "Bright"));
    options.add(new StateOption("778", "Off"));
    testMoodList(options, 778);
}
Also used : ArrayList(java.util.ArrayList) StateOption(org.openhab.core.types.StateOption)

Example 19 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class LxControlRadioTest2 method testChannels.

@Override
@Test
public void testChannels() {
    List<StateOption> opts = new ArrayList<>();
    for (Integer i = 1; i <= 6; i++) {
        opts.add(new StateOption(i.toString(), "Sprinkler " + i.toString()));
    }
    opts.add(new StateOption("0", "All Off"));
    testChannel("Number", null, BigDecimal.ZERO, new BigDecimal(16), BigDecimal.ONE, null, false, opts);
}
Also used : ArrayList(java.util.ArrayList) StateOption(org.openhab.core.types.StateOption) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 20 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class LxControlLightControllerV2Test method testMoodList.

private void testMoodList(List<StateOption> options, Integer offId) {
    assertEquals(options.size(), handler.extraControls.size());
    if (options.isEmpty()) {
        return;
    }
    Integer min = null;
    Integer max = null;
    for (StateOption o : options) {
        testMood(o.getLabel(), o.getValue(), o.getValue().equals(offId.toString()));
        Integer id = Integer.parseInt(o.getValue());
        assertNotNull(id);
        if (min == null || id < min) {
            min = id;
        }
        if (max == null || id > max) {
            max = id;
        }
    }
    assertNotNull(min);
    assertNotNull(max);
    testChannel("Number", null, new BigDecimal(min), new BigDecimal(max), BigDecimal.ONE, null, false, options, Collections.singleton("Scene"));
}
Also used : StateOption(org.openhab.core.types.StateOption) BigDecimal(java.math.BigDecimal)

Aggregations

StateOption (org.openhab.core.types.StateOption)109 ArrayList (java.util.ArrayList)68 ChannelUID (org.openhab.core.thing.ChannelUID)45 BigDecimal (java.math.BigDecimal)22 Test (org.junit.jupiter.api.Test)20 List (java.util.List)17 Nullable (org.eclipse.jdt.annotation.Nullable)17 Channel (org.openhab.core.thing.Channel)17 ChannelTypeUID (org.openhab.core.thing.type.ChannelTypeUID)16 StateDescription (org.openhab.core.types.StateDescription)16 StringType (org.openhab.core.library.types.StringType)14 StateDescriptionFragmentBuilder (org.openhab.core.types.StateDescriptionFragmentBuilder)13 Map (java.util.Map)11 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)11 StateDescriptionFragment (org.openhab.core.types.StateDescriptionFragment)11 Thing (org.openhab.core.thing.Thing)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 Collectors (java.util.stream.Collectors)9 OnOffType (org.openhab.core.library.types.OnOffType)8