Skip to content

Commit

Permalink
[dbquery] Fix thing action annotation (#17784)
Browse files Browse the repository at this point in the history
Related to #17504

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo authored Nov 22, 2024
1 parent 511fab7 commit fd092a2
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.openhab.binding.dbquery.internal.domain.ResultRow;
import org.openhab.binding.dbquery.internal.error.UnnexpectedCondition;
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.thing.binding.ThingActions;
import org.openhab.core.thing.binding.ThingActionsScope;
Expand All @@ -49,8 +50,10 @@ public class DBQueryActions implements IDBQueryActions, ThingActions {

@Override
@RuleAction(label = "Execute query", description = "Execute query synchronously (use with care)")
public ActionQueryResult executeQuery(String query, Map<String, @Nullable Object> parameters,
int timeoutInSeconds) {
public @ActionOutput(label = "Result", type = "org.openhab.binding.dbquery.action.ActionQueryResult") ActionQueryResult executeQuery(
@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);
var currentDatabaseBridgeHandler = databaseBridgeHandler;
if (currentDatabaseBridgeHandler != null) {
Expand Down Expand Up @@ -91,7 +94,7 @@ public void setQueryParameters(@ActionInput(name = "parameters") Map<String, @Nu

@Override
@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;
if (currentQueryHandler != null) {
return queryResult2ActionQueryResult(queryHandler.getLastQueryResult());
Expand All @@ -101,6 +104,19 @@ public ActionQueryResult getLastQueryResult() {
}
}

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
public void setThingHandler(ThingHandler thingHandler) {
if (thingHandler instanceof QueryHandler queryHandler) {
Expand Down

0 comments on commit fd092a2

Please sign in to comment.