use of org.eclipse.smarthome.core.types.Type in project smarthome by eclipse.
the class CommunicationManager method handleEvent.
private <T extends Type> void handleEvent(String itemName, T type, String source, Function<@Nullable String, @Nullable List<Class<? extends T>>> acceptedTypesFunction, ProfileAction<T> action) {
final Item item = getItem(itemName);
if (item == null) {
logger.debug("Received an event for item {} which does not exist", itemName);
return;
}
itemChannelLinkRegistry.stream().filter(link -> {
// all links for the item
return link.getItemName().equals(itemName);
}).filter(link -> {
// make sure the command event is not sent back to its source
return !link.getLinkedUID().toString().equals(source);
}).forEach(link -> {
ChannelUID channelUID = link.getLinkedUID();
Thing thing = getThing(channelUID.getThingUID());
if (thing != null) {
Channel channel = thing.getChannel(channelUID.getId());
if (channel != null) {
@Nullable T convertedType = toAcceptedType(type, channel, acceptedTypesFunction);
if (convertedType != null) {
if (thing.getHandler() != null) {
Profile profile = getProfile(link, item, thing);
action.handle(profile, thing, convertedType);
}
} else {
logger.debug("Received event '{}' ({}) could not be converted to any type accepted by item '{}' ({})", type, type.getClass().getSimpleName(), itemName, item.getType());
}
} else {
logger.debug("Received event '{}' for non-existing channel '{}', not forwarding it to the handler", type, channelUID);
}
} else {
logger.debug("Received event '{}' for non-existing thing '{}', not forwarding it to the handler", type, channelUID.getThingUID());
}
});
}
use of org.eclipse.smarthome.core.types.Type 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.types.Type 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.types.Type 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);
}
use of org.eclipse.smarthome.core.types.Type 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);
}
Aggregations