use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.
the class HSBK method getHSB.
public HSBType getHSB() {
DecimalType hue = hueToDecimalType(this.hue);
PercentType saturation = saturationToPercentType(this.saturation);
PercentType brightness = brightnessToPercentType(this.brightness);
return new HSBType(hue, saturation, brightness);
}
use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.
the class LightStateConverter method toHSBType.
/**
* Transforms Hue Light {@link State} into {@link HSBType} representing the
* color.
*
* @param lightState light state
* @return HSB type representing the color
*/
public static HSBType toHSBType(State lightState) {
int hue = lightState.getHue();
int saturationInPercent = (int) (lightState.getSaturation() / SATURATION_FACTOR);
int brightnessInPercent = (int) (lightState.getBrightness() / BRIGHTNESS_FACTOR);
saturationInPercent = restrictToBounds(saturationInPercent);
brightnessInPercent = restrictToBounds(brightnessInPercent);
return new HSBType(new DecimalType(hue / HUE_FACTOR), new PercentType(saturationInPercent), new PercentType(brightnessInPercent));
}
use of org.eclipse.smarthome.core.library.types.HSBType in project habot by ghys.
the class SetValueSkill method interpretSetColor.
private void interpretSetColor(Intent intent, String language, IntentInterpretation interpretation, Set<Item> matchedItems) {
String colorString = intent.getEntities().get("color");
// filter out the items which can't receive an HSB command
List<Item> filteredItems = matchedItems.stream().filter(i -> i.getAcceptedCommandTypes().contains(HSBType.class)).collect(Collectors.toList());
String hsbValue;
try {
ResourceBundle colors = ResourceBundle.getBundle("colors", new Locale(language));
hsbValue = colors.getString("color_" + colorString);
} catch (MissingResourceException e) {
interpretation.setAnswer(answerFormatter.getRandomAnswer("set_color_unknown", ImmutableMap.of("color", colorString)));
return;
}
if (filteredItems.isEmpty()) {
interpretation.setAnswer(answerFormatter.getRandomAnswer("set_color_no_item", ImmutableMap.of("color", colorString)));
interpretation.setHint(answerFormatter.getStandardTagHint(intent.getEntities()));
} else if (filteredItems.size() == 1) {
interpretation.setCard(cardBuilder.buildCard(intent, filteredItems));
eventPublisher.post(ItemEventFactory.createCommandEvent(filteredItems.get(0).getName(), new HSBType(hsbValue)));
interpretation.setAnswer(answerFormatter.getRandomAnswer("set_color_single", ImmutableMap.of("color", colorString)));
} else {
interpretation.setCard(cardBuilder.buildCard(intent, filteredItems));
for (Item item : filteredItems) {
eventPublisher.post(ItemEventFactory.createCommandEvent(item.getName(), new HSBType(hsbValue)));
}
interpretation.setAnswer(answerFormatter.getRandomAnswer("set_color_multiple", ImmutableMap.of("count", String.valueOf(filteredItems.size()), "color", colorString)));
}
}
use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.
the class GroupItemTest method assertThatGroupItemWithColoritemBaseItemConversionWorks.
@Test
public void assertThatGroupItemWithColoritemBaseItemConversionWorks() {
// initially this group has State UndefType.NULL
GroupItem groupItem = new GroupItem("root", new ColorItem("myColor"));
State groupStateAsPercent = groupItem.getStateAs(PercentType.class);
// a state conversion from NULL to PercentType should not be possible
assertNull(groupStateAsPercent);
// init group
groupItem.setState(new HSBType("200,80,80"));
groupStateAsPercent = groupItem.getStateAs(PercentType.class);
assertTrue(groupStateAsPercent instanceof PercentType);
assertThat(((PercentType) groupStateAsPercent).intValue(), is(80));
}
use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.
the class ColorItemTest method testSetStateWithHSBType.
@Test
public void testSetStateWithHSBType() {
ColorItem item = new ColorItem("test");
item.setState(new HSBType(new DecimalType(75), new PercentType(75), new PercentType(75)));
assertEquals(new HSBType(new DecimalType(75), new PercentType(75), new PercentType(75)), item.getState());
}
Aggregations