use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class NumberExtensionsTest method testOperator_lessThanTypeNumber.
/**
* Test method for
* {@link org.eclipse.smarthome.model.script.lib.NumberExtensions#operator_lessThan(org.eclipse.smarthome.core.types.Type, java.lang.Number)}
* .
*/
@Test
public void testOperator_lessThanTypeNumber() {
DecimalType type = new DecimalType(10);
Number x = 123;
boolean result = NumberExtensions.operator_lessThan((Type) type, x);
Assert.assertTrue(result);
x = 2;
result = NumberExtensions.operator_lessThan((Type) type, x);
Assert.assertFalse(result);
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class NumberExtensionsTest method testOperator_greaterEqualsThanTypeNumber.
/**
* Test method for
* {@link org.eclipse.smarthome.model.script.lib.NumberExtensions#operator_greaterEqualsThan(org.eclipse.smarthome.core.types.Type, java.lang.Number)}
* .
*/
@Test
public void testOperator_greaterEqualsThanTypeNumber() {
DecimalType type = new DecimalType(10);
Number x = 123;
boolean result = NumberExtensions.operator_greaterEqualsThan((Type) type, x);
Assert.assertFalse(result);
x = 2;
result = NumberExtensions.operator_greaterEqualsThan((Type) type, x);
Assert.assertTrue(result);
x = 10;
result = NumberExtensions.operator_greaterEqualsThan((Type) type, x);
Assert.assertTrue(result);
}
use of org.eclipse.smarthome.core.library.types.DecimalType 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.DecimalType in project smarthome by eclipse.
the class AbstractRuleBasedInterpreter method itemRule.
/**
* Creates an item rule on base of a head and a tail expression, where the middle part of the new rule's expression
* will consist of an item
* name expression. Either the head expression or the tail expression should contain at least one {@link cmd}
* generated expression.
*
* @param headExpression The head expression.
* @param tailExpression The tail expression.
* @return The created rule.
*/
protected Rule itemRule(Object headExpression, Object tailExpression) {
Expression tail = exp(tailExpression);
Expression expression = tail == null ? seq(headExpression, name()) : seq(headExpression, name(tail), tail);
return new Rule(expression) {
@Override
public InterpretationResult interpretAST(ResourceBundle language, ASTNode node) {
String[] name = node.findValueAsStringArray(NAME);
ASTNode cmdNode = node.findNode(CMD);
Object tag = cmdNode.getTag();
Object value = cmdNode.getValue();
Command command;
if (tag instanceof Command) {
command = (Command) tag;
} else if (value instanceof Number) {
command = new DecimalType(((Number) value).longValue());
} else {
command = new StringType(cmdNode.getValueAsString());
}
if (name != null && command != null) {
try {
return new InterpretationResult(true, executeSingle(language, name, command));
} catch (InterpretationException ex) {
return new InterpretationResult(ex);
}
}
return InterpretationResult.SEMANTIC_ERROR;
}
};
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class PersistenceExtensionsTest method testAverageSince.
@Test
public void testAverageSince() {
item.setState(new DecimalType(3025));
DateMidnight startStored = new DateMidnight(2003, 1, 1);
DateMidnight endStored = new DateMidnight(2012, 1, 1);
long storedInterval = endStored.getMillis() - startStored.getMillis();
long recentInterval = DateTime.now().getMillis() - endStored.getMillis();
double expected = (2007.4994 * storedInterval + 2518.5 * recentInterval) / (storedInterval + recentInterval);
DecimalType average = PersistenceExtensions.averageSince(item, startStored, "test");
assertEquals(expected, average.doubleValue(), 0.01);
}
Aggregations