use of org.openhab.core.events.Event in project openhab-core by openhab.
the class ItemEventFactoryTest method testCreateEventItemStateEventUnDefType.
@Test
public void testCreateEventItemStateEventUnDefType() throws Exception {
Event event = factory.createEvent(ITEM_STATE_EVENT_TYPE, ITEM_STATE_EVENT_TOPIC, ITEM_UNDEF_STATE_EVENT_PAYLOAD, SOURCE);
assertEquals(ItemStateEvent.class, event.getClass());
ItemStateEvent itemStateEvent = (ItemStateEvent) event;
assertEquals(ITEM_STATE_EVENT_TYPE, itemStateEvent.getType());
assertEquals(ITEM_STATE_EVENT_TOPIC, itemStateEvent.getTopic());
assertEquals(ITEM_UNDEF_STATE_EVENT_PAYLOAD, itemStateEvent.getPayload());
assertEquals(ITEM_NAME, itemStateEvent.getItemName());
assertEquals(SOURCE, itemStateEvent.getSource());
assertEquals(UnDefType.UNDEF, itemStateEvent.getItemState());
}
use of org.openhab.core.events.Event in project openhab-core by openhab.
the class ItemEventFactoryTest method testCreateEventItemAddedEvent.
@Test
public void testCreateEventItemAddedEvent() throws Exception {
Event event = factory.createEvent(ITEM_ADDED_EVENT_TYPE, ITEM_ADDED_EVENT_TOPIC, ITEM_ADDED_EVENT_PAYLOAD, null);
assertEquals(ItemAddedEvent.class, event.getClass());
ItemAddedEvent itemAddedEvent = (ItemAddedEvent) event;
assertEquals(ITEM_ADDED_EVENT_TYPE, itemAddedEvent.getType());
assertEquals(ITEM_ADDED_EVENT_TOPIC, itemAddedEvent.getTopic());
assertEquals(ITEM_ADDED_EVENT_PAYLOAD, itemAddedEvent.getPayload());
assertNotNull(itemAddedEvent.getItem());
assertEquals(ITEM_NAME, itemAddedEvent.getItem().name);
assertEquals(CoreItemFactory.SWITCH, itemAddedEvent.getItem().type);
}
use of org.openhab.core.events.Event in project openhab-core by openhab.
the class ItemEventFactoryTest method testCreateEventItemStatePredictedEventOnOffType.
@Test
public void testCreateEventItemStatePredictedEventOnOffType() throws Exception {
Event event = factory.createEvent(ITEM_STATE_PREDICTED_EVENT_TYPE, ITEM_STATE_PREDICTED_EVENT_TOPIC, ITEM_STATE_PREDICTED_EVENT_PAYLOAD, SOURCE);
assertEquals(ItemStatePredictedEvent.class, event.getClass());
ItemStatePredictedEvent itemStatePredictedEvent = (ItemStatePredictedEvent) event;
assertEquals(ITEM_STATE_PREDICTED_EVENT_TYPE, itemStatePredictedEvent.getType());
assertEquals(ITEM_STATE_PREDICTED_EVENT_TOPIC, itemStatePredictedEvent.getTopic());
assertEquals(ITEM_STATE_PREDICTED_EVENT_PAYLOAD, itemStatePredictedEvent.getPayload());
assertEquals(ITEM_NAME, itemStatePredictedEvent.getItemName());
assertEquals(OnOffType.class, itemStatePredictedEvent.getPredictedState().getClass());
assertEquals(ITEM_STATE, itemStatePredictedEvent.getPredictedState());
}
use of org.openhab.core.events.Event in project openhab-addons by openhab.
the class NeeoBrainService method getEventFilter.
/**
* Returns the {@link EventFilter} used by this service. The {@link EventFilter} will simply filter for those items
* that have been bound
*
* @return a non-null {@link EventFilter}
*/
@NonNull
@Override
public EventFilter getEventFilter() {
return new EventFilter() {
@Override
public boolean apply(@Nullable Event event) {
Objects.requireNonNull(event, "event cannot be null");
final ItemStateChangedEvent ise = (ItemStateChangedEvent) event;
final String itemName = ise.getItemName();
final NeeoDeviceKeys keys = api.getDeviceKeys();
final boolean isBound = context.getDefinitions().isBound(keys, itemName);
logger.trace("Apply Event: {} --- {} --- {} = {}", event, itemName, isBound, keys);
return isBound;
}
};
}
use of org.openhab.core.events.Event in project jrule by seaside1.
the class JRuleHandler method propertyChange.
@Override
public void propertyChange(@Nullable PropertyChangeEvent evt) {
if (evt == null) {
return;
}
final String property = evt.getPropertyName();
if (property.equals(JRuleEventSubscriber.PROPERTY_ITEM_REGISTRY_EVENT)) {
Event event = (Event) evt.getNewValue();
if (event == null) {
logDebug("Event value null. ignoring: {}", evt);
return;
}
String eventType = event.getType();
String itemName = JRuleUtil.getItemNameFromTopic(event.getTopic());
if (eventType.equals(ItemRemovedEvent.TYPE)) {
logDebug("RemovedType: {}", evt);
deleteClassFileForItem(itemName);
deleteSourceFileForItem(itemName);
recompileJar = true;
} else if (eventType.equals(ItemAddedEvent.TYPE) || event.getType().equals(ItemUpdatedEvent.TYPE)) {
try {
logDebug("Added/updatedType: {}", evt);
Item item = itemRegistry.getItem(itemName);
generateItemSource(item);
} catch (ItemNotFoundException e) {
logDebug("Could not find new item", e);
}
} else {
logDebug("Failed to do something with item event");
}
if (recompileJar) {
compileItems();
createItemsJar();
}
} else if (JRuleRulesWatcher.PROPERTY_ENTRY_CREATE.equals(property) || JRuleRulesWatcher.PROPERTY_ENTRY_MODIFY.equals(property) || JRuleRulesWatcher.PROPERTY_ENTRY_DELETE.equals(property)) {
Path newValue = (Path) evt.getNewValue();
logDebug("Directory watcher new value: {}", newValue);
reloadRules();
logDebug("All Rules reloaded");
}
}
Aggregations