Rework ThingActions (#8732)

* Remove proxy workarounds
* Move ThingActions and a few other classes into the internal package
* Use more consistent action labels/descriptions

Related to:

* openhab/openhab-core#1714
* openhab/openhab-core#1639

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born
2020-10-14 19:01:12 +02:00
committed by GitHub
parent 4adc214c69
commit bef1046258
86 changed files with 708 additions and 2096 deletions

View File

@@ -1,29 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.satel.action;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* Automation action handler interface for reading Satel event log.
*
* @author Krzysztof Goworek - Initial contribution
*/
@NonNullByDefault
public interface ISatelEventLogActions {
public Map<String, Object> readEvent(@Nullable Number index);
}

View File

@@ -10,10 +10,8 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.satel.action;
package org.openhab.binding.satel.internal.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;
@@ -37,7 +35,7 @@ import org.slf4j.LoggerFactory;
*/
@ThingActionsScope(name = "satel")
@NonNullByDefault
public class SatelEventLogActions implements ThingActions, ISatelEventLogActions {
public class SatelEventLogActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(getClass());
@@ -55,7 +53,6 @@ public class SatelEventLogActions implements ThingActions, ISatelEventLogActions
return handler;
}
@Override
@RuleAction(label = "@text/actionReadEventLabel", description = "@text/actionReadEventDesc")
public @ActionOutput(name = "index", type = "java.lang.Integer", label = "@text/actionOutputIndexLabel", description = "@text/actionOutputIndexDesc") @ActionOutput(name = "prev_index", type = "java.lang.Integer", label = "@text/actionOutputPrevIndexLabel", description = "@text/actionOutputPrevIndexDesc") @ActionOutput(name = "timestamp", type = "java.time.ZonedDateTime", label = "@text/actionOutputTimestampLabel", description = "@text/actionOutputTimestampDesc") @ActionOutput(name = "description", type = "java.lang.String", label = "@text/actionOutputDescriptionLabel", description = "@text/actionOutputDescriptionDesc") @ActionOutput(name = "details", type = "java.lang.String", label = "@text/actionOutputDetailsLabel", description = "@text/actionOutputDetailsDesc") Map<String, Object> readEvent(
@ActionInput(name = "index", label = "@text/actionInputIndexLabel", description = "@text/actionInputIndexDesc") @Nullable Number index) {
@@ -75,21 +72,10 @@ public class SatelEventLogActions implements ThingActions, ISatelEventLogActions
}
public static Map<String, Object> readEvent(@Nullable ThingActions actions, @Nullable Number index) {
return invokeMethodOf(actions).readEvent(index);
}
private static ISatelEventLogActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
} else if (actions instanceof ISatelEventLogActions) {
return (ISatelEventLogActions) actions;
} else if (actions.getClass().getName().equals(SatelEventLogActions.class.getName())) {
return (ISatelEventLogActions) Proxy.newProxyInstance(ISatelEventLogActions.class.getClassLoader(),
new Class[] { ISatelEventLogActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(), method.getParameterTypes());
return m.invoke(actions, args);
});
if (actions instanceof SatelEventLogActions) {
return ((SatelEventLogActions) actions).readEvent(index);
} else {
throw new IllegalArgumentException("Actions is not an instance of SatelEventLogActions");
}
throw new IllegalArgumentException("actions is not an instance of ISatelEventLogActions");
}
}

View File

@@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.satel.action.SatelEventLogActions;
import org.openhab.binding.satel.internal.action.SatelEventLogActions;
import org.openhab.binding.satel.internal.command.ReadDeviceInfoCommand;
import org.openhab.binding.satel.internal.command.ReadDeviceInfoCommand.DeviceType;
import org.openhab.binding.satel.internal.command.ReadEventCommand;