use of org.eclipse.smarthome.automation.core.ManagedRuleProvider in project smarthome by eclipse.
the class RuleRegistryImpl method addProvider.
@Override
protected void addProvider(Provider<Rule> provider) {
super.addProvider(provider);
forEach(provider, rule -> {
try {
Rule resolvedRule = resolveRuleByTemplate(rule);
if (rule != resolvedRule && provider instanceof ManagedRuleProvider) {
update(resolvedRule);
}
} catch (IllegalArgumentException e) {
logger.error("Added rule '{}' is invalid", rule.getUID(), e);
}
});
}
use of org.eclipse.smarthome.automation.core.ManagedRuleProvider in project smarthome by eclipse.
the class RuleRegistryImpl method added.
@Override
public void added(RuleTemplate element) {
String templateUID = element.getUID();
Set<String> rules = new HashSet<String>();
synchronized (this) {
Set<String> rulesForResolving = mapTemplateToRules.get(templateUID);
if (rulesForResolving != null) {
rules.addAll(rulesForResolving);
}
}
for (String rUID : rules) {
try {
Rule unresolvedRule = get(rUID);
Rule resolvedRule = resolveRuleByTemplate(unresolvedRule);
Provider<Rule> provider = getProvider(rUID);
if (provider instanceof ManagedRuleProvider) {
update(resolvedRule);
} else {
updated(provider, unresolvedRule, unresolvedRule);
}
} catch (IllegalArgumentException e) {
logger.error("Resolving the rule '{}' by template '{}' failed", rUID, templateUID, e);
}
}
}
use of org.eclipse.smarthome.automation.core.ManagedRuleProvider in project smarthome by eclipse.
the class AutomationIntegrationTest method before.
@Before
public void before() {
logger.info("@Before.begin");
getService(ItemRegistry.class);
ItemProvider itemProvider = new ItemProvider() {
@Override
public void addProviderChangeListener(@NonNull ProviderChangeListener<@NonNull Item> listener) {
}
@Override
@NonNull
public Collection<@NonNull 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(@NonNull ProviderChangeListener<@NonNull 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);
logger.info("@Before.finish");
}
use of org.eclipse.smarthome.automation.core.ManagedRuleProvider in project smarthome by eclipse.
the class RuleRegistryImpl method added.
@Override
public void added(Provider<Rule> provider, Rule element) {
String ruleUID = element.getUID();
Rule resolvedRule = element;
try {
resolvedRule = resolveRuleByTemplate(element);
} catch (IllegalArgumentException e) {
logger.debug("Added rule '{}' is invalid", ruleUID, e);
}
super.added(provider, element);
if (element != resolvedRule) {
if (provider instanceof ManagedRuleProvider) {
update(resolvedRule);
} else {
super.updated(provider, element, resolvedRule);
}
}
}
use of org.eclipse.smarthome.automation.core.ManagedRuleProvider in project smarthome by eclipse.
the class AutomationIntegrationJsonTest method before.
// rules imported from
// json files
@Before
public void before() {
logger.info("@Before.begin");
getService(ItemRegistry.class);
ItemProvider itemProvider = new ItemProvider() {
@Override
public void addProviderChangeListener(@NonNull ProviderChangeListener<@NonNull Item> listener) {
}
@Override
@NonNull
public Collection<@NonNull Item> getAll() {
HashSet<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("myMotionItem11"));
items.add(new SwitchItem("myLampItem11"));
items.add(new SwitchItem("myMotionItem3"));
items.add(new SwitchItem("templ_MotionItem"));
items.add(new SwitchItem("templ_LampItem"));
return items;
}
@Override
public void removeProviderChangeListener(@NonNull ProviderChangeListener<@NonNull Item> listener) {
}
};
registerService(itemProvider);
registerVolatileStorageService();
EventSubscriber ruleEventHandler = new EventSubscriber() {
@Override
@NonNull
public Set<@NonNull String> getSubscribedEventTypes() {
return Collections.singleton(RuleStatusInfoEvent.TYPE);
}
@Override
@Nullable
public EventFilter getEventFilter() {
return null;
}
@Override
public void receive(@NonNull Event e) {
logger.info("RuleEvent: " + e.getTopic() + " --> " + e.getPayload());
System.out.println("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);
logger.info("@Before.finish");
}
Aggregations