Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dbquery] Fix Thing Action support for DSL rules #17784

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}

lsiepel marked this conversation as resolved.
Show resolved Hide resolved
@Override
public void setThingHandler(ThingHandler thingHandler) {
if (thingHandler instanceof QueryHandler queryHandler) {
Expand Down