use of org.openhab.core.items.ItemProvider in project openhab-core by openhab.
the class ScriptEngineOSGiTest method setup.
@BeforeEach
public void setup() {
registerVolatileStorageService();
EventPublisher eventPublisher = event -> {
};
registerService(eventPublisher);
itemRegistry = getService(ItemRegistry.class);
assertNotNull(itemRegistry);
itemProvider = new ItemProvider() {
@Override
public void addProviderChangeListener(ProviderChangeListener<Item> listener) {
}
@Override
public Collection<Item> getAll() {
return List.of(new SwitchItem(ITEM_NAME), createNumberItem(NUMBER_ITEM_TEMPERATURE, Temperature.class), createNumberItem(NUMBER_ITEM_LENGTH, Length.class), new NumberItem(NUMBER_ITEM_DECIMAL));
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<Item> listener) {
}
};
registerService(itemProvider);
ScriptServiceUtil scriptServiceUtil = getService(ScriptServiceUtil.class);
assertNotNull(scriptServiceUtil);
scriptEngine = ScriptServiceUtil.getScriptEngine();
}
use of org.openhab.core.items.ItemProvider in project openhab-core by openhab.
the class AutomationIntegrationJsonTest method before.
@BeforeEach
public void before() {
logger.info("@Before.begin");
getService(ItemRegistry.class);
ItemProvider itemProvider = new ItemProvider() {
@Override
public void addProviderChangeListener(ProviderChangeListener<Item> listener) {
}
@Override
public Collection<Item> getAll() {
return Set.of(new SwitchItem("myMotionItem"), new SwitchItem("myPresenceItem"), new SwitchItem("myLampItem"), new SwitchItem("myMotionItem2"), new SwitchItem("myPresenceItem2"), new SwitchItem("myLampItem2"), new SwitchItem("myMotionItem11"), new SwitchItem("myLampItem11"), new SwitchItem("myMotionItem3"), new SwitchItem("templ_MotionItem"), new SwitchItem("templ_LampItem"));
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<Item> listener) {
}
};
registerService(itemProvider);
registerVolatileStorageService();
EventSubscriber ruleEventHandler = new EventSubscriber() {
@Override
public Set<String> getSubscribedEventTypes() {
return Set.of(RuleStatusInfoEvent.TYPE);
}
@Override
@Nullable
public EventFilter getEventFilter() {
return null;
}
@Override
public void receive(Event e) {
logger.info("RuleEvent: {} --> {}", e.getTopic(), e.getPayload());
if (e.getPayload().contains("RUNNING")) {
ruleEvent = e;
}
}
};
registerService(ruleEventHandler);
StorageService storageService = getService(StorageService.class);
managedRuleProvider = getService(ManagedRuleProvider.class);
eventPublisher = getService(EventPublisher.class);
itemRegistry = getService(ItemRegistry.class);
ruleRegistry = getService(RuleRegistry.class);
ruleManager = getService(RuleManager.class);
moduleTypeRegistry = getService(ModuleTypeRegistry.class);
waitForAssert(() -> {
assertThat(storageService, is(notNullValue()));
// sometimes assert fails because EventPublisher service is null
assertThat(eventPublisher, is(notNullValue()));
assertThat(itemRegistry, is(notNullValue()));
assertThat(ruleRegistry, is(notNullValue()));
assertThat(ruleManager, is(notNullValue()));
assertThat(managedRuleProvider, is(notNullValue()));
assertThat(moduleTypeRegistry, is(notNullValue()));
}, 9000, 1000);
// start rule engine
RuleEngineImpl ruleEngine = (RuleEngineImpl) ruleManager;
ruleEngine.onReadyMarkerAdded(new ReadyMarker("", ""));
waitForAssert(() -> assertTrue(ruleEngine.isStarted()));
logger.info("@Before.finish");
}
use of org.openhab.core.items.ItemProvider in project openhab-core by openhab.
the class RuntimeRuleTest method before.
@BeforeEach
public void before() {
registerService(new ItemProvider() {
@Override
public void addProviderChangeListener(final ProviderChangeListener<Item> listener) {
}
@Override
public void removeProviderChangeListener(final ProviderChangeListener<Item> listener) {
}
@Override
public Collection<Item> getAll() {
return List.of(new SwitchItem("myMotionItem"), new SwitchItem("myPresenceItem"), new SwitchItem("myLampItem"), new SwitchItem("myMotionItem2"), new SwitchItem("myPresenceItem2"), new SwitchItem("myLampItem2"), new SwitchItem("myMotionItem3"), new SwitchItem("myPresenceItem3"), new SwitchItem("myLampItem3"), new SwitchItem("myMotionItem4"), new SwitchItem("myPresenceItem4"), new SwitchItem("myLampItem4"));
}
});
registerService(volatileStorageService);
// start rule engine
RuleEngineImpl ruleEngine = requireNonNull((RuleEngineImpl) getService(RuleManager.class));
ruleEngine.onReadyMarkerAdded(new ReadyMarker("", ""));
waitForAssert(() -> assertTrue(ruleEngine.isStarted()));
}
use of org.openhab.core.items.ItemProvider in project openhab-core by openhab.
the class RuleEventTest method before.
@BeforeEach
public void before() {
ItemProvider itemProvider = new ItemProvider() {
@Override
public void addProviderChangeListener(ProviderChangeListener<Item> listener) {
}
@Override
public Collection<Item> getAll() {
return List.of(new SwitchItem("myMotionItem"), new SwitchItem("myPresenceItem"), new SwitchItem("myLampItem"), new SwitchItem("myMotionItem2"), new SwitchItem("myPresenceItem2"), new SwitchItem("myLampItem2"));
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<Item> listener) {
}
};
registerService(itemProvider);
registerVolatileStorageService();
// start rule engine
RuleEngineImpl ruleEngine = requireNonNull((RuleEngineImpl) getService(RuleManager.class));
ruleEngine.onReadyMarkerAdded(new ReadyMarker("", ""));
waitForAssert(() -> assertTrue(ruleEngine.isStarted()));
}
use of org.openhab.core.items.ItemProvider in project openhab-core by openhab.
the class AutomationIntegrationTest method before.
@BeforeEach
public void before() {
logger.info("@Before.begin");
getService(ItemRegistry.class);
ItemProvider itemProvider = new ItemProvider() {
@Override
public void addProviderChangeListener(ProviderChangeListener<Item> listener) {
}
@Override
public Collection<Item> getAll() {
Set<Item> items = new HashSet<>();
items.add(new SwitchItem("myMotionItem"));
items.add(new SwitchItem("myPresenceItem"));
items.add(new SwitchItem("myLampItem"));
items.add(new SwitchItem("myMotionItem2"));
items.add(new SwitchItem("myPresenceItem2"));
items.add(new SwitchItem("myLampItem2"));
items.add(new SwitchItem("myMotionItem3"));
items.add(new SwitchItem("templ_MotionItem"));
items.add(new SwitchItem("templ_LampItem"));
items.add(new SwitchItem("myMotionItem3"));
items.add(new SwitchItem("myPresenceItem3"));
items.add(new SwitchItem("myLampItem3"));
items.add(new SwitchItem("myMotionItem4"));
items.add(new SwitchItem("myPresenceItem4"));
items.add(new SwitchItem("myLampItem4"));
items.add(new SwitchItem("myMotionItem5"));
items.add(new SwitchItem("myPresenceItem5"));
items.add(new SwitchItem("myLampItem5"));
items.add(new SwitchItem("xtempl_MotionItem"));
items.add(new SwitchItem("xtempl_LampItem"));
return items;
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<Item> listener) {
}
};
registerService(itemProvider);
registerVolatileStorageService();
StorageService storageService = getService(StorageService.class);
eventPublisher = getService(EventPublisher.class);
itemRegistry = getService(ItemRegistry.class);
ruleRegistry = getService(RuleRegistry.class);
ruleEngine = getService(RuleManager.class);
managedRuleProvider = getService(ManagedRuleProvider.class);
moduleTypeRegistry = getService(ModuleTypeRegistry.class);
templateRegistry = getService(TemplateRegistry.class);
waitForAssert(() -> {
assertThat(eventPublisher, is(notNullValue()));
assertThat(storageService, is(notNullValue()));
assertThat(itemRegistry, is(notNullValue()));
assertThat(ruleRegistry, is(notNullValue()));
assertThat(ruleEngine, is(notNullValue()));
assertThat(moduleTypeRegistry, is(notNullValue()));
assertThat(templateRegistry, is(notNullValue()));
assertThat(managedRuleProvider, is(notNullValue()));
}, 9000, 1000);
// start rule engine
((RuleEngineImpl) ruleEngine).onReadyMarkerAdded(new ReadyMarker("", ""));
waitForAssert(() -> {
assertThat(((RuleEngineImpl) ruleEngine).isStarted(), is(true));
}, 5000, 1000);
logger.info("@Before.finish");
}
Aggregations