Search in sources :

Example 6 with StateDescription

use of org.eclipse.smarthome.core.types.StateDescription 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 7 with StateDescription

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

the class ItemUIRegistryImplTest method getLabel_labelWithPatternInStateDescription.

@Test
public void getLabel_labelWithPatternInStateDescription() throws ItemNotFoundException {
    String testLabel = "Label";
    StateDescription stateDescription = mock(StateDescription.class);
    when(widget.getLabel()).thenReturn(testLabel);
    when(item.getStateDescription()).thenReturn(stateDescription);
    when(stateDescription.getPattern()).thenReturn("%s");
    when(item.getState()).thenReturn(new StringType("State"));
    String label = uiRegistry.getLabel(widget);
    assertEquals("Label [State]", label);
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StateDescription(org.eclipse.smarthome.core.types.StateDescription) Test(org.junit.Test)

Example 8 with StateDescription

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

the class ItemUIRegistryImplTest method getLabel_labelWithEmptyPattern.

@Test
public void getLabel_labelWithEmptyPattern() throws ItemNotFoundException {
    String testLabel = "Label []";
    StateDescription stateDescription = mock(StateDescription.class);
    when(widget.getLabel()).thenReturn(testLabel);
    when(item.getStateDescription()).thenReturn(stateDescription);
    when(stateDescription.getPattern()).thenReturn("%s");
    when(item.getState()).thenReturn(new StringType("State"));
    String label = uiRegistry.getLabel(widget);
    assertEquals("Label", label);
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StateDescription(org.eclipse.smarthome.core.types.StateDescription) Test(org.junit.Test)

Example 9 with StateDescription

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

the class ItemUIRegistryImplTest method getLabel_labelWithoutPatternInStateDescription.

@Test
public void getLabel_labelWithoutPatternInStateDescription() throws ItemNotFoundException {
    String testLabel = "Label";
    StateDescription stateDescription = mock(StateDescription.class);
    when(widget.getLabel()).thenReturn(testLabel);
    when(item.getStateDescription()).thenReturn(stateDescription);
    when(stateDescription.getPattern()).thenReturn(null);
    when(item.getState()).thenReturn(new StringType("State"));
    String label = uiRegistry.getLabel(widget);
    assertEquals("Label", label);
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StateDescription(org.eclipse.smarthome.core.types.StateDescription) Test(org.junit.Test)

Example 10 with StateDescription

use of org.eclipse.smarthome.core.types.StateDescription 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)

Aggregations

StateDescription (org.eclipse.smarthome.core.types.StateDescription)31 Test (org.junit.Test)15 StateOption (org.eclipse.smarthome.core.types.StateOption)13 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)7 ArrayList (java.util.ArrayList)6 StringType (org.eclipse.smarthome.core.library.types.StringType)6 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)6 BigDecimal (java.math.BigDecimal)4 Item (org.eclipse.smarthome.core.items.Item)4 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)4 StateDescriptionProvider (org.eclipse.smarthome.core.types.StateDescriptionProvider)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 GroupItem (org.eclipse.smarthome.core.items.GroupItem)3 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)3 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)3 StringItem (org.eclipse.smarthome.core.library.items.StringItem)3 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Before (org.junit.Before)3 Collection (java.util.Collection)2