Search in sources :

Example 1 with StateOption

use of org.eclipse.smarthome.core.types.StateOption in project smarthome by eclipse.

the class XmlChannelTypeProvider method createLocalizedChannelState.

private StateDescription createLocalizedChannelState(Bundle bundle, ChannelType channelType, ChannelTypeUID channelTypeUID, Locale locale) {
    StateDescription state = channelType.getState();
    if (state != null) {
        String pattern = this.thingTypeI18nUtil.getChannelStatePattern(bundle, channelTypeUID, state.getPattern(), locale);
        List<StateOption> localizedOptions = new ArrayList<>();
        List<StateOption> options = state.getOptions();
        for (StateOption stateOption : options) {
            String optionLabel = this.thingTypeI18nUtil.getChannelStateOption(bundle, channelTypeUID, stateOption.getValue(), stateOption.getLabel(), locale);
            localizedOptions.add(new StateOption(stateOption.getValue(), optionLabel));
        }
        return new StateDescription(state.getMinimum(), state.getMaximum(), state.getStep(), pattern, state.isReadOnly(), localizedOptions);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) StateOption(org.eclipse.smarthome.core.types.StateOption) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Example 2 with StateOption

use of org.eclipse.smarthome.core.types.StateOption in project smarthome by eclipse.

the class DefaultSystemChannelTypeProvider method createLocalizedChannelState.

private StateDescription createLocalizedChannelState(Bundle bundle, ChannelType channelType, ChannelTypeUID channelTypeUID, Locale locale) {
    StateDescription state = channelType.getState();
    if (state != null) {
        String pattern = thingTypeI18nUtil.getChannelStatePattern(bundle, channelTypeUID, state.getPattern(), locale);
        List<StateOption> localizedOptions = new ArrayList<>();
        List<StateOption> options = state.getOptions();
        for (StateOption stateOption : options) {
            String optionLabel = thingTypeI18nUtil.getChannelStateOption(bundle, channelTypeUID, stateOption.getValue(), stateOption.getLabel(), locale);
            localizedOptions.add(new StateOption(stateOption.getValue(), optionLabel));
        }
        return new StateDescription(state.getMinimum(), state.getMaximum(), state.getStep(), pattern, state.isReadOnly(), localizedOptions);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) StateOption(org.eclipse.smarthome.core.types.StateOption) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Example 3 with StateOption

use of org.eclipse.smarthome.core.types.StateOption in project smarthome by eclipse.

the class ItemUIRegistryImplTest method getLabel_labelWithMappedOption.

@Test
public void getLabel_labelWithMappedOption() throws ItemNotFoundException {
    String testLabel = "Label";
    StateDescription stateDescription = mock(StateDescription.class);
    List<StateOption> options = new ArrayList<>();
    options.add(new StateOption("State0", "This is the state 0"));
    options.add(new StateOption("State1", "This is the state 1"));
    when(widget.getLabel()).thenReturn(testLabel);
    when(item.getStateDescription()).thenReturn(stateDescription);
    when(stateDescription.getPattern()).thenReturn("%s");
    when(stateDescription.getOptions()).thenReturn(options);
    when(item.getState()).thenReturn(new StringType("State1"));
    String label = uiRegistry.getLabel(widget);
    assertEquals("Label [This is the state 1]", label);
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StateOption(org.eclipse.smarthome.core.types.StateOption) StateDescription(org.eclipse.smarthome.core.types.StateDescription) Test(org.junit.Test)

Example 4 with StateOption

use of org.eclipse.smarthome.core.types.StateOption in project smarthome by eclipse.

the class StateDescriptionServiceImpl method getStateDescription.

@Override
@Nullable
public StateDescription getStateDescription(String itemName, Locale locale) {
    StateDescription result = null;
    List<StateOption> stateOptions = Collections.emptyList();
    if (stateDescriptionProviders != null) {
        for (StateDescriptionProvider stateDescriptionProvider : stateDescriptionProviders) {
            StateDescription stateDescription = stateDescriptionProvider.getStateDescription(itemName, locale);
            // as long as no valid StateDescription is provided we reassign here:
            if (result == null) {
                result = stateDescription;
            }
            // here
            if (stateDescription != null && !stateDescription.getOptions().isEmpty() && stateOptions.isEmpty()) {
                stateOptions = stateDescription.getOptions();
            }
        }
    }
    // are given:
    if (result != null && !stateOptions.isEmpty()) {
        result = new StateDescription(result.getMinimum(), result.getMaximum(), result.getStep(), result.getPattern(), result.isReadOnly(), stateOptions);
    }
    return result;
}
Also used : StateDescriptionProvider(org.eclipse.smarthome.core.types.StateDescriptionProvider) StateOption(org.eclipse.smarthome.core.types.StateOption) StateDescription(org.eclipse.smarthome.core.types.StateDescription) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 5 with StateOption

use of org.eclipse.smarthome.core.types.StateOption in project smarthome by eclipse.

the class DsChannelTypeProvider method getStageDescription.

private StateDescription getStageDescription(String channelID, Locale locale) {
    if (channelID.contains(STAGE.toLowerCase())) {
        List<StateOption> stateOptions = new ArrayList<StateOption>();
        if (channelID.contains(LIGHT)) {
            stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_OFF, getText(getStageChannelOption(LIGHT, DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_OFF), locale)));
            stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_ON, getText(getStageChannelOption(LIGHT, DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_ON), locale)));
            stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_FIRST_ON, getText(getStageChannelOption(LIGHT, DigitalSTROMBindingConstants.OPTION_COMBINED_FIRST_ON), locale)));
            if (channelID.contains("3")) {
                stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_SECOND_ON, getText(getStageChannelOption(LIGHT, DigitalSTROMBindingConstants.OPTION_COMBINED_SECOND_ON), locale)));
            }
        } else {
            stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_OFF, getText(getStageChannelOption(GENERAL, DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_OFF), locale)));
            stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_ON, getText(getStageChannelOption(GENERAL, DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_ON), locale)));
            stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_FIRST_ON, getText(getStageChannelOption(GENERAL, DigitalSTROMBindingConstants.OPTION_COMBINED_FIRST_ON), locale)));
            if (channelID.contains("3")) {
                stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_SECOND_ON, getText(getStageChannelOption(GENERAL, DigitalSTROMBindingConstants.OPTION_COMBINED_SECOND_ON), locale)));
            }
        }
        return new StateDescription(null, null, null, null, false, stateOptions);
    }
    if (channelID.contains(TEMPERATURE_CONTROLLED)) {
        return new StateDescription(new BigDecimal(0), new BigDecimal(50), new BigDecimal(0.1), "%.1f °C", false, null);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) StateOption(org.eclipse.smarthome.core.types.StateOption) BigDecimal(java.math.BigDecimal) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Aggregations

StateDescription (org.eclipse.smarthome.core.types.StateDescription)13 StateOption (org.eclipse.smarthome.core.types.StateOption)13 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 Item (org.eclipse.smarthome.core.items.Item)3 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)3 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)3 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)3 StringItem (org.eclipse.smarthome.core.library.items.StringItem)3 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)3 StringType (org.eclipse.smarthome.core.library.types.StringType)3 BigDecimal (java.math.BigDecimal)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)2 Before (org.junit.Before)2 ChronoUnit (java.time.temporal.ChronoUnit)1 Collection (java.util.Collection)1 Locale (java.util.Locale)1 Unit (javax.measure.Unit)1 Configuration (org.eclipse.smarthome.config.core.Configuration)1