Search in sources :

Example 26 with DecimalType

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);
}
Also used : Type(org.eclipse.smarthome.core.types.Type) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) Test(org.junit.Test)

Example 27 with DecimalType

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);
}
Also used : Type(org.eclipse.smarthome.core.types.Type) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) Test(org.junit.Test)

Example 28 with DecimalType

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);
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) HSBType(org.eclipse.smarthome.core.library.types.HSBType)

Example 29 with DecimalType

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;
        }
    };
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) Command(org.eclipse.smarthome.core.types.Command) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) ResourceBundle(java.util.ResourceBundle)

Example 30 with DecimalType

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);
}
Also used : DateMidnight(org.joda.time.DateMidnight) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) Test(org.junit.Test)

Aggregations

DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)68 Test (org.junit.Test)33 State (org.eclipse.smarthome.core.types.State)17 PercentType (org.eclipse.smarthome.core.library.types.PercentType)16 HistoricItem (org.eclipse.smarthome.core.persistence.HistoricItem)11 StringType (org.eclipse.smarthome.core.library.types.StringType)9 HSBType (org.eclipse.smarthome.core.library.types.HSBType)8 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)7 Type (org.eclipse.smarthome.core.types.Type)7 Item (org.eclipse.smarthome.core.items.Item)6 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 BigDecimal (java.math.BigDecimal)5 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)4 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)4 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)4 Response (javax.ws.rs.core.Response)3 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)3 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)3 DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)3