mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-27 07:41:39 +01:00
[dbquery] Fix thing action annotation (#17784)
Related to #17504 Signed-off-by: Laurent Garnier <lg.hc@free.fr> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
a91fdaab16
commit
baad61d614
@ -26,6 +26,7 @@ import org.openhab.binding.dbquery.internal.domain.QueryResult;
|
|||||||
import org.openhab.binding.dbquery.internal.domain.ResultRow;
|
import org.openhab.binding.dbquery.internal.domain.ResultRow;
|
||||||
import org.openhab.binding.dbquery.internal.error.UnnexpectedCondition;
|
import org.openhab.binding.dbquery.internal.error.UnnexpectedCondition;
|
||||||
import org.openhab.core.automation.annotation.ActionInput;
|
import org.openhab.core.automation.annotation.ActionInput;
|
||||||
|
import org.openhab.core.automation.annotation.ActionOutput;
|
||||||
import org.openhab.core.automation.annotation.RuleAction;
|
import org.openhab.core.automation.annotation.RuleAction;
|
||||||
import org.openhab.core.thing.binding.ThingActions;
|
import org.openhab.core.thing.binding.ThingActions;
|
||||||
import org.openhab.core.thing.binding.ThingActionsScope;
|
import org.openhab.core.thing.binding.ThingActionsScope;
|
||||||
@ -49,8 +50,10 @@ public class DBQueryActions implements IDBQueryActions, ThingActions {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@RuleAction(label = "Execute query", description = "Execute query synchronously (use with care)")
|
@RuleAction(label = "Execute query", description = "Execute query synchronously (use with care)")
|
||||||
public ActionQueryResult executeQuery(String query, Map<String, @Nullable Object> parameters,
|
public @ActionOutput(label = "Result", type = "org.openhab.binding.dbquery.action.ActionQueryResult") ActionQueryResult executeQuery(
|
||||||
int timeoutInSeconds) {
|
@ActionInput(name = "query") String query,
|
||||||
|
@ActionInput(name = "parameters") Map<String, @Nullable Object> parameters,
|
||||||
|
@ActionInput(name = "timeoutInSeconds") int timeoutInSeconds) {
|
||||||
logger.debug("executeQuery from action {} params={}", query, parameters);
|
logger.debug("executeQuery from action {} params={}", query, parameters);
|
||||||
var currentDatabaseBridgeHandler = databaseBridgeHandler;
|
var currentDatabaseBridgeHandler = databaseBridgeHandler;
|
||||||
if (currentDatabaseBridgeHandler != null) {
|
if (currentDatabaseBridgeHandler != null) {
|
||||||
@ -91,7 +94,7 @@ public class DBQueryActions implements IDBQueryActions, ThingActions {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@RuleAction(label = "Get last query result", description = "Get last result from a query")
|
@RuleAction(label = "Get last query result", description = "Get last result from a query")
|
||||||
public ActionQueryResult getLastQueryResult() {
|
public @ActionOutput(label = "Result", type = "org.openhab.binding.dbquery.action.ActionQueryResult") ActionQueryResult getLastQueryResult() {
|
||||||
var currentQueryHandler = queryHandler;
|
var currentQueryHandler = queryHandler;
|
||||||
if (currentQueryHandler != null) {
|
if (currentQueryHandler != null) {
|
||||||
return queryResult2ActionQueryResult(queryHandler.getLastQueryResult());
|
return queryResult2ActionQueryResult(queryHandler.getLastQueryResult());
|
||||||
@ -101,6 +104,19 @@ public class DBQueryActions implements IDBQueryActions, ThingActions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ActionQueryResult executeQuery(ThingActions actions, String query,
|
||||||
|
Map<String, @Nullable Object> parameters, int timeoutInSeconds) {
|
||||||
|
return ((DBQueryActions) actions).executeQuery(query, parameters, timeoutInSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setQueryParameters(ThingActions actions, Map<String, @Nullable Object> parameters) {
|
||||||
|
((DBQueryActions) actions).setQueryParameters(parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ActionQueryResult getLastQueryResult(ThingActions actions) {
|
||||||
|
return ((DBQueryActions) actions).getLastQueryResult();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setThingHandler(ThingHandler thingHandler) {
|
public void setThingHandler(ThingHandler thingHandler) {
|
||||||
if (thingHandler instanceof QueryHandler queryHandler) {
|
if (thingHandler instanceof QueryHandler queryHandler) {
|
||||||
|
Loading…
Reference in New Issue
Block a user