use of org.eclipse.smarthome.core.types.StateDescription in project smarthome by eclipse.
the class ThingTypesTest method thingTypesShouldLoad.
@Test
public void thingTypesShouldLoad() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 3));
BridgeType bridgeType = (BridgeType) thingTypes.stream().filter(it -> it.toString().equals("hue:bridge")).findFirst().get();
assertThat(bridgeType, is(notNullValue()));
assertThat(bridgeType.getCategory(), is("NetworkAppliance"));
assertThat(bridgeType.isListed(), is(false));
assertThat(bridgeType.getLabel(), is("HUE Bridge"));
assertThat(bridgeType.getDescription(), is("The hue Bridge represents the Philips hue bridge."));
assertThat(bridgeType.getProperties().size(), is(1));
assertThat(bridgeType.getProperties().get("vendor"), is("Philips"));
assertThat(bridgeType.getRepresentationProperty(), is("serialNumber"));
ThingType thingType = thingTypes.stream().filter(it -> it.toString().equals("hue:lamp")).findFirst().get();
assertThat(thingType, is(notNullValue()));
assertThat(thingType.getCategory(), is("Lightbulb"));
assertThat(thingType.isListed(), is(false));
assertThat(thingType.getLabel(), is("HUE Lamp"));
assertThat(thingType.getDescription(), is("My own great HUE Lamp."));
assertThat(thingType.getSupportedBridgeTypeUIDs().size(), is(1));
assertThat(thingType.getSupportedBridgeTypeUIDs().get(0), is("hue:bridge"));
assertThat(thingType.getExtensibleChannelTypeIds(), containsInAnyOrder("alarm", "brightness"));
assertThat(thingType.getProperties().size(), is(2));
assertThat(thingType.getProperties().get("key1"), is("value1"));
assertThat(thingType.getProperties().get("key2"), is("value2"));
assertThat(thingType.getRepresentationProperty(), is("uniqueId"));
List<ChannelDefinition> channelDefinitions = thingType.getChannelDefinitions();
assertThat(channelDefinitions.size(), is(3));
ChannelDefinition colorChannel = channelDefinitions.stream().filter(it -> it.getId().equals("color")).findFirst().get();
assertThat(colorChannel, is(notNullValue()));
assertThat(colorChannel.getProperties().size(), is(2));
assertThat(colorChannel.getProperties().get("chan.key1"), is("value1"));
assertThat(colorChannel.getProperties().get("chan.key2"), is("value2"));
ChannelType colorChannelType = channelTypeRegistry.getChannelType(colorChannel.getChannelTypeUID());
assertThat(colorChannelType, is(notNullValue()));
assertThat(colorChannelType.toString(), is("hue:color"));
assertThat(colorChannelType.getItemType(), is("ColorItem"));
assertThat(colorChannelType.getLabel(), is("HUE Lamp Color"));
assertThat(colorChannelType.getDescription(), is("The color channel allows to control the color of the hue lamp. It is also possible to dim values and switch the lamp on and off."));
Set<String> tags = colorChannelType.getTags();
assertThat(tags, is(notNullValue()));
assertThat(tags.contains("Hue"), is(true));
assertThat(tags.contains("ColorLamp"), is(true));
assertThat(tags.contains("AmbientLamp"), is(false));
assertThat(tags.contains("AlarmSystem"), is(false));
ChannelDefinition colorTemperatureChannel = channelDefinitions.stream().filter(it -> it.getId().equals("color_temperature")).findFirst().get();
assertThat(colorTemperatureChannel, is(notNullValue()));
assertThat(colorTemperatureChannel.getProperties().size(), is(0));
ChannelType colorTemperatureChannelType = channelTypeRegistry.getChannelType(colorTemperatureChannel.getChannelTypeUID());
assertThat(colorTemperatureChannelType, is(notNullValue()));
assertThat(colorTemperatureChannelType.toString(), is("hue:color_temperature"));
assertThat(colorTemperatureChannelType.getItemType(), is("DimmerItem"));
assertThat(colorTemperatureChannelType.getLabel(), is("HUE Lamp Color Temperature"));
assertThat(colorTemperatureChannelType.getDescription(), is("The color temperature channel allows to set the color temperature from 0 (cold) to 100 (warm)."));
tags = colorTemperatureChannelType.getTags();
assertThat(tags, is(notNullValue()));
assertThat(tags.contains("Hue"), is(true));
assertThat(tags.contains("AmbientLamp"), is(true));
assertThat(tags.contains("ColorLamp"), is(false));
assertThat(tags.contains("AlarmSystem"), is(false));
ChannelDefinition alarmChannel = channelDefinitions.stream().filter(it -> it.getId().equals("alarm")).findFirst().get();
assertThat(alarmChannel, is(notNullValue()));
ChannelType alarmChannelType = channelTypeRegistry.getChannelType(alarmChannel.getChannelTypeUID());
assertThat(alarmChannelType, is(notNullValue()));
assertThat(alarmChannelType.toString(), is("hue:alarm"));
assertThat(alarmChannelType.getItemType(), is("Number"));
assertThat(alarmChannelType.getLabel(), is("Alarm System"));
assertThat(alarmChannelType.getDescription(), is("The light blinks if alarm is set."));
tags = alarmChannelType.getTags();
assertThat(tags, is(notNullValue()));
assertThat(tags.contains("Hue"), is(true));
assertThat(tags.contains("AlarmSystem"), is(true));
assertThat(tags.contains("AmbientLamp"), is(false));
assertThat(tags.contains("ColorLamp"), is(false));
assertThat(alarmChannelType.getCategory(), is(equalTo("ALARM")));
StateDescription state = alarmChannelType.getState();
assertThat(state.getMinimum(), is(BigDecimal.ZERO));
assertThat(state.getMaximum(), is(BigDecimal.valueOf(100.0)));
assertThat(state.getStep(), is(BigDecimal.valueOf(10.0)));
assertThat(state.getPattern(), is(equalTo("%d Peek")));
assertThat(state.isReadOnly(), is(true));
assertThat(state.getOptions().size(), is(2));
assertThat(state.getOptions().get(0).getValue(), is(equalTo("SOUND")));
assertThat(state.getOptions().get(0).getLabel(), is(equalTo("My great sound.")));
thingType = thingTypes.stream().filter(it -> it.toString().equals("hue:lamp-with-group")).findFirst().get();
assertThat(thingType.getProperties().size(), is(0));
assertThat(thingType.getCategory(), is(nullValue()));
assertThat(thingType.isListed(), is(true));
assertThat(thingType.getExtensibleChannelTypeIds(), containsInAnyOrder("brightness", "alarm"));
// uninstall test bundle
bundle.uninstall();
assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
}
use of org.eclipse.smarthome.core.types.StateDescription in project smarthome by eclipse.
the class StateDescriptionServiceImplTest method testCorrectIsReadOnlyWhenTwoDescriptionProvidersHigherRankingIsReadOnly.
@Test
public void testCorrectIsReadOnlyWhenTwoDescriptionProvidersHigherRankingIsReadOnly() {
StateDescription stateDescription1 = new StateDescription(null, null, null, null, true, null);
StateDescription stateDescription2 = new StateDescription(null, null, null, null, false, null);
int stateDescriptionProvider1ServiceRanking = -1;
int stateDescriptionProvider2ServiceRanking = -2;
StateDescription finalStateDescription = mergeStateDescriptions(stateDescription1, stateDescription2, stateDescriptionProvider1ServiceRanking, stateDescriptionProvider2ServiceRanking);
assertThat(finalStateDescription.isReadOnly(), is(stateDescription1.isReadOnly()));
}
use of org.eclipse.smarthome.core.types.StateDescription in project smarthome by eclipse.
the class StateDescriptionServiceImplTest method testMinValueMaxValueStepAndPatternTwoDescriptionProviders.
@Test
public void testMinValueMaxValueStepAndPatternTwoDescriptionProviders() {
StateDescription stateDescription1 = new StateDescription(new BigDecimal("-1"), new BigDecimal("-1"), new BigDecimal("-1"), "pattern1", false, null);
StateDescription stateDescription2 = new StateDescription(new BigDecimal("-2"), new BigDecimal("-2"), new BigDecimal("-2"), "pattern2", false, null);
int stateDescriptionProvider1ServiceRanking = -1;
int stateDescriptionProvider2ServiceRanking = -2;
StateDescription finalStateDescription = mergeStateDescriptions(stateDescription1, stateDescription2, stateDescriptionProvider1ServiceRanking, stateDescriptionProvider2ServiceRanking);
assertThat(finalStateDescription.getMinimum(), is(stateDescription1.getMinimum()));
assertThat(finalStateDescription.getMaximum(), is(stateDescription1.getMaximum()));
assertThat(finalStateDescription.getStep(), is(stateDescription1.getStep()));
assertThat(finalStateDescription.getPattern(), is(stateDescription1.getPattern()));
}
use of org.eclipse.smarthome.core.types.StateDescription in project smarthome by eclipse.
the class ItemStateConverterImpl method parseItemUnit.
private Unit<?> parseItemUnit(NumberItem numberItem) {
StateDescription stateDescription = numberItem.getStateDescription();
if (stateDescription == null) {
return null;
}
String pattern = stateDescription.getPattern();
return UnitUtils.parseUnit(pattern);
}
use of org.eclipse.smarthome.core.types.StateDescription 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;
}
Aggregations