Search in sources :

Example 21 with DecimalType

use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.

the class ConnectedBluetoothHandler method updateBatteryLevel.

protected void updateBatteryLevel(BluetoothCharacteristic characteristic) {
    // the byte has values from 0-255, which we need to map to 0-100
    Double level = characteristic.getValue()[0] / 2.55;
    updateState(characteristic.getGattCharacteristic().name(), new DecimalType(level.intValue()));
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType)

Example 22 with DecimalType

use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.

the class LocationItem method distanceFrom.

/**
 * Compute the distance with another Point type,
 * http://stackoverflow.com/questions/837872/calculate-distance-in-meters-when-you-know-longitude-and-latitude-in-
 * java
 *
 * @param away : the point to calculate the distance with
 * @return distance between the two points in meters
 */
public DecimalType distanceFrom(@Nullable LocationItem awayItem) {
    if (awayItem != null && awayItem.state instanceof PointType && this.state instanceof PointType) {
        PointType thisPoint = (PointType) this.state;
        PointType awayPoint = (PointType) awayItem.state;
        return thisPoint.distanceFrom(awayPoint);
    }
    return new DecimalType(-1);
}
Also used : PointType(org.eclipse.smarthome.core.library.types.PointType) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType)

Example 23 with DecimalType

use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.

the class NumberExtensionsTest method testOperator_notEqualsTypeNumber.

/**
 * Test method for
 * {@link org.eclipse.smarthome.model.script.lib.NumberExtensions#operator_notEquals(org.eclipse.smarthome.core.types.Type, java.lang.Number)}
 * .
 */
@Test
public void testOperator_notEqualsTypeNumber() {
    DecimalType type = new DecimalType(10);
    Number x = 10;
    boolean result = NumberExtensions.operator_notEquals((Type) type, x);
    Assert.assertFalse(result);
    x = 1;
    result = NumberExtensions.operator_notEquals((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 24 with DecimalType

use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.

the class NumberExtensionsTest method testOperator_lessEqualsThanTypeNumber.

/**
 * Test method for
 * {@link org.eclipse.smarthome.model.script.lib.NumberExtensions#operator_lessEqualsThan(org.eclipse.smarthome.core.types.Type, java.lang.Number)}
 * .
 */
@Test
public void testOperator_lessEqualsThanTypeNumber() {
    DecimalType type = new DecimalType(10);
    Number x = 123;
    boolean result = NumberExtensions.operator_lessEqualsThan((Type) type, x);
    Assert.assertTrue(result);
    x = 2;
    result = NumberExtensions.operator_lessEqualsThan((Type) type, x);
    Assert.assertFalse(result);
    x = 10;
    result = NumberExtensions.operator_lessEqualsThan((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 25 with DecimalType

use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.

the class NumberExtensionsTest method testOperator_equalsTypeNumber.

/**
 * Test method for
 * {@link org.eclipse.smarthome.model.script.lib.NumberExtensions#operator_equals(org.eclipse.smarthome.core.types.Type, java.lang.Number)}
 * .
 */
@Test
public void testOperator_equalsTypeNumber() {
    DecimalType type = new DecimalType(10);
    Number x = 10;
    boolean result = NumberExtensions.operator_equals((Type) type, x);
    Assert.assertTrue(result);
    x = 1;
    result = NumberExtensions.operator_equals((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)

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