use of org.eclipse.smarthome.automation.annotation.RuleAction in project smarthome by eclipse.
the class MQTTActions method publishMQTT.
@RuleAction(label = "@text/actionLabel", description = "@text/actionDesc")
public void publishMQTT(@ActionInput(name = "topic", label = "@text/actionInputTopicLabel", description = "@text/actionInputTopicDesc") @Nullable String topic, @ActionInput(name = "value", label = "@text/actionInputValueLabel", description = "@text/actionInputValueDesc") @Nullable String value) {
AbstractBrokerHandler brokerHandler = handler;
if (brokerHandler == null) {
logger.warn("MQTT Action service ThingHandler is null!");
return;
}
MqttBrokerConnection connection = brokerHandler.getConnection();
if (connection == null) {
logger.warn("MQTT Action service ThingHandler connection is null!");
return;
}
if (value == null) {
logger.debug("skipping MQTT publishing to topic '{}' due to null value.", topic);
return;
}
if (topic == null) {
logger.debug("skipping MQTT publishing of value '{}' as topic is null.", value);
return;
}
connection.publish(topic, value.getBytes()).thenRun(() -> {
logger.debug("MQTT publish to {} performed", topic);
}).exceptionally(e -> {
logger.warn("MQTT publish to {} failed!", topic);
return null;
});
}
use of org.eclipse.smarthome.automation.annotation.RuleAction in project smarthome by eclipse.
the class AnnotationActionModuleTypeHelper method parseAnnotations.
@SuppressWarnings({ "rawtypes" })
public Collection<ModuleInformation> parseAnnotations(String name, Object actionProvider) {
Collection<ModuleInformation> moduleInformation = new ArrayList<>();
Class clazz = actionProvider.getClass();
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(RuleAction.class)) {
List<Input> inputs = getInputsFromAction(method);
List<Output> outputs = getOutputsFromMethod(method);
RuleAction ruleAction = method.getAnnotation(RuleAction.class);
String uid = name + "." + method.getName();
Set<String> tags = new HashSet<>(Arrays.asList(ruleAction.tags()));
ModuleInformation mi = new ModuleInformation(uid, actionProvider, method);
mi.setLabel(ruleAction.label());
mi.setDescription(ruleAction.description());
mi.setVisibility(ruleAction.visibility());
mi.setInputs(inputs);
mi.setOutputs(outputs);
mi.setTags(tags);
moduleInformation.add(mi);
}
}
return moduleInformation;
}
Aggregations