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()));
}
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);
}
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);
}
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);
}
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);
}
Aggregations