use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class MagicDelayedOnlineHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (channelUID.getId().equals("number")) {
if (command instanceof DecimalType) {
DecimalType cmd = (DecimalType) command;
int cmdInt = cmd.intValue();
ThingStatus status = cmdInt > 0 ? ThingStatus.ONLINE : ThingStatus.OFFLINE;
int waitTime = Math.abs(cmd.intValue());
scheduler.schedule(() -> updateStatus(status), waitTime, TimeUnit.SECONDS);
}
}
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class SetpointRenderer method renderWidget.
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
Setpoint sp = (Setpoint) w;
State state = itemUIRegistry.getState(w);
String newLowerState = state.toString();
String newHigherState = state.toString();
// set defaults for min, max and step
BigDecimal step = sp.getStep();
if (step == null) {
step = BigDecimal.ONE;
}
BigDecimal minValue = sp.getMinValue();
if (minValue == null) {
minValue = BigDecimal.ZERO;
}
BigDecimal maxValue = sp.getMaxValue();
if (maxValue == null) {
maxValue = BigDecimal.valueOf(100);
}
// if the current state is a valid value, we calculate the up and down step values
if (state instanceof DecimalType) {
DecimalType actState = (DecimalType) state;
BigDecimal newLower = actState.toBigDecimal().subtract(step);
BigDecimal newHigher = actState.toBigDecimal().add(step);
if (newLower.compareTo(minValue) < 0) {
newLower = minValue;
}
if (newHigher.compareTo(maxValue) > 0) {
newHigher = maxValue;
}
newLowerState = newLower.toString();
newHigherState = newHigher.toString();
}
String unit = getUnitForWidget(w);
String snippetName = "setpoint";
String snippet = getSnippet(snippetName);
snippet = preprocessSnippet(snippet, w);
snippet = StringUtils.replace(snippet, "%newlowerstate%", newLowerState);
snippet = StringUtils.replace(snippet, "%newhigherstate%", newHigherState);
snippet = StringUtils.replace(snippet, "%value%", getValue(w));
snippet = StringUtils.replace(snippet, "%minValue%", minValue.toString());
snippet = StringUtils.replace(snippet, "%maxValue%", maxValue.toString());
snippet = StringUtils.replace(snippet, "%step%", step.toString());
snippet = StringUtils.replace(snippet, "%unit%", unit);
// Process the color tags
snippet = processColor(w, snippet);
sb.append(snippet);
return null;
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class SetpointRenderer method renderWidget.
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
Setpoint sp = (Setpoint) w;
State state = itemUIRegistry.getState(w);
String newLowerState = state.toString();
String newHigherState = state.toString();
// set defaults for min, max and step
BigDecimal step = sp.getStep();
if (step == null) {
step = BigDecimal.ONE;
}
BigDecimal minValue = sp.getMinValue();
if (minValue == null) {
minValue = BigDecimal.ZERO;
}
BigDecimal maxValue = sp.getMaxValue();
if (maxValue == null) {
maxValue = BigDecimal.valueOf(100);
}
// if the current state is a valid value, we calculate the up and down step values
if (state instanceof DecimalType || state instanceof QuantityType) {
BigDecimal currentState;
if (state instanceof DecimalType) {
currentState = ((DecimalType) state).toBigDecimal();
} else {
currentState = ((QuantityType<?>) state).toBigDecimal();
}
BigDecimal newLower = currentState.subtract(step);
BigDecimal newHigher = currentState.add(step);
if (newLower.compareTo(minValue) < 0) {
newLower = minValue;
}
if (newHigher.compareTo(maxValue) > 0) {
newHigher = maxValue;
}
newLowerState = newLower.toString();
newHigherState = newHigher.toString();
if (state instanceof QuantityType) {
newLowerState = newLowerState + " " + ((QuantityType<?>) state).getUnit().toString();
newHigherState = newHigherState + " " + ((QuantityType<?>) state).getUnit().toString();
}
}
String snippetName = "setpoint";
String snippet = getSnippet(snippetName);
snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(w));
snippet = StringUtils.replace(snippet, "%category%", getCategory(w));
snippet = StringUtils.replace(snippet, "%item%", w.getItem());
snippet = StringUtils.replace(snippet, "%state%", getState(w));
snippet = StringUtils.replace(snippet, "%newlowerstate%", newLowerState);
snippet = StringUtils.replace(snippet, "%newhigherstate%", newHigherState);
snippet = StringUtils.replace(snippet, "%label%", getLabel(w));
snippet = StringUtils.replace(snippet, "%format%", getFormat());
snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME);
snippet = StringUtils.replace(snippet, "%minValue%", minValue.toString());
snippet = StringUtils.replace(snippet, "%maxValue%", maxValue.toString());
snippet = StringUtils.replace(snippet, "%step%", step.toString());
// Process the color tags
snippet = processColor(w, snippet);
sb.append(snippet);
return null;
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class GroupItemTest method assertCyclicGroupItemsCalculateState.
@Test
public void assertCyclicGroupItemsCalculateState() {
GroupFunction countFn = new ArithmeticGroupFunction.Count(new StringType(".*"));
GroupItem rootGroup = new GroupItem("rootGroup", new SwitchItem("baseItem"), countFn);
TestItem rootMember = new TestItem("rootMember");
rootGroup.addMember(rootMember);
GroupItem group1 = new GroupItem("group1");
GroupItem group2 = new GroupItem("group2");
rootGroup.addMember(group1);
group1.addMember(group2);
group2.addMember(group1);
group1.addMember(new TestItem("sub1"));
group2.addMember(new TestItem("sub2-1"));
group2.addMember(new TestItem("sub2-2"));
group2.addMember(new TestItem("sub2-3"));
// count: rootMember, sub1, sub2-1, sub2-2, sub2-3
assertThat(rootGroup.getStateAs(DecimalType.class), is(new DecimalType(5)));
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class ColorItemTest method testUpdateStateWithPercentType.
@Test
public void testUpdateStateWithPercentType() {
ColorItem item = new ColorItem("test");
item.setState(new HSBType(new DecimalType(75), new PercentType(75), new PercentType(75)));
item.setState(new PercentType(50));
assertEquals(new HSBType(new DecimalType(75), new PercentType(75), new PercentType(50)), item.getState());
}
Aggregations