diff --git a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/actions/BridgeActions.java b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/actions/BridgeActions.java index bbcd10401..658f97817 100644 --- a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/actions/BridgeActions.java +++ b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/actions/BridgeActions.java @@ -12,9 +12,6 @@ */ package org.openhab.binding.alarmdecoder.internal.actions; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; - import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.alarmdecoder.internal.handler.ADBridgeHandler; @@ -33,7 +30,7 @@ import org.slf4j.LoggerFactory; */ @ThingActionsScope(name = "alarmdecoder") @NonNullByDefault -public class BridgeActions implements ThingActions, IBridgeActions { +public class BridgeActions implements ThingActions { private final Logger logger = LoggerFactory.getLogger(BridgeActions.class); @@ -58,8 +55,7 @@ public class BridgeActions implements ThingActions, IBridgeActions { /** * Reboot thing action */ - @Override - @RuleAction(label = "Reboot", description = "Reboot the Alarm Decoder device") + @RuleAction(label = "reboot the device", description = "Reboot the Alarm Decoder device.") public void reboot() { ADBridgeHandler bridge = this.bridge; if (bridge != null) { @@ -72,34 +68,10 @@ public class BridgeActions implements ThingActions, IBridgeActions { // Static method for Rules DSL backward compatibility public static void reboot(@Nullable ThingActions actions) { - // if (actions instanceof BridgeActions) { - // ((BridgeActions) actions).reboot(); - // } else { - // throw new IllegalArgumentException("Instance is not a BridgeActions class."); - // } - invokeMethodOf(actions).reboot(); // Remove and uncomment above when core issue #1536 is fixed - } - - /** - * This is only necessary to work around a bug in openhab-core (issue #1536). It should be removed once that is - * resolved. - */ - private static IBridgeActions invokeMethodOf(@Nullable ThingActions actions) { - if (actions == null) { - throw new IllegalArgumentException("actions cannot be null"); + if (actions instanceof BridgeActions) { + ((BridgeActions) actions).reboot(); + } else { + throw new IllegalArgumentException("Actions is not an instance of BridgeActions"); } - if (actions.getClass().getName().equals(BridgeActions.class.getName())) { - if (actions instanceof IBridgeActions) { - return (IBridgeActions) actions; - } else { - return (IBridgeActions) Proxy.newProxyInstance(IBridgeActions.class.getClassLoader(), - new Class[] { IBridgeActions.class }, (Object proxy, Method method, Object[] args) -> { - Method m = actions.getClass().getDeclaredMethod(method.getName(), - method.getParameterTypes()); - return m.invoke(actions, args); - }); - } - } - throw new IllegalArgumentException("Actions is not an instance of BridgeActions"); } } diff --git a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/actions/IBridgeActions.java b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/actions/IBridgeActions.java deleted file mode 100644 index 849ca7c11..000000000 --- a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/actions/IBridgeActions.java +++ /dev/null @@ -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.alarmdecoder.internal.actions; - -import org.eclipse.jdt.annotation.NonNullByDefault; - -/** - * The {@link IBridgeActions} defines the interface for all thing actions supported by the bridges. - * This is only necessary to work around a bug in openhab-core (issue #1536). It should be removed once that is - * resolved. - * - * @author Bob Adair - Initial contribution - * - */ -@NonNullByDefault -public interface IBridgeActions { - - public void reboot(); -} diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/action/AstroActions.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/action/AstroActions.java index 202135e92..f8415c5e6 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/action/AstroActions.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/action/AstroActions.java @@ -12,8 +12,6 @@ */ package org.openhab.binding.astro.internal.action; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; import java.time.ZonedDateTime; import javax.measure.quantity.Angle; @@ -35,18 +33,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * The {AstroActions } defines rule actions for the Astro binding. - *
- * Note:The static method invokeMethodOf handles the case where
- * the test actions instanceof AstroActions fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link AstroActions} class
- * can be loaded by a different classloader than the actions instance.
+ * Defines the automation thing actions for the Astro binding.
*
* @author Gaël L'hopital - Initial contribution
*/
@ThingActionsScope(name = "astro")
@NonNullByDefault
-public class AstroActions implements ThingActions, IAstroActions {
+public class AstroActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(AstroActions.class);
protected @Nullable AstroThingHandler handler;
@@ -64,11 +57,10 @@ public class AstroActions implements ThingActions, IAstroActions {
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
+ return handler;
}
- @Override
- @RuleAction(label = "Astro : Get Azimuth", description = "Get the azimuth of the sun for a given time")
+ @RuleAction(label = "get the azimuth", description = "Get the azimuth for a given time.")
public @Nullable @ActionOutput(name = "getAzimuth", label = "Azimuth", type = "org.openhab.core.library.types.QuantityType
- * Note:The static method invokeMethodOf handles the case where
- * the test actions instanceof DmxActions fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link DmxActions} class
- * can be loaded by a different classloader than the actions instance.
*
* @author Jan N. Klug - Initial contribution
*/
-
@ThingActionsScope(name = "dmx")
@NonNullByDefault
-public class DmxActions implements ThingActions, IDmxActions {
+public class DmxActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(DmxActions.class);
private @Nullable DmxBridgeHandler handler;
- @Override
- @RuleAction(label = "DMX Output", description = "immediately performs fade on selected DMX channels")
+ @RuleAction(label = "immediately fade channels", description = "Immediately performs fade on selected DMX channels.")
public void sendFade(@ActionInput(name = "channels") @Nullable String channels,
@ActionInput(name = "fade") @Nullable String fade,
@ActionInput(name = "resumeAfter") @Nullable Boolean resumeAfter) {
logger.debug("thingHandlerAction called with inputs: {} {} {}", channels, fade, resumeAfter);
+ DmxBridgeHandler handler = this.handler;
if (handler == null) {
logger.warn("DMX Action service ThingHandler is null!");
@@ -77,26 +68,11 @@ public class DmxActions implements ThingActions, IDmxActions {
public static void sendFade(@Nullable ThingActions actions, @Nullable String channels, @Nullable String fade,
@Nullable Boolean resumeAfter) {
- invokeMethodOf(actions).sendFade(channels, fade, resumeAfter);
- }
-
- private static IDmxActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
+ if (actions instanceof DmxActions) {
+ ((DmxActions) actions).sendFade(channels, fade, resumeAfter);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of DmxActions");
}
- if (actions.getClass().getName().equals(DmxActions.class.getName())) {
- if (actions instanceof IDmxActions) {
- return (IDmxActions) actions;
- } else {
- return (IDmxActions) Proxy.newProxyInstance(IDmxActions.class.getClassLoader(),
- new Class[] { IDmxActions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of DmxActions");
}
@Override
@@ -108,6 +84,6 @@ public class DmxActions implements ThingActions, IDmxActions {
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
+ return handler;
}
}
diff --git a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/action/IDoorbirdActions.java b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/action/IDoorbirdActions.java
deleted file mode 100644
index 928604654..000000000
--- a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/action/IDoorbirdActions.java
+++ /dev/null
@@ -1,37 +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.doorbird.action;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-/**
- * The {@link IDoorbirdActions} defines the interface for all thing actions supported by the binding.
- * These methods, parameters, and return types are explained in {@link DoorbirdActions}.
- *
- * @author Mark Hilbush - Initial contribution
- */
-@NonNullByDefault
-public interface IDoorbirdActions {
-
- public void restart();
-
- public void sipHangup();
-
- public String getRingTimeLimit();
-
- public String getCallTimeLimit();
-
- public String getLastErrorCode();
-
- public String getLastErrorText();
-}
diff --git a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/action/DoorbirdActions.java b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java
similarity index 52%
rename from bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/action/DoorbirdActions.java
rename to bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java
index d6095a8d4..389a7bd58 100644
--- a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/action/DoorbirdActions.java
+++ b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java
@@ -10,10 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.doorbird.action;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
+package org.openhab.binding.doorbird.internal.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -34,12 +31,12 @@ import org.slf4j.LoggerFactory;
@ThingActionsScope(name = "doorbird")
@NonNullByDefault
public class DoorbirdActions implements ThingActions {
- private static final Logger LOGGER = LoggerFactory.getLogger(DoorbirdActions.class);
+ private final Logger logger = LoggerFactory.getLogger(DoorbirdActions.class);
private @Nullable DoorbellHandler handler;
public DoorbirdActions() {
- LOGGER.debug("DoorbirdActions service created");
+ logger.debug("DoorbirdActions service created");
}
@Override
@@ -51,113 +48,118 @@ public class DoorbirdActions implements ThingActions {
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
+ return handler;
}
- private static IDoorbirdActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
- }
- if (actions.getClass().getName().equals(DoorbirdActions.class.getName())) {
- if (actions instanceof IDoorbirdActions) {
- return (IDoorbirdActions) actions;
- } else {
- return (IDoorbirdActions) Proxy.newProxyInstance(IDoorbirdActions.class.getClassLoader(),
- new Class[] { IDoorbirdActions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("actions is not an instance of DoorbirdActions");
- }
-
- @RuleAction(label = "Restart Doorbird", description = "Restarts the Doorbird device")
+ @RuleAction(label = "restart the Doorbird", description = "Restarts the Doorbird device.")
public void restart() {
- LOGGER.debug("Doorbird action 'restart' called");
+ logger.debug("Doorbird action 'restart' called");
if (handler != null) {
handler.actionRestart();
} else {
- LOGGER.info("Doorbird Action service ThingHandler is null!");
+ logger.info("Doorbird Action service ThingHandler is null!");
}
}
public static void restart(@Nullable ThingActions actions) {
- invokeMethodOf(actions).restart();
+ if (actions instanceof DoorbirdActions) {
+ ((DoorbirdActions) actions).restart();
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
+ }
}
- @RuleAction(label = "SIP Hangup", description = "Hangup SIP call")
+ @RuleAction(label = "hangup a SIP call", description = "Hangup SIP call.")
public void sipHangup() {
- LOGGER.debug("Doorbird action 'sipHangup' called");
+ logger.debug("Doorbird action 'sipHangup' called");
if (handler != null) {
handler.actionSIPHangup();
} else {
- LOGGER.info("Doorbird Action service ThingHandler is null!");
+ logger.info("Doorbird Action service ThingHandler is null!");
}
}
public static void sipHangup(@Nullable ThingActions actions) {
- invokeMethodOf(actions).sipHangup();
+ if (actions instanceof DoorbirdActions) {
+ ((DoorbirdActions) actions).sipHangup();
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
+ }
}
- @RuleAction(label = "Get Ring Time Limit", description = "Get the value of RING_TIME_LIMIT")
+ @RuleAction(label = "get the ring time limit", description = "Get the value of RING_TIME_LIMIT.")
public @ActionOutput(name = "getRingTimeLimit", type = "java.lang.String") String getRingTimeLimit() {
- LOGGER.debug("Doorbird action 'getRingTimeLimit' called");
+ logger.debug("Doorbird action 'getRingTimeLimit' called");
if (handler != null) {
return handler.actionGetRingTimeLimit();
} else {
- LOGGER.info("Doorbird Action service ThingHandler is null!");
+ logger.info("Doorbird Action service ThingHandler is null!");
return "";
}
}
public static String getRingTimeLimit(@Nullable ThingActions actions) {
- return invokeMethodOf(actions).getRingTimeLimit();
+ if (actions instanceof DoorbirdActions) {
+ return ((DoorbirdActions) actions).getRingTimeLimit();
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
+ }
}
- @RuleAction(label = "Get Call Time Limit", description = "Get the value of CALL_TIME_LIMIT")
+ @RuleAction(label = "get the call time limit", description = "Get the value of CALL_TIME_LIMIT.")
public @ActionOutput(name = "getCallTimeLimit", type = "java.lang.String") String getCallTimeLimit() {
- LOGGER.debug("Doorbird action 'getCallTimeLimit' called");
+ logger.debug("Doorbird action 'getCallTimeLimit' called");
if (handler != null) {
return handler.actionGetCallTimeLimit();
} else {
- LOGGER.info("Doorbird Action service ThingHandler is null!");
+ logger.info("Doorbird Action service ThingHandler is null!");
return "";
}
}
public static String getCallTimeLimit(@Nullable ThingActions actions) {
- return invokeMethodOf(actions).getCallTimeLimit();
+ if (actions instanceof DoorbirdActions) {
+ return ((DoorbirdActions) actions).getCallTimeLimit();
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
+ }
}
- @RuleAction(label = "Get Last Error Code", description = "Get the value of LASTERRORCODE")
+ @RuleAction(label = "get the last error code", description = "Get the value of LASTERRORCODE.")
public @ActionOutput(name = "getLastErrorCode", type = "java.lang.String") String getLastErrorCode() {
- LOGGER.debug("Doorbird action 'getLastErrorCode' called");
+ logger.debug("Doorbird action 'getLastErrorCode' called");
if (handler != null) {
return handler.actionGetLastErrorCode();
} else {
- LOGGER.info("Doorbird Action service ThingHandler is null!");
+ logger.info("Doorbird Action service ThingHandler is null!");
return "";
}
}
public static String getLastErrorCode(@Nullable ThingActions actions) {
- return invokeMethodOf(actions).getLastErrorCode();
+ if (actions instanceof DoorbirdActions) {
+ return ((DoorbirdActions) actions).getLastErrorCode();
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
+ }
}
- @RuleAction(label = "Get Last Error Text", description = "Get the value of LASTERRORTEXT")
+ @RuleAction(label = "get the last error text", description = "Get the value of LASTERRORTEXT.")
public @ActionOutput(name = "getLastErrorText", type = "java.lang.String") String getLastErrorText() {
- LOGGER.debug("Doorbird action 'getLastErrorText' called");
+ logger.debug("Doorbird action 'getLastErrorText' called");
if (handler != null) {
return handler.actionGetLastErrorText();
} else {
- LOGGER.info("Doorbird Action service ThingHandler is null!");
+ logger.info("Doorbird Action service ThingHandler is null!");
return "";
}
}
public static String getLastErrorText(@Nullable ThingActions actions) {
- return invokeMethodOf(actions).getLastErrorText();
+ if (actions instanceof DoorbirdActions) {
+ return ((DoorbirdActions) actions).getLastErrorText();
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
+ }
}
}
diff --git a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/handler/DoorbellHandler.java b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/handler/DoorbellHandler.java
index 1db3f4924..f5017578d 100644
--- a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/handler/DoorbellHandler.java
+++ b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/handler/DoorbellHandler.java
@@ -33,7 +33,7 @@ import javax.imageio.ImageIO;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
-import org.openhab.binding.doorbird.action.DoorbirdActions;
+import org.openhab.binding.doorbird.internal.action.DoorbirdActions;
import org.openhab.binding.doorbird.internal.api.DoorbirdAPI;
import org.openhab.binding.doorbird.internal.api.DoorbirdImage;
import org.openhab.binding.doorbird.internal.api.SipStatus;
diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/action/IEcobeeActions.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/action/IEcobeeActions.java
deleted file mode 100644
index 3ed103c27..000000000
--- a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/action/IEcobeeActions.java
+++ /dev/null
@@ -1,78 +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.ecobee.action;
-
-import java.util.Date;
-import java.util.Map;
-
-import javax.measure.quantity.Temperature;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.core.library.types.QuantityType;
-
-/**
- * The {@link IEcobeeActions} defines the interface for all thing actions supported by the binding.
- * These methods, parameters, and return types are explained in {@link EcobeeActions}.
- *
- * @author Mark Hilbush - Initial contribution
- */
-@NonNullByDefault
-public interface IEcobeeActions {
-
- public Boolean acknowledge(@Nullable String ackRef, @Nullable String ackType, @Nullable Boolean remindMeLater);
-
- public Boolean controlPlug(@Nullable String plugName, @Nullable String plugState, @Nullable Date startDateTime,
- @Nullable Date endDateTime, @Nullable String holdType, @Nullable Number holdHours);
-
- public Boolean sendMessage(@Nullable String text);
-
- public Boolean createVacation(@Nullable String name, @Nullable QuantityType
- * Note:The static method invokeMethod handles the case where
- * the test actions instanceof EcobeeActions fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link EcobeeActions} class
- * can be loaded by a different classloader than the actions instance.
*
* @author John Cocula - Initial contribution
* @author Mark Hilbush - Adapted for OH2/3
@@ -64,7 +57,7 @@ import org.slf4j.LoggerFactory;
*/
@ThingActionsScope(name = "ecobee")
@NonNullByDefault
-public class EcobeeActions implements ThingActions, IEcobeeActions {
+public class EcobeeActions implements ThingActions {
private static final Logger LOGGER = LoggerFactory.getLogger(EcobeeActions.class);
@@ -83,26 +76,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
- }
-
- private static IEcobeeActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
- }
- if (actions.getClass().getName().equals(EcobeeActions.class.getName())) {
- if (actions instanceof IEcobeeActions) {
- return (IEcobeeActions) actions;
- } else {
- return (IEcobeeActions) Proxy.newProxyInstance(IEcobeeActions.class.getClassLoader(),
- new Class[] { IEcobeeActions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
+ return handler;
}
/**
@@ -112,8 +86,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
* href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/Acknowledge.shtml">Acknowledge
*
*/
- @Override
- @RuleAction(label = "Acknowledge", description = "Acknowledges an alert.")
+ @RuleAction(label = "acknowledge an alert", description = "Acknowledges an alert.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean acknowledge(
@ActionInput(name = "ackRef", description = "The acknowledge ref of alert") @Nullable String ackRef,
@ActionInput(name = "ackType", description = "The type of acknowledgement. Valid values: accept, decline, defer, unacknowledged") @Nullable String ackType,
@@ -131,7 +104,11 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
public static boolean acknowledge(@Nullable ThingActions actions, @Nullable String ackRef, @Nullable String ackType,
@Nullable Boolean remindMeLater) {
- return invokeMethodOf(actions).acknowledge(ackRef, ackType, remindMeLater);
+ if (actions instanceof EcobeeActions) {
+ return ((EcobeeActions) actions).acknowledge(ackRef, ackType, remindMeLater);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
+ }
}
/**
@@ -140,8 +117,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
* @see Control
* Plug
*/
- @Override
- @RuleAction(label = "Control Plug", description = "Control the on/off state of a plug by setting a hold on the plug.")
+ @RuleAction(label = "control a plug", description = "Control the on/off state of a plug by setting a hold on the plug.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean controlPlug(
@ActionInput(name = "plugName", description = "The name of the plug. Ensure each plug has a unique name.") @Nullable String plugName,
@ActionInput(name = "plugState", description = "The state to put the plug into. Valid values: on, off, resume.") @Nullable String plugState,
@@ -164,8 +140,12 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
public static boolean controlPlug(@Nullable ThingActions actions, @Nullable String plugName,
@Nullable String plugState, @Nullable Date startDateTime, @Nullable Date endDateTime,
@Nullable String holdType, @Nullable Number holdHours) {
- return invokeMethodOf(actions).controlPlug(plugName, plugState, startDateTime, endDateTime, holdType,
- holdHours);
+ if (actions instanceof EcobeeActions) {
+ return ((EcobeeActions) actions).controlPlug(plugName, plugState, startDateTime, endDateTime, holdType,
+ holdHours);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
+ }
}
/**
@@ -174,8 +154,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
* @see Create
* Vacation
*/
- @Override
- @RuleAction(label = "Create Vacation", description = "The create vacation function creates a vacation event on the thermostat.")
+ @RuleAction(label = "create a vacation", description = "The create vacation function creates a vacation event on the thermostat.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean createVacation(
@ActionInput(name = "name", description = "The vacation event name. It must be unique.") @Nullable String name,
@ActionInput(name = "coolHoldTemp", description = "The temperature at which to set the cool vacation hold.") @Nullable QuantityType
- * Note:The static method invokeMethodOf handles the case where
- * the test actions instanceof Ipx800Actions fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link Ipx800Actions} class
- * can be loaded by a different classloader than the actions instance.
+ * Defines rule actions for the GCE binding.
*
* @author Gaël L'hopital - Initial contribution
*/
@ThingActionsScope(name = "gce")
@NonNullByDefault
-public class Ipx800Actions implements ThingActions, IIpx800Actions {
+public class Ipx800Actions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(Ipx800Actions.class);
protected @Nullable Ipx800v3Handler handler;
@@ -56,11 +48,10 @@ public class Ipx800Actions implements ThingActions, IIpx800Actions {
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
+ return handler;
}
- @Override
- @RuleAction(label = "GCE : Reset counter", description = "Resets to 0 value of a given counter")
+ @RuleAction(label = "reset a counter", description = "Resets to 0 value of a given counter.")
public void resetCounter(
@ActionInput(name = "counter", label = "Counter", required = true, description = "Id of the counter", type = "java.lang.Integer") Integer counter) {
logger.debug("IPX800 action 'resetCounter' called");
@@ -72,8 +63,7 @@ public class Ipx800Actions implements ThingActions, IIpx800Actions {
}
}
- @Override
- @RuleAction(label = "GCE : Reset PLC", description = "Restarts the IPX800")
+ @RuleAction(label = "reset the PLC", description = "Restarts the IPX800.")
public void reset(
@ActionInput(name = "placeholder", label = "Placeholder", required = false, description = "This parameter is not used", type = "java.lang.Integer") @Nullable Integer placeholder) {
logger.debug("IPX800 action 'reset' called");
@@ -86,29 +76,18 @@ public class Ipx800Actions implements ThingActions, IIpx800Actions {
}
public static void resetCounter(@Nullable ThingActions actions, Integer counter) {
- invokeMethodOf(actions).resetCounter(counter);
+ if (actions instanceof Ipx800Actions) {
+ ((Ipx800Actions) actions).resetCounter(counter);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of Ipx800Actions");
+ }
}
public static void reset(@Nullable ThingActions actions, @Nullable Integer placeholder) {
- invokeMethodOf(actions).reset(placeholder);
- }
-
- private static IIpx800Actions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
+ if (actions instanceof Ipx800Actions) {
+ ((Ipx800Actions) actions).reset(placeholder);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of Ipx800Actions");
}
- if (actions.getClass().getName().equals(Ipx800Actions.class.getName())) {
- if (actions instanceof IIpx800Actions) {
- return (IIpx800Actions) actions;
- } else {
- return (IIpx800Actions) Proxy.newProxyInstance(IIpx800Actions.class.getClassLoader(),
- new Class[] { IIpx800Actions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of Ipx800Actions");
}
}
diff --git a/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/action/HeosActions.java b/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/action/HeosActions.java
index e4e6e9c74..72dbe8e7b 100644
--- a/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/action/HeosActions.java
+++ b/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/action/HeosActions.java
@@ -13,8 +13,6 @@
package org.openhab.binding.heos.internal.action;
import java.io.IOException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -32,17 +30,12 @@ import org.slf4j.LoggerFactory;
/**
* The class is responsible to call corresponding action on HEOS Handler
- *
- * Note:The static method invokeMethodOf handles the case where
- * the test actions instanceof HeosActions fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link HeosActions} class
- * can be loaded by a different classloader than the actions instance.
*
* @author Martin van Wingerden - Initial contribution
*/
@ThingActionsScope(name = "heos")
@NonNullByDefault
-public class HeosActions implements ThingActions, IHeosActions {
+public class HeosActions implements ThingActions {
private final static Logger logger = LoggerFactory.getLogger(HeosActions.class);
@@ -57,10 +50,11 @@ public class HeosActions implements ThingActions, IHeosActions {
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
+ return handler;
}
private @Nullable HeosFacade getConnection() throws HeosNotConnectedException {
+ HeosBridgeHandler handler = this.handler;
if (handler == null) {
return null;
}
@@ -68,7 +62,6 @@ public class HeosActions implements ThingActions, IHeosActions {
return handler.getApiConnection();
}
- @Override
@RuleAction(label = "Play Input", description = "Play an input from another device")
public void playInputFromPlayer(
@ActionInput(name = "source", label = "Source Player", description = "Player used for input") @Nullable Integer sourcePlayer,
@@ -97,25 +90,10 @@ public class HeosActions implements ThingActions, IHeosActions {
public static void playInputFromPlayer(@Nullable ThingActions actions, @Nullable Integer sourcePlayer,
@Nullable String input, @Nullable Integer destinationPlayer) {
- invokeMethodOf(actions).playInputFromPlayer(sourcePlayer, input, destinationPlayer);
- }
-
- private static IHeosActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
+ if (actions instanceof HeosActions) {
+ ((HeosActions) actions).playInputFromPlayer(sourcePlayer, input, destinationPlayer);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of HeosActions");
}
- if (actions.getClass().getName().equals(HeosActions.class.getName())) {
- if (actions instanceof IHeosActions) {
- return (IHeosActions) actions;
- } else {
- return (IHeosActions) Proxy.newProxyInstance(IHeosActions.class.getClassLoader(),
- new Class[] { IHeosActions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of HeosActions");
}
}
diff --git a/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/action/IHeosActions.java b/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/action/IHeosActions.java
deleted file mode 100644
index 3739292f9..000000000
--- a/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/action/IHeosActions.java
+++ /dev/null
@@ -1,28 +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.heos.internal.action;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-
-/**
- * The {@link IHeosActions} defines the interface for all thing actions supported by the binding.
- *
- * @author Laurent Garnier - Initial contribution
- */
-@NonNullByDefault
-public interface IHeosActions {
-
- public void playInputFromPlayer(@Nullable Integer sourcePlayer, @Nullable String input,
- @Nullable Integer destinationPlayer);
-}
diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/action/ILightActions.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/action/ILightActions.java
deleted file mode 100644
index 912791bb6..000000000
--- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/action/ILightActions.java
+++ /dev/null
@@ -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.hue.internal.action;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.core.library.types.DecimalType;
-import org.openhab.core.types.Command;
-
-/**
- * The {@link ILightActions} defines the interface for all thing actions supported by the binding.
- *
- * @author Laurent Garnier - Initial contribution
- */
-@NonNullByDefault
-public interface ILightActions {
-
- public void fadingLightCommand(@Nullable String channel, @Nullable Command command, @Nullable DecimalType fadeTime);
-}
diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/action/LightActions.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/action/LightActions.java
index 6d4942e82..2e994368e 100644
--- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/action/LightActions.java
+++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/action/LightActions.java
@@ -12,9 +12,6 @@
*/
package org.openhab.binding.hue.internal.action;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.hue.internal.handler.HueLightHandler;
@@ -30,18 +27,13 @@ import org.slf4j.LoggerFactory;
/**
* The {@link LightActions} defines the thing actions for the hue binding.
- *
- * Note:The static method invokeMethodOf handles the case where
- * the test actions instanceof LightActions fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link LightActions} class
- * can be loaded by a different classloader than the actions instance.
*
* @author Jochen Leopold - Initial contribution
* @author Laurent Garnier - new method invokeMethodOf + interface ILightActions
*/
@ThingActionsScope(name = "hue")
@NonNullByDefault
-public class LightActions implements ThingActions, ILightActions {
+public class LightActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(LightActions.class);
private @Nullable HueLightHandler handler;
@@ -52,10 +44,9 @@ public class LightActions implements ThingActions, ILightActions {
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
+ return handler;
}
- @Override
@RuleAction(label = "@text/actionLabel", description = "@text/actionDesc")
public void fadingLightCommand(
@ActionInput(name = "channel", label = "@text/actionInputChannelLabel", description = "@text/actionInputChannelDesc") @Nullable String channel,
@@ -85,27 +76,12 @@ public class LightActions implements ThingActions, ILightActions {
logger.debug("send LightAction to {} with {}ms of fadeTime", channel, fadeTime);
}
- private static ILightActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
- }
- if (actions.getClass().getName().equals(LightActions.class.getName())) {
- if (actions instanceof ILightActions) {
- return (ILightActions) actions;
- } else {
- return (ILightActions) Proxy.newProxyInstance(ILightActions.class.getClassLoader(),
- new Class[] { ILightActions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of LightActions");
- }
-
public static void fadingLightCommand(@Nullable ThingActions actions, @Nullable String channel,
@Nullable Command command, @Nullable DecimalType fadeTime) {
- invokeMethodOf(actions).fadingLightCommand(channel, command, fadeTime);
+ if (actions instanceof LightActions) {
+ ((LightActions) actions).fadingLightCommand(channel, command, fadeTime);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of LightActions");
+ }
}
}
diff --git a/bundles/org.openhab.binding.kaleidescape/src/main/java/org/openhab/binding/kaleidescape/internal/IKaleidescapeThingActions.java b/bundles/org.openhab.binding.kaleidescape/src/main/java/org/openhab/binding/kaleidescape/internal/IKaleidescapeThingActions.java
deleted file mode 100644
index 3643273d6..000000000
--- a/bundles/org.openhab.binding.kaleidescape/src/main/java/org/openhab/binding/kaleidescape/internal/IKaleidescapeThingActions.java
+++ /dev/null
@@ -1,27 +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.kaleidescape.internal;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-/**
- * The {@link IKaleidescapeThingActions} defines the interface for all thing actions supported by the binding.
- * These methods, parameters, and return types are explained in {@link KaleidescapeThingActions}.
- *
- * @author Michael Lobstein - Initial contribution
- */
-@NonNullByDefault
-public interface IKaleidescapeThingActions {
-
- void sendKCommand(String kCommand);
-}
diff --git a/bundles/org.openhab.binding.kaleidescape/src/main/java/org/openhab/binding/kaleidescape/internal/KaleidescapeThingActions.java b/bundles/org.openhab.binding.kaleidescape/src/main/java/org/openhab/binding/kaleidescape/internal/KaleidescapeThingActions.java
index 577422439..6a5fad50b 100644
--- a/bundles/org.openhab.binding.kaleidescape/src/main/java/org/openhab/binding/kaleidescape/internal/KaleidescapeThingActions.java
+++ b/bundles/org.openhab.binding.kaleidescape/src/main/java/org/openhab/binding/kaleidescape/internal/KaleidescapeThingActions.java
@@ -12,9 +12,6 @@
*/
package org.openhab.binding.kaleidescape.internal;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.kaleidescape.internal.handler.KaleidescapeHandler;
@@ -30,16 +27,15 @@ import org.slf4j.LoggerFactory;
* Some automation actions to be used with a {@link KaleidescapeThingActions}
*
* @author Michael Lobstein - initial contribution
- *
*/
@ThingActionsScope(name = "kaleidescape")
@NonNullByDefault
-public class KaleidescapeThingActions implements ThingActions, IKaleidescapeThingActions {
+public class KaleidescapeThingActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(KaleidescapeThingActions.class);
private @Nullable KaleidescapeHandler handler;
- @RuleAction(label = "sendKCommand", description = "Action that sends raw command to the kaleidescape zone")
+ @RuleAction(label = "send a raw command", description = "Action that sends raw command to the kaleidescape zone.")
public void sendKCommand(@ActionInput(name = "sendKCommand") String kCommand) {
KaleidescapeHandler localHandler = handler;
if (localHandler != null) {
@@ -52,7 +48,11 @@ public class KaleidescapeThingActions implements ThingActions, IKaleidescapeThin
/** Static alias to support the old DSL rules engine and make the action available there. */
public static void sendKCommand(@Nullable ThingActions actions, String kCommand) throws IllegalArgumentException {
- invokeMethodOf(actions).sendKCommand(kCommand);
+ if (actions instanceof KaleidescapeThingActions) {
+ ((KaleidescapeThingActions) actions).sendKCommand(kCommand);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of KaleidescapeThingActions");
+ }
}
@Override
@@ -62,27 +62,6 @@ public class KaleidescapeThingActions implements ThingActions, IKaleidescapeThin
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
- }
-
- private static IKaleidescapeThingActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
- }
- if (actions.getClass().getName().equals(KaleidescapeThingActions.class.getName())) {
- if (actions instanceof KaleidescapeThingActions) {
- return (IKaleidescapeThingActions) actions;
- } else {
- return (IKaleidescapeThingActions) Proxy.newProxyInstance(
- IKaleidescapeThingActions.class.getClassLoader(),
- new Class[] { IKaleidescapeThingActions.class },
- (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of KaleidescapeThingActions");
+ return handler;
}
}
diff --git a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/ILcnModuleActions.java b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/ILcnModuleActions.java
deleted file mode 100644
index e35924a09..000000000
--- a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/ILcnModuleActions.java
+++ /dev/null
@@ -1,33 +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.lcn.internal;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-
-/**
- * The {@link ILcnModuleActions} defines the interface for all thing actions supported by the binding.
- * These methods, parameters, and return types are explained in {@link LcnModuleActions}.
- *
- * @author Fabian Wolter - Initial contribution
- */
-@NonNullByDefault
-public interface ILcnModuleActions {
- void hitKey(@Nullable String table, int key, @Nullable String action);
-
- void flickerOutput(int output, int depth, int ramp, int count);
-
- void sendDynamicText(int row, @Nullable String textInput);
-
- void startRelayTimer(int relaynumber, double duration);
-}
diff --git a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnModuleActions.java b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnModuleActions.java
index d023fcc48..cad59e557 100644
--- a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnModuleActions.java
+++ b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnModuleActions.java
@@ -12,8 +12,6 @@
*/
package org.openhab.binding.lcn.internal;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
import java.nio.ByteBuffer;
import java.util.Arrays;
@@ -40,7 +38,7 @@ import org.slf4j.LoggerFactory;
*/
@ThingActionsScope(name = "lcn")
@NonNullByDefault
-public class LcnModuleActions implements ThingActions, ILcnModuleActions {
+public class LcnModuleActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(LcnModuleActions.class);
private static final int DYN_TEXT_CHUNK_COUNT = 5;
private static final int DYN_TEXT_HEADER_LENGTH = 6;
@@ -57,8 +55,7 @@ public class LcnModuleActions implements ThingActions, ILcnModuleActions {
return moduleHandler;
}
- @Override
- @RuleAction(label = "LCN Hit Key", description = "Sends a \"hit key\" command to an LCN module")
+ @RuleAction(label = "send a hit key command", description = "Sends a \"hit key\" command to an LCN module.")
public void hitKey(
@ActionInput(name = "table", required = true, type = "java.lang.String", label = "Table", description = "The key table (A-D)") @Nullable String table,
@ActionInput(name = "key", required = true, type = "java.lang.Integer", label = "Key", description = "The key number (1-8)") int key,
@@ -104,8 +101,7 @@ public class LcnModuleActions implements ThingActions, ILcnModuleActions {
}
}
- @Override
- @RuleAction(label = "LCN Flicker Output", description = "Let a dimmer output flicker for a given count of flashes")
+ @RuleAction(label = "flicker a dimmer output", description = "Let a dimmer output flicker for a given count of flashes.")
public void flickerOutput(
@ActionInput(name = "output", type = "java.lang.Integer", required = true, label = "Output", description = "The output number (1-4)") int output,
@ActionInput(name = "depth", type = "java.lang.Integer", label = "Depth", description = "0=25% 1=50% 2=100%") int depth,
@@ -118,8 +114,7 @@ public class LcnModuleActions implements ThingActions, ILcnModuleActions {
}
}
- @Override
- @RuleAction(label = "LCN Dynamic Text", description = "Send custom text to an LCN-GTxD display")
+ @RuleAction(label = "send a custom text", description = "Send custom text to an LCN-GTxD display.")
public void sendDynamicText(
@ActionInput(name = "row", type = "java.lang.Integer", required = true, label = "Row", description = "Display the text on the LCN-GTxD in the given row number (1-4)") int row,
@ActionInput(name = "text", type = "java.lang.String", label = "Text", description = "The text to display (max. 60 chars/bytes)") @Nullable String textInput) {
@@ -162,8 +157,7 @@ public class LcnModuleActions implements ThingActions, ILcnModuleActions {
* @param relaynumber 1-based number of the relay to use
* @param duration duration of the relay timer in milliseconds
*/
- @Override
- @RuleAction(label = "LCN Relay Timer", description = "Start an LCN relay timer")
+ @RuleAction(label = "start a relay timer", description = "Start an LCN relay timer.")
public void startRelayTimer(
@ActionInput(name = "relaynumber", required = true, type = "java.lang.Integer", label = "Relay Number", description = "The relay number (1-8)") int relayNumber,
@ActionInput(name = "duration", required = true, type = "java.lang.Double", label = "Duration [ms]", description = "The timer duration in milliseconds") double duration) {
@@ -174,44 +168,41 @@ public class LcnModuleActions implements ThingActions, ILcnModuleActions {
}
}
- private static ILcnModuleActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
- }
- if (actions.getClass().getName().equals(LcnModuleActions.class.getName())) {
- if (actions instanceof LcnModuleActions) {
- return (ILcnModuleActions) actions;
- } else {
- return (ILcnModuleActions) Proxy.newProxyInstance(ILcnModuleActions.class.getClassLoader(),
- new Class[] { ILcnModuleActions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions");
- }
-
/** Static alias to support the old DSL rules engine and make the action available there. */
public static void hitKey(@Nullable ThingActions actions, @Nullable String table, int key,
@Nullable String action) {
- invokeMethodOf(actions).hitKey(table, key, action);
+ if (actions instanceof LcnModuleHandler) {
+ ((LcnModuleActions) actions).hitKey(table, key, action);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions");
+ }
}
/** Static alias to support the old DSL rules engine and make the action available there. */
public static void flickerOutput(@Nullable ThingActions actions, int output, int depth, int ramp, int count) {
- invokeMethodOf(actions).flickerOutput(output, depth, ramp, count);
+ if (actions instanceof LcnModuleHandler) {
+ ((LcnModuleActions) actions).flickerOutput(output, depth, ramp, count);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions");
+ }
}
/** Static alias to support the old DSL rules engine and make the action available there. */
public static void sendDynamicText(@Nullable ThingActions actions, int row, @Nullable String text) {
- invokeMethodOf(actions).sendDynamicText(row, text);
+ if (actions instanceof LcnModuleHandler) {
+ ((LcnModuleActions) actions).sendDynamicText(row, text);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions");
+ }
}
/** Static alias to support the old DSL rules engine and make the action available there. */
public static void startRelayTimer(@Nullable ThingActions actions, int relaynumber, double duration) {
- invokeMethodOf(actions).startRelayTimer(relaynumber, duration);
+ if (actions instanceof LcnModuleHandler) {
+ ((LcnModuleActions) actions).startRelayTimer(relaynumber, duration);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions");
+ }
}
private LcnModuleHandler getHandler() throws LcnException {
diff --git a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/action/ILGWebOSActions.java b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/action/ILGWebOSActions.java
deleted file mode 100644
index 5eb004b05..000000000
--- a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/action/ILGWebOSActions.java
+++ /dev/null
@@ -1,46 +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.lgwebos.action;
-
-import java.io.IOException;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-/**
- * The {@link ILGWebOSActions} defines the interface for all thing actions supported by the binding.
- *
- * @author Laurent Garnier - Initial contribution
- */
-@NonNullByDefault
-public interface ILGWebOSActions {
-
- public void showToast(String text) throws IOException;
-
- public void showToast(String icon, String text) throws IOException;
-
- public void launchBrowser(String url);
-
- public void launchApplication(String appId);
-
- public void launchApplication(String appId, String params);
-
- public void sendText(String text);
-
- public void sendButton(String button);
-
- public void increaseChannel();
-
- public void decreaseChannel();
-
- public void sendRCButton(String rcButton);
-}
diff --git a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/action/LGWebOSActions.java b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/action/LGWebOSActions.java
similarity index 84%
rename from bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/action/LGWebOSActions.java
rename to bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/action/LGWebOSActions.java
index 6cf60a38a..954a09715 100644
--- a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/action/LGWebOSActions.java
+++ b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/action/LGWebOSActions.java
@@ -10,14 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.lgwebos.action;
+package org.openhab.binding.lgwebos.internal.action;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
@@ -53,18 +51,13 @@ import com.google.gson.JsonParser;
/**
* The {@link LGWebOSActions} defines the thing actions for the LGwebOS binding.
- *
- * Note:The static method invokeMethodOf handles the case where
- * the test actions instanceof LGWebOSActions fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link LGWebOSActions} class
- * can be loaded by a different classloader than the actions instance.
*
* @author Sebastian Prehn - Initial contribution
* @author Laurent Garnier - new method invokeMethodOf + interface ILGWebOSActions
*/
@ThingActionsScope(name = "lgwebos")
@NonNullByDefault
-public class LGWebOSActions implements ThingActions, ILGWebOSActions {
+public class LGWebOSActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(LGWebOSActions.class);
private final ResponseListener
- * Note:The static method invokeMethodOf handles the case where
- * the test actions instanceof MQTTActions fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link MQTTActions} class
- * can be loaded by a different classloader than the actions instance.
*
* @author David Graeff - Initial contribution
*/
@ThingActionsScope(name = "mqtt")
@NonNullByDefault
-public class MQTTActions implements ThingActions, IMQTTActions {
+public class MQTTActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(MQTTActions.class);
private @Nullable AbstractBrokerHandler handler;
@@ -50,7 +42,7 @@ public class MQTTActions implements ThingActions, IMQTTActions {
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
+ return handler;
}
@RuleAction(label = "@text/actionLabel", description = "@text/actionDesc")
@@ -60,7 +52,6 @@ public class MQTTActions implements ThingActions, IMQTTActions {
publishMQTT(topic, value, null);
}
- @Override
@RuleAction(label = "@text/actionLabel", description = "@text/actionDesc")
public void publishMQTT(
@ActionInput(name = "topic", label = "@text/actionInputTopicLabel", description = "@text/actionInputTopicDesc") @Nullable final String topic,
@@ -100,25 +91,10 @@ public class MQTTActions implements ThingActions, IMQTTActions {
public static void publishMQTT(@Nullable ThingActions actions, @Nullable String topic, @Nullable String value,
@Nullable Boolean retain) {
- invokeMethodOf(actions).publishMQTT(topic, value, retain);
- }
-
- private static IMQTTActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
+ if (actions instanceof MQTTActions) {
+ ((MQTTActions) actions).publishMQTT(topic, value, retain);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of MQTTActions");
}
- if (actions.getClass().getName().equals(MQTTActions.class.getName())) {
- if (actions instanceof IMQTTActions) {
- return (IMQTTActions) actions;
- } else {
- return (IMQTTActions) Proxy.newProxyInstance(IMQTTActions.class.getClassLoader(),
- new Class[] { IMQTTActions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of MQTTActions");
}
}
diff --git a/bundles/org.openhab.binding.network/src/main/java/org/openhab/binding/network/internal/action/INetworkActions.java b/bundles/org.openhab.binding.network/src/main/java/org/openhab/binding/network/internal/action/INetworkActions.java
deleted file mode 100644
index cc068ae2d..000000000
--- a/bundles/org.openhab.binding.network/src/main/java/org/openhab/binding/network/internal/action/INetworkActions.java
+++ /dev/null
@@ -1,26 +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.network.internal.action;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-/**
- * The {@link INetworkActions} defines the interface for all thing actions supported by the binding.
- *
- * @author Wouter Born - Initial contribution
- */
-@NonNullByDefault
-public interface INetworkActions {
-
- void sendWakeOnLanPacket();
-}
diff --git a/bundles/org.openhab.binding.network/src/main/java/org/openhab/binding/network/internal/action/NetworkActions.java b/bundles/org.openhab.binding.network/src/main/java/org/openhab/binding/network/internal/action/NetworkActions.java
index ab2d6801f..a28837f02 100644
--- a/bundles/org.openhab.binding.network/src/main/java/org/openhab/binding/network/internal/action/NetworkActions.java
+++ b/bundles/org.openhab.binding.network/src/main/java/org/openhab/binding/network/internal/action/NetworkActions.java
@@ -12,9 +12,6 @@
*/
package org.openhab.binding.network.internal.action;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.network.internal.handler.NetworkHandler;
@@ -27,17 +24,12 @@ import org.slf4j.LoggerFactory;
/**
* The class is responsible to call corresponding actions on {@link NetworkHandler}.
- *
- * Note:The static method invokeMethodOf handles the case where
- * the test actions instanceof NetworkActions fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link NetworkActions} class
- * can be loaded by a different classloader than the actions instance.
*
* @author Wouter Born - Initial contribution
*/
@ThingActionsScope(name = "network")
@NonNullByDefault
-public class NetworkActions implements ThingActions, INetworkActions {
+public class NetworkActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(NetworkActions.class);
@@ -55,8 +47,7 @@ public class NetworkActions implements ThingActions, INetworkActions {
return handler;
}
- @Override
- @RuleAction(label = "Send WoL Packet", description = "Send a Wake-on-LAN packet to wake the device")
+ @RuleAction(label = "send a WoL packet", description = "Send a Wake-on-LAN packet to wake the device.")
public void sendWakeOnLanPacket() {
NetworkHandler localHandler = handler;
if (localHandler != null) {
@@ -67,25 +58,10 @@ public class NetworkActions implements ThingActions, INetworkActions {
}
public static void sendWakeOnLanPacket(@Nullable ThingActions actions) {
- invokeMethodOf(actions).sendWakeOnLanPacket();
- }
-
- private static INetworkActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
+ if (actions instanceof NetworkActions) {
+ ((NetworkActions) actions).sendWakeOnLanPacket();
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of NetworkActions");
}
- if (actions.getClass().getName().equals(NetworkActions.class.getName())) {
- if (actions instanceof INetworkActions) {
- return (INetworkActions) actions;
- } else {
- return (INetworkActions) Proxy.newProxyInstance(INetworkActions.class.getClassLoader(),
- new Class[] { INetworkActions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of " + NetworkActions.class.getName());
}
}
diff --git a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/INuvoThingActions.java b/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/INuvoThingActions.java
deleted file mode 100644
index 8bec3d20d..000000000
--- a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/INuvoThingActions.java
+++ /dev/null
@@ -1,27 +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.nuvo.internal;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-/**
- * The {@link INuvoThingActions} defines the interface for all thing actions supported by the binding.
- * These methods, parameters, and return types are explained in {@link NuvoThingActions}.
- *
- * @author Michael Lobstein - Initial contribution
- */
-@NonNullByDefault
-public interface INuvoThingActions {
-
- void sendNuvoCommand(String rawCommand);
-}
diff --git a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/NuvoThingActions.java b/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/NuvoThingActions.java
index cf37669eb..59716555b 100644
--- a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/NuvoThingActions.java
+++ b/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/NuvoThingActions.java
@@ -12,9 +12,6 @@
*/
package org.openhab.binding.nuvo.internal;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.nuvo.internal.handler.NuvoHandler;
@@ -30,17 +27,16 @@ import org.slf4j.LoggerFactory;
* Some automation actions to be used with a {@link NuvoThingActions}
*
* @author Michael Lobstein - initial contribution
- *
*/
@ThingActionsScope(name = "nuvo")
@NonNullByDefault
-public class NuvoThingActions implements ThingActions, INuvoThingActions {
+public class NuvoThingActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(NuvoThingActions.class);
private @Nullable NuvoHandler handler;
- @RuleAction(label = "sendNuvoCommand", description = "Action that sends raw command to the amplifer")
+ @RuleAction(label = "send a raw command", description = "Send a raw command to the amplifier.")
public void sendNuvoCommand(@ActionInput(name = "sendNuvoCommand") String rawCommand) {
NuvoHandler localHandler = handler;
if (localHandler != null) {
@@ -52,9 +48,12 @@ public class NuvoThingActions implements ThingActions, INuvoThingActions {
}
/** Static alias to support the old DSL rules engine and make the action available there. */
- public static void sendNuvoCommand(@Nullable ThingActions actions, String rawCommand)
- throws IllegalArgumentException {
- invokeMethodOf(actions).sendNuvoCommand(rawCommand);
+ public static void sendNuvoCommand(@Nullable ThingActions actions, String rawCommand) {
+ if (actions instanceof NuvoThingActions) {
+ ((NuvoThingActions) actions).sendNuvoCommand(rawCommand);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of NuvoThingActions");
+ }
}
@Override
@@ -64,25 +63,6 @@ public class NuvoThingActions implements ThingActions, INuvoThingActions {
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
- }
-
- private static INuvoThingActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
- }
- if (actions.getClass().getName().equals(NuvoThingActions.class.getName())) {
- if (actions instanceof NuvoThingActions) {
- return (INuvoThingActions) actions;
- } else {
- return (INuvoThingActions) Proxy.newProxyInstance(INuvoThingActions.class.getClassLoader(),
- new Class[] { INuvoThingActions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of NuvoThingActions");
+ return handler;
}
}
diff --git a/bundles/org.openhab.binding.onkyo/src/main/java/org/openhab/binding/onkyo/internal/automation/modules/OnkyoThingActions.java b/bundles/org.openhab.binding.onkyo/src/main/java/org/openhab/binding/onkyo/internal/automation/modules/OnkyoThingActions.java
index 6386f7fe3..9c84aa7e6 100644
--- a/bundles/org.openhab.binding.onkyo/src/main/java/org/openhab/binding/onkyo/internal/automation/modules/OnkyoThingActions.java
+++ b/bundles/org.openhab.binding.onkyo/src/main/java/org/openhab/binding/onkyo/internal/automation/modules/OnkyoThingActions.java
@@ -14,14 +14,58 @@ package org.openhab.binding.onkyo.internal.automation.modules;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.onkyo.internal.handler.OnkyoHandler;
+import org.openhab.core.automation.annotation.ActionInput;
+import org.openhab.core.automation.annotation.RuleAction;
+import org.openhab.core.thing.binding.ThingActions;
+import org.openhab.core.thing.binding.ThingActionsScope;
+import org.openhab.core.thing.binding.ThingHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * The {@link OnkyoThingActions} defines the interface for all thing actions supported by the binding.
+ * Some automation actions to be used with a {@link OnkyoThingActions}
*
- * @author Laurent Garnier - initial contribution
+ * @author David Masshardt - initial contribution
*/
+@ThingActionsScope(name = "onkyo")
@NonNullByDefault
-public interface OnkyoThingActions {
+public class OnkyoThingActions implements ThingActions {
- public void sendRawCommand(@Nullable String command, @Nullable String value);
+ private final Logger logger = LoggerFactory.getLogger(OnkyoThingActions.class);
+
+ private @Nullable OnkyoHandler handler;
+
+ @SuppressWarnings("null")
+ @RuleAction(label = "send a raw command", description = "Send a raw command to the receiver.")
+ public void sendRawCommand(@ActionInput(name = "command") @Nullable String command,
+ @ActionInput(name = "command") @Nullable String value) {
+ logger.debug("sendRawCommand called with raw command: {} value: {}", command, value);
+ if (handler == null) {
+ logger.warn("Onkyo Action service ThingHandler is null!");
+ return;
+ }
+ handler.sendRawCommand(command, value);
+ }
+
+ public static void sendRawCommand(@Nullable ThingActions actions, @Nullable String command,
+ @Nullable String value) {
+ if (actions instanceof OnkyoThingActions) {
+ ((OnkyoThingActions) actions).sendRawCommand(command, value);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of OnkyoThingActions");
+ }
+ }
+
+ @Override
+ public void setThingHandler(@Nullable ThingHandler handler) {
+ if (handler instanceof OnkyoHandler) {
+ this.handler = (OnkyoHandler) handler;
+ }
+ }
+
+ @Override
+ public @Nullable ThingHandler getThingHandler() {
+ return handler;
+ }
}
diff --git a/bundles/org.openhab.binding.onkyo/src/main/java/org/openhab/binding/onkyo/internal/automation/modules/OnkyoThingActionsService.java b/bundles/org.openhab.binding.onkyo/src/main/java/org/openhab/binding/onkyo/internal/automation/modules/OnkyoThingActionsService.java
deleted file mode 100644
index 3b2a0d86c..000000000
--- a/bundles/org.openhab.binding.onkyo/src/main/java/org/openhab/binding/onkyo/internal/automation/modules/OnkyoThingActionsService.java
+++ /dev/null
@@ -1,96 +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.onkyo.internal.automation.modules;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.binding.onkyo.internal.handler.OnkyoHandler;
-import org.openhab.core.automation.annotation.ActionInput;
-import org.openhab.core.automation.annotation.RuleAction;
-import org.openhab.core.thing.binding.ThingActions;
-import org.openhab.core.thing.binding.ThingActionsScope;
-import org.openhab.core.thing.binding.ThingHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Some automation actions to be used with a {@link OnkyoThingActionsService}
- *
- * Note:The static method invokeMethodOf handles the case where
- * the test actions instanceof OnkyoThingActionsService fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link OnkyoThingActionsService} class
- * can be loaded by a different classloader than the actions instance.
- *
- * @author David Masshardt - initial contribution
- *
- */
-@ThingActionsScope(name = "onkyo")
-@NonNullByDefault
-public class OnkyoThingActionsService implements ThingActions, OnkyoThingActions {
-
- private final Logger logger = LoggerFactory.getLogger(OnkyoThingActionsService.class);
-
- private @Nullable OnkyoHandler handler;
-
- @Override
- @SuppressWarnings("null")
- @RuleAction(label = "Onkyo sendRawCommand", description = "Action that sends raw command to the receiver")
- public void sendRawCommand(@ActionInput(name = "command") @Nullable String command,
- @ActionInput(name = "command") @Nullable String value) {
- logger.debug("sendRawCommand called with raw command: {} value: {}", command, value);
- if (handler == null) {
- logger.warn("Onkyo Action service ThingHandler is null!");
- return;
- }
- handler.sendRawCommand(command, value);
- }
-
- public static void sendRawCommand(@Nullable ThingActions actions, @Nullable String command,
- @Nullable String value) {
- invokeMethodOf(actions).sendRawCommand(command, value);
- }
-
- private static OnkyoThingActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
- }
- if (actions.getClass().getName().equals(OnkyoThingActionsService.class.getName())) {
- if (actions instanceof OnkyoThingActions) {
- return (OnkyoThingActions) actions;
- } else {
- return (OnkyoThingActions) Proxy.newProxyInstance(OnkyoThingActions.class.getClassLoader(),
- new Class[] { OnkyoThingActions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of OnkyoThingActionsService");
- }
-
- @Override
- public void setThingHandler(@Nullable ThingHandler handler) {
- if (handler instanceof OnkyoHandler) {
- this.handler = (OnkyoHandler) handler;
- }
- }
-
- @Override
- public @Nullable ThingHandler getThingHandler() {
- return this.handler;
- }
-}
diff --git a/bundles/org.openhab.binding.onkyo/src/main/java/org/openhab/binding/onkyo/internal/handler/OnkyoHandler.java b/bundles/org.openhab.binding.onkyo/src/main/java/org/openhab/binding/onkyo/internal/handler/OnkyoHandler.java
index 0e54d4292..717873b3d 100644
--- a/bundles/org.openhab.binding.onkyo/src/main/java/org/openhab/binding/onkyo/internal/handler/OnkyoHandler.java
+++ b/bundles/org.openhab.binding.onkyo/src/main/java/org/openhab/binding/onkyo/internal/handler/OnkyoHandler.java
@@ -32,7 +32,7 @@ import org.openhab.binding.onkyo.internal.OnkyoConnection;
import org.openhab.binding.onkyo.internal.OnkyoEventListener;
import org.openhab.binding.onkyo.internal.OnkyoStateDescriptionProvider;
import org.openhab.binding.onkyo.internal.ServiceType;
-import org.openhab.binding.onkyo.internal.automation.modules.OnkyoThingActionsService;
+import org.openhab.binding.onkyo.internal.automation.modules.OnkyoThingActions;
import org.openhab.binding.onkyo.internal.config.OnkyoDeviceConfiguration;
import org.openhab.binding.onkyo.internal.eiscp.EiscpCommand;
import org.openhab.binding.onkyo.internal.eiscp.EiscpMessage;
@@ -910,6 +910,6 @@ public class OnkyoHandler extends UpnpAudioSinkHandler implements OnkyoEventList
@Override
public Collection
- * Note:The static method invokeMethodOf handles the case where
- * the test actions instanceof PushbulletActions fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link PushbulletActions} class
- * can be loaded by a different classloader than the actions instance.
*
* @author Hakan Tandogan - Initial contribution
*/
@ThingActionsScope(name = "pushbullet")
@NonNullByDefault
-public class PushbulletActions implements ThingActions, IPushbulletActions {
+public class PushbulletActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(PushbulletActions.class);
@@ -52,10 +44,9 @@ public class PushbulletActions implements ThingActions, IPushbulletActions {
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
+ return handler;
}
- @Override
@RuleAction(label = "@text/actionSendPushbulletNoteLabel", description = "@text/actionSendPushbulletNoteDesc")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendPushbulletNote(
@ActionInput(name = "recipient", label = "@text/actionSendPushbulletNoteInputRecipientLabel", description = "@text/actionSendPushbulletNoteInputRecipientDesc") @Nullable String recipient,
@@ -63,9 +54,7 @@ public class PushbulletActions implements ThingActions, IPushbulletActions {
@ActionInput(name = "message", label = "@text/actionSendPushbulletNoteInputMessageLabel", description = "@text/actionSendPushbulletNoteInputMessageDesc") @Nullable String message) {
logger.trace("sendPushbulletNote '{}', '{}', '{}'", recipient, title, message);
- // Use local variable so the SAT check can do proper flow analysis
PushbulletHandler localHandler = handler;
-
if (localHandler == null) {
logger.warn("Pushbullet service Handler is null!");
return false;
@@ -76,19 +65,20 @@ public class PushbulletActions implements ThingActions, IPushbulletActions {
public static boolean sendPushbulletNote(@Nullable ThingActions actions, @Nullable String recipient,
@Nullable String title, @Nullable String message) {
- return invokeMethodOf(actions).sendPushbulletNote(recipient, title, message);
+ if (actions instanceof PushbulletActions) {
+ return ((PushbulletActions) actions).sendPushbulletNote(recipient, title, message);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of PushbulletActions");
+ }
}
- @Override
@RuleAction(label = "@text/actionSendPushbulletNoteLabel", description = "@text/actionSendPushbulletNoteDesc")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendPushbulletNote(
@ActionInput(name = "recipient", label = "@text/actionSendPushbulletNoteInputRecipientLabel", description = "@text/actionSendPushbulletNoteInputRecipientDesc") @Nullable String recipient,
@ActionInput(name = "message", label = "@text/actionSendPushbulletNoteInputMessageLabel", description = "@text/actionSendPushbulletNoteInputMessageDesc") @Nullable String message) {
logger.trace("sendPushbulletNote '{}', '{}'", recipient, message);
- // Use local variable so the SAT check can do proper flow analysis
PushbulletHandler localHandler = handler;
-
if (localHandler == null) {
logger.warn("Pushbullet service Handler is null!");
return false;
@@ -99,25 +89,10 @@ public class PushbulletActions implements ThingActions, IPushbulletActions {
public static boolean sendPushbulletNote(@Nullable ThingActions actions, @Nullable String recipient,
@Nullable String message) {
- return invokeMethodOf(actions).sendPushbulletNote(recipient, message);
- }
-
- private static IPushbulletActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
+ if (actions instanceof PushbulletActions) {
+ return ((PushbulletActions) actions).sendPushbulletNote(recipient, message);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of PushbulletActions");
}
- if (actions.getClass().getName().equals(PushbulletActions.class.getName())) {
- if (actions instanceof IPushbulletActions) {
- return (IPushbulletActions) actions;
- } else {
- return (IPushbulletActions) Proxy.newProxyInstance(IPushbulletActions.class.getClassLoader(),
- new Class[] { IPushbulletActions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of PushbulletActions");
}
}
diff --git a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/IRadioThermostatThingActions.java b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/IRadioThermostatThingActions.java
deleted file mode 100644
index 101cef8f6..000000000
--- a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/IRadioThermostatThingActions.java
+++ /dev/null
@@ -1,28 +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.radiothermostat.internal;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-
-/**
- * The {@link IRadioThermostatThingActions} defines the interface for all thing actions supported by the binding.
- * These methods, parameters, and return types are explained in {@link RadioThermostatThingActions}.
- *
- * @author Michael Lobstein - Initial contribution
- */
-@NonNullByDefault
-public interface IRadioThermostatThingActions {
-
- void sendRawCommand(@Nullable String rawCommand);
-}
diff --git a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatThingActions.java b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatThingActions.java
index 730dc4971..997a71b27 100644
--- a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatThingActions.java
+++ b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatThingActions.java
@@ -12,9 +12,6 @@
*/
package org.openhab.binding.radiothermostat.internal;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.radiothermostat.internal.handler.RadioThermostatHandler;
@@ -30,24 +27,22 @@ import org.slf4j.LoggerFactory;
* Some automation actions to be used with a {@link RadioThermostatThingActions}
*
* @author Michael Lobstein - initial contribution
- *
*/
@ThingActionsScope(name = "radiothermostat")
@NonNullByDefault
-public class RadioThermostatThingActions implements ThingActions, IRadioThermostatThingActions {
+public class RadioThermostatThingActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(RadioThermostatThingActions.class);
private @Nullable RadioThermostatHandler handler;
- @Override
- @RuleAction(label = "sendRawCommand", description = "Action that sends raw command to the thermostat")
+ @RuleAction(label = "send a raw command", description = "Send a raw command to the thermostat.")
public void sendRawCommand(@ActionInput(name = "sendRawCommand") @Nullable String rawCommand) {
- RadioThermostatHandler localHandler = handler;
if (rawCommand == null) {
logger.warn("sendRawCommand called with null command, ignoring");
return;
}
+ RadioThermostatHandler localHandler = handler;
if (localHandler != null) {
localHandler.handleRawCommand(rawCommand);
logger.debug("sendRawCommand called with raw command: {}", rawCommand);
@@ -55,9 +50,12 @@ public class RadioThermostatThingActions implements ThingActions, IRadioThermost
}
/** Static alias to support the old DSL rules engine and make the action available there. */
- public static void sendRawCommand(@Nullable ThingActions actions, @Nullable String rawCommand)
- throws IllegalArgumentException {
- invokeMethodOf(actions).sendRawCommand(rawCommand);
+ public static void sendRawCommand(@Nullable ThingActions actions, @Nullable String rawCommand) {
+ if (actions instanceof RadioThermostatThingActions) {
+ ((RadioThermostatThingActions) actions).sendRawCommand(rawCommand);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of RadioThermostatThingActions");
+ }
}
@Override
@@ -67,27 +65,6 @@ public class RadioThermostatThingActions implements ThingActions, IRadioThermost
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
- }
-
- private static IRadioThermostatThingActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
- }
- if (actions.getClass().getName().equals(RadioThermostatThingActions.class.getName())) {
- if (actions instanceof RadioThermostatThingActions) {
- return (IRadioThermostatThingActions) actions;
- } else {
- return (IRadioThermostatThingActions) Proxy.newProxyInstance(
- IRadioThermostatThingActions.class.getClassLoader(),
- new Class[] { IRadioThermostatThingActions.class },
- (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of RadioThermostatThingActions");
+ return handler;
}
}
diff --git a/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/action/ISatelEventLogActions.java b/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/action/ISatelEventLogActions.java
deleted file mode 100644
index 53a8786be..000000000
--- a/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/action/ISatelEventLogActions.java
+++ /dev/null
@@ -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
- * Note:The static method invokeMethodOf handles the case where
- * the test actions instanceof TelegramActions fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link TelegramActions} class
- * can be loaded by a different classloader than the actions instance.
*
* @author Alexander Krasnogolowy - Initial contribution
- *
*/
@ThingActionsScope(name = "telegram")
@NonNullByDefault
-public class TelegramActions implements ThingActions, ITelegramActions {
+public class TelegramActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(TelegramActions.class);
private @Nullable TelegramHandler handler;
@@ -81,7 +73,6 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return true;
}
- @NonNullByDefault
private static class BasicResult implements Authentication.Result {
private final HttpHeader header;
@@ -112,8 +103,7 @@ public class TelegramActions implements ThingActions, ITelegramActions {
}
}
- @Override
- @RuleAction(label = "Telegram answer", description = "Sends a Telegram answer via Telegram API")
+ @RuleAction(label = "send an answer", description = "Send a Telegram answer using the Telegram API.")
public boolean sendTelegramAnswer(@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "replyId") @Nullable String replyId,
@ActionInput(name = "message") @Nullable String message) {
@@ -155,8 +145,7 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return false;
}
- @Override
- @RuleAction(label = "Telegram answer", description = "Sends a Telegram answer via Telegram API")
+ @RuleAction(label = "send an answer", description = "Send a Telegram answer using the Telegram API.")
public boolean sendTelegramAnswer(@ActionInput(name = "replyId") @Nullable String replyId,
@ActionInput(name = "message") @Nullable String message) {
TelegramHandler localHandler = handler;
@@ -170,15 +159,13 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return true;
}
- @Override
- @RuleAction(label = "Telegram message", description = "Sends a Telegram via Telegram API")
+ @RuleAction(label = "send a message", description = "Send a Telegram message using the Telegram API.")
public boolean sendTelegram(@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "message") @Nullable String message) {
return sendTelegramGeneral(chatId, message, (String) null);
}
- @Override
- @RuleAction(label = "Telegram message", description = "Sends a Telegram via Telegram API")
+ @RuleAction(label = "send a message", description = "Send a Telegram message using the Telegram API.")
public boolean sendTelegram(@ActionInput(name = "message") @Nullable String message) {
TelegramHandler localHandler = handler;
if (localHandler != null) {
@@ -191,8 +178,7 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return true;
}
- @Override
- @RuleAction(label = "Telegram message", description = "Sends a Telegram via Telegram API")
+ @RuleAction(label = "send a message", description = "Send a Telegram using the Telegram API.")
public boolean sendTelegramQuery(@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "message") @Nullable String message,
@ActionInput(name = "replyId") @Nullable String replyId,
@@ -200,8 +186,7 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return sendTelegramGeneral(chatId, message, replyId, buttons);
}
- @Override
- @RuleAction(label = "Telegram message", description = "Sends a Telegram via Telegram API")
+ @RuleAction(label = "send a message", description = "Send a Telegram using the Telegram API.")
public boolean sendTelegramQuery(@ActionInput(name = "message") @Nullable String message,
@ActionInput(name = "replyId") @Nullable String replyId,
@ActionInput(name = "buttons") @Nullable String... buttons) {
@@ -266,16 +251,14 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return false;
}
- @Override
- @RuleAction(label = "Telegram message", description = "Sends a Telegram via Telegram API")
+ @RuleAction(label = "send a message", description = "Send a Telegram using the Telegram API.")
public boolean sendTelegram(@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "message") @Nullable String message,
@ActionInput(name = "args") @Nullable Object... args) {
return sendTelegram(chatId, String.format(message, args));
}
- @Override
- @RuleAction(label = "Telegram message", description = "Sends a Telegram via Telegram API")
+ @RuleAction(label = "send a message", description = "Send a Telegram using the Telegram API.")
public boolean sendTelegram(@ActionInput(name = "message") @Nullable String message,
@ActionInput(name = "args") @Nullable Object... args) {
TelegramHandler localHandler = handler;
@@ -289,15 +272,14 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return true;
}
- @RuleAction(label = "Telegram photo", description = "Sends a Picture via Telegram API")
+ @RuleAction(label = "send a photo", description = "Send a picture using the Telegram API.")
public boolean sendTelegramPhoto(@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "photoURL") @Nullable String photoURL,
@ActionInput(name = "caption") @Nullable String caption) {
return sendTelegramPhoto(chatId, photoURL, caption, null, null);
}
- @Override
- @RuleAction(label = "Telegram photo", description = "Sends a Picture via Telegram API")
+ @RuleAction(label = "send a photo", description = "Send a picture using the Telegram API.")
public boolean sendTelegramPhoto(@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "photoURL") @Nullable String photoURL,
@ActionInput(name = "caption") @Nullable String caption,
@@ -387,8 +369,7 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return false;
}
- @Override
- @RuleAction(label = "Telegram photo", description = "Sends a Picture via Telegram API")
+ @RuleAction(label = "send a photo", description = "Send a Picture using the Telegram API.")
public boolean sendTelegramPhoto(@ActionInput(name = "photoURL") @Nullable String photoURL,
@ActionInput(name = "caption") @Nullable String caption,
@ActionInput(name = "username") @Nullable String username,
@@ -404,7 +385,7 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return true;
}
- @RuleAction(label = "Telegram photo", description = "Sends a Picture via Telegram API")
+ @RuleAction(label = "send a photo", description = "Send a Picture using the Telegram API.")
public boolean sendTelegramPhoto(@ActionInput(name = "photoURL") @Nullable String photoURL,
@ActionInput(name = "caption") @Nullable String caption) {
return sendTelegramPhoto(photoURL, caption, null, null);
@@ -414,78 +395,103 @@ public class TelegramActions implements ThingActions, ITelegramActions {
/* APIs without chatId parameter */
public static boolean sendTelegram(@Nullable ThingActions actions, @Nullable String format,
@Nullable Object... args) {
- return invokeMethodOf(actions).sendTelegram(format, args);
+ if (actions instanceof TelegramActions) {
+ return ((TelegramActions) actions).sendTelegram(format, args);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
+ }
}
public static boolean sendTelegramQuery(@Nullable ThingActions actions, @Nullable String message,
@Nullable String replyId, @Nullable String... buttons) {
- return invokeMethodOf(actions).sendTelegramQuery(message, replyId, buttons);
+ if (actions instanceof TelegramActions) {
+ return ((TelegramActions) actions).sendTelegramQuery(message, replyId, buttons);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
+ }
}
public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable String photoURL,
@Nullable String caption) {
- return invokeMethodOf(actions).sendTelegramPhoto(photoURL, caption, null, null);
+ if (actions instanceof TelegramActions) {
+ return ((TelegramActions) actions).sendTelegramPhoto(photoURL, caption, null, null);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
+ }
}
public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable String photoURL,
@Nullable String caption, @Nullable String username, @Nullable String password) {
- return invokeMethodOf(actions).sendTelegramPhoto(photoURL, caption, username, password);
+ if (actions instanceof TelegramActions) {
+ return ((TelegramActions) actions).sendTelegramPhoto(photoURL, caption, username, password);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
+ }
}
public static boolean sendTelegramAnswer(@Nullable ThingActions actions, @Nullable String replyId,
@Nullable String message) {
- return invokeMethodOf(actions).sendTelegramAnswer(replyId, message);
+ if (actions instanceof TelegramActions) {
+ return ((TelegramActions) actions).sendTelegramAnswer(replyId, message);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
+ }
}
/* APIs with chatId parameter */
public static boolean sendTelegram(@Nullable ThingActions actions, @Nullable Long chatId, @Nullable String format,
@Nullable Object... args) {
- return invokeMethodOf(actions).sendTelegram(chatId, format, args);
+ if (actions instanceof TelegramActions) {
+ return ((TelegramActions) actions).sendTelegram(chatId, format, args);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
+ }
}
public static boolean sendTelegramQuery(@Nullable ThingActions actions, @Nullable Long chatId,
@Nullable String message, @Nullable String replyId, @Nullable String... buttons) {
- return invokeMethodOf(actions).sendTelegramQuery(chatId, message, replyId, buttons);
+ if (actions instanceof TelegramActions) {
+ return ((TelegramActions) actions).sendTelegramQuery(chatId, message, replyId, buttons);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
+ }
}
public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable Long chatId,
@Nullable String photoURL, @Nullable String caption) {
- return invokeMethodOf(actions).sendTelegramPhoto(chatId, photoURL, caption, null, null);
+ if (actions instanceof TelegramActions) {
+ return ((TelegramActions) actions).sendTelegramPhoto(chatId, photoURL, caption, null, null);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
+ }
}
public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable Long chatId,
@Nullable String photoURL, @Nullable String caption, @Nullable String username, @Nullable String password) {
- return invokeMethodOf(actions).sendTelegramPhoto(chatId, photoURL, caption, username, password);
+ if (actions instanceof TelegramActions) {
+ return ((TelegramActions) actions).sendTelegramPhoto(chatId, photoURL, caption, username, password);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
+ }
}
public static boolean sendTelegramAnswer(@Nullable ThingActions actions, @Nullable Long chatId,
@Nullable String replyId, @Nullable String message) {
- return invokeMethodOf(actions).sendTelegramAnswer(chatId, replyId, message);
+ if (actions instanceof TelegramActions) {
+ return ((TelegramActions) actions).sendTelegramAnswer(chatId, replyId, message);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
+ }
}
public static boolean sendTelegramAnswer(@Nullable ThingActions actions, @Nullable String chatId,
@Nullable String replyId, @Nullable String message) {
- return invokeMethodOf(actions).sendTelegramAnswer(Long.valueOf(chatId), replyId, message);
- }
-
- private static ITelegramActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
+ if (actions instanceof TelegramActions) {
+ return ((TelegramActions) actions).sendTelegramAnswer(Long.valueOf(chatId), replyId, message);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
- if (actions.getClass().getName().equals(TelegramActions.class.getName())) {
- if (actions instanceof ITelegramActions) {
- return (ITelegramActions) actions;
- } else {
- return (ITelegramActions) Proxy.newProxyInstance(ITelegramActions.class.getClassLoader(),
- new Class[] { ITelegramActions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
@Override
diff --git a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/action/VolvoOnCallActions.java b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/action/VolvoOnCallActions.java
index d15fd3438..a00d92115 100644
--- a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/action/VolvoOnCallActions.java
+++ b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/action/VolvoOnCallActions.java
@@ -41,7 +41,7 @@ public class VolvoOnCallActions implements ThingActions {
private @Nullable VehicleHandler handler;
public VolvoOnCallActions() {
- logger.info("Volvo On Call actions service instanciated");
+ logger.debug("Volvo On Call actions service instantiated");
}
@Override
@@ -53,7 +53,7 @@ public class VolvoOnCallActions implements ThingActions {
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
+ return handler;
}
@RuleAction(label = "close the car", description = "Closes the car")
diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/action/IXMPPActions.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/action/IXMPPActions.java
deleted file mode 100644
index 05e684d9a..000000000
--- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/action/IXMPPActions.java
+++ /dev/null
@@ -1,32 +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.xmppclient.action;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-
-/**
- * This is the automation engine action handler service for the publishXMPP action.
- *
- * Note:The static method invokeMethodOf handles the case where
- * the test actions instanceof XMPPActions fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link IXMPPActions} class
- * can be loaded by a different classloader than the actions instance.
- *
- * @author Laurent Garnier - Initial contribution
- */
-@NonNullByDefault
-public interface IXMPPActions {
-
- public void publishXMPP(@Nullable String to, @Nullable String text);
-}
diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java
index 93bac0845..1ac261acc 100644
--- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java
+++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java
@@ -16,7 +16,12 @@ import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
-import org.jivesoftware.smack.*;
+import org.jivesoftware.smack.AbstractXMPPConnection;
+import org.jivesoftware.smack.ConnectionListener;
+import org.jivesoftware.smack.ReconnectionManager;
+import org.jivesoftware.smack.SmackException;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.chat2.Chat;
import org.jivesoftware.smack.chat2.ChatManager;
import org.jivesoftware.smack.chat2.IncomingChatMessageListener;
@@ -28,7 +33,7 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
-import org.openhab.binding.xmppclient.handler.XMPPClientMessageSubscriber;
+import org.openhab.binding.xmppclient.internal.handler.XMPPClientMessageSubscriber;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/XMPPClientBindingConstants.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientBindingConstants.java
similarity index 94%
rename from bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/XMPPClientBindingConstants.java
rename to bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientBindingConstants.java
index 9ce9d51f1..a07f609a6 100644
--- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/XMPPClientBindingConstants.java
+++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientBindingConstants.java
@@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.xmppclient;
+package org.openhab.binding.xmppclient.internal;
import org.openhab.core.thing.ThingTypeUID;
diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientHandlerFactory.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientHandlerFactory.java
index dea805fc2..129f8e5dd 100644
--- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientHandlerFactory.java
+++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientHandlerFactory.java
@@ -15,8 +15,7 @@ package org.openhab.binding.xmppclient.internal;
import java.util.Collections;
import java.util.Set;
-import org.openhab.binding.xmppclient.XMPPClientBindingConstants;
-import org.openhab.binding.xmppclient.handler.XMPPClientHandler;
+import org.openhab.binding.xmppclient.internal.handler.XMPPClientHandler;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/action/XMPPActions.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java
similarity index 58%
rename from bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/action/XMPPActions.java
rename to bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java
index 1d617fd7d..7edf1c6e4 100644
--- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/action/XMPPActions.java
+++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java
@@ -10,15 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.xmppclient.action;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
+package org.openhab.binding.xmppclient.internal.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.binding.xmppclient.handler.XMPPClientHandler;
import org.openhab.binding.xmppclient.internal.XMPPClient;
+import org.openhab.binding.xmppclient.internal.handler.XMPPClientHandler;
import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.RuleAction;
import org.openhab.core.thing.binding.ThingActions;
@@ -29,17 +26,12 @@ import org.slf4j.LoggerFactory;
/**
* This is the automation engine action handler service for the publishXMPP action.
- *
- * Note:The static method invokeMethodOf handles the case where
- * the test actions instanceof XMPPActions fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link XMPPActions} class
- * can be loaded by a different classloader than the actions instance.
*
* @author Pavel Gololobov - Initial contribution
*/
@ThingActionsScope(name = "xmpp")
@NonNullByDefault
-public class XMPPActions implements ThingActions, IXMPPActions {
+public class XMPPActions implements ThingActions {
private static final Logger logger = LoggerFactory.getLogger(XMPPActions.class);
private @Nullable XMPPClientHandler handler;
@@ -50,11 +42,10 @@ public class XMPPActions implements ThingActions, IXMPPActions {
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
+ return handler;
}
- @Override
- @RuleAction(label = "publishXMPP", description = "Publish to XMPP")
+ @RuleAction(label = "publish a message", description = "Publish a message using XMPP.")
public void publishXMPP(@ActionInput(name = "to", label = "To", description = "Send to") @Nullable String to,
@ActionInput(name = "text", label = "Text", description = "Message text") @Nullable String text) {
XMPPClientHandler clientHandler = handler;
@@ -76,25 +67,10 @@ public class XMPPActions implements ThingActions, IXMPPActions {
}
public static void publishXMPP(@Nullable ThingActions actions, @Nullable String to, @Nullable String text) {
- invokeMethodOf(actions).publishXMPP(to, text);
- }
-
- private static IXMPPActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
+ if (actions instanceof XMPPActions) {
+ ((XMPPActions) actions).publishXMPP(to, text);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of XMPPActions");
}
- if (actions.getClass().getName().equals(XMPPActions.class.getName())) {
- if (actions instanceof IXMPPActions) {
- return (IXMPPActions) actions;
- } else {
- return (IXMPPActions) Proxy.newProxyInstance(IXMPPActions.class.getClassLoader(),
- new Class[] { IXMPPActions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of XMPPActions");
}
}
diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/PublishTriggerChannel.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/PublishTriggerChannel.java
similarity index 97%
rename from bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/PublishTriggerChannel.java
rename to bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/PublishTriggerChannel.java
index 86334bc14..c5c703d50 100644
--- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/PublishTriggerChannel.java
+++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/PublishTriggerChannel.java
@@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.xmppclient.handler;
+package org.openhab.binding.xmppclient.internal.handler;
import org.openhab.binding.xmppclient.internal.XMPPClient;
import org.openhab.core.thing.ChannelUID;
diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/PublishTriggerChannelConfig.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/PublishTriggerChannelConfig.java
similarity index 92%
rename from bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/PublishTriggerChannelConfig.java
rename to bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/PublishTriggerChannelConfig.java
index b5c937a49..fc3055afd 100644
--- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/PublishTriggerChannelConfig.java
+++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/PublishTriggerChannelConfig.java
@@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.xmppclient.handler;
+package org.openhab.binding.xmppclient.internal.handler;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/XMPPClientConfiguration.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientConfiguration.java
similarity index 93%
rename from bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/XMPPClientConfiguration.java
rename to bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientConfiguration.java
index 5e99bef6a..2344255aa 100644
--- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/XMPPClientConfiguration.java
+++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientConfiguration.java
@@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.xmppclient.handler;
+package org.openhab.binding.xmppclient.internal.handler;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/XMPPClientHandler.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientHandler.java
similarity index 96%
rename from bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/XMPPClientHandler.java
rename to bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientHandler.java
index ce748112c..ded44527a 100644
--- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/XMPPClientHandler.java
+++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientHandler.java
@@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.xmppclient.handler;
+package org.openhab.binding.xmppclient.internal.handler;
import java.io.IOException;
import java.util.Collection;
@@ -20,8 +20,8 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.jivesoftware.smack.*;
-import org.openhab.binding.xmppclient.action.XMPPActions;
import org.openhab.binding.xmppclient.internal.XMPPClient;
+import org.openhab.binding.xmppclient.internal.action.XMPPActions;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/XMPPClientMessageSubscriber.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientMessageSubscriber.java
similarity index 91%
rename from bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/XMPPClientMessageSubscriber.java
rename to bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientMessageSubscriber.java
index 8ffc1c78d..6145ef74b 100644
--- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/handler/XMPPClientMessageSubscriber.java
+++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientMessageSubscriber.java
@@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.xmppclient.handler;
+package org.openhab.binding.xmppclient.internal.handler;
/**
* Subscriber interface
diff --git a/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/action/IZmActions.java b/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/action/IZmActions.java
deleted file mode 100644
index f0ed5208a..000000000
--- a/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/action/IZmActions.java
+++ /dev/null
@@ -1,32 +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.zoneminder.action;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-
-/**
- * The {@link IZmActions} defines the interface for all thing actions supported by the binding.
- * These methods, parameters, and return types are explained in {@link ZmActions}.
- *
- * @author Mark Hilbush - Initial contribution
- */
-@NonNullByDefault
-public interface IZmActions {
-
- public void triggerAlarm(@Nullable Number alarmDuration);
-
- public void triggerAlarm();
-
- public void cancelAlarm();
-}
diff --git a/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/action/ZmActions.java b/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/internal/action/ZmActions.java
similarity index 63%
rename from bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/action/ZmActions.java
rename to bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/internal/action/ZmActions.java
index 05752c5a0..8ca8809b0 100644
--- a/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/action/ZmActions.java
+++ b/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/internal/action/ZmActions.java
@@ -10,10 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.zoneminder.action;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
+package org.openhab.binding.zoneminder.internal.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -29,23 +26,18 @@ import org.slf4j.LoggerFactory;
/**
* The {@link ZmActions} defines the thing actions provided by this binding.
*
- * Note:The static method invokeMethodOf handles the case where
- * the test actions instanceof ZmActions fails. This test can fail
- * due to an issue in openHAB core v2.5.0 where the {@link ZmActions} class
- * can be loaded by a different classloader than the actions instance.
- *
* @author Mark Hilbush - Initial contribution
*/
@ThingActionsScope(name = "zm")
@NonNullByDefault
-public class ZmActions implements ThingActions, IZmActions {
+public class ZmActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(ZmActions.class);
private @Nullable ZmMonitorHandler handler;
@Override
public @Nullable ThingHandler getThingHandler() {
- return this.handler;
+ return handler;
}
@Override
@@ -55,31 +47,11 @@ public class ZmActions implements ThingActions, IZmActions {
}
}
- private static IZmActions invokeMethodOf(@Nullable ThingActions actions) {
- if (actions == null) {
- throw new IllegalArgumentException("actions cannot be null");
- }
- if (actions.getClass().getName().equals(ZmActions.class.getName())) {
- if (actions instanceof IZmActions) {
- return (IZmActions) actions;
- } else {
- return (IZmActions) Proxy.newProxyInstance(IZmActions.class.getClassLoader(),
- new Class[] { IZmActions.class }, (Object proxy, Method method, Object[] args) -> {
- Method m = actions.getClass().getDeclaredMethod(method.getName(),
- method.getParameterTypes());
- return m.invoke(actions, args);
- });
- }
- }
- throw new IllegalArgumentException("Actions is not an instance of ZmActions");
- }
-
/**
* The Trigger Alarm function triggers an alarm that will run for the number of seconds
* specified by the supplied parameter duration.
*/
- @Override
- @RuleAction(label = "TriggerAlarm", description = "Trigger an alarm on the monitor.")
+ @RuleAction(label = "trigger an alarm", description = "Trigger an alarm on the monitor.")
public void triggerAlarm(
@ActionInput(name = "duration", description = "The duration of the alarm in seconds.") @Nullable Number duration) {
logger.debug("ZmActions: Action 'TriggerAlarm' called");
@@ -92,15 +64,18 @@ public class ZmActions implements ThingActions, IZmActions {
}
public static void triggerAlarm(@Nullable ThingActions actions, @Nullable Number alarmDuration) {
- invokeMethodOf(actions).triggerAlarm(alarmDuration);
+ if (actions instanceof ZmActions) {
+ ((ZmActions) actions).triggerAlarm(alarmDuration);
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of ZmActions");
+ }
}
/**
* The Trigger Alarm function triggers an alarm that will run for the number of seconds
* specified in the thing configuration.
*/
- @Override
- @RuleAction(label = "TriggerAlarm", description = "Trigger an alarm on the monitor.")
+ @RuleAction(label = "trigger an alarm", description = "Trigger an alarm on the monitor.")
public void triggerAlarm() {
logger.debug("ZmActions: Action 'TriggerAlarm' called");
ZmMonitorHandler localHandler = handler;
@@ -112,14 +87,17 @@ public class ZmActions implements ThingActions, IZmActions {
}
public static void triggerAlarm(@Nullable ThingActions actions) {
- invokeMethodOf(actions).triggerAlarm();
+ if (actions instanceof ZmActions) {
+ ((ZmActions) actions).triggerAlarm();
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of ZmActions");
+ }
}
/**
* The Cancel Alarm function cancels a running alarm.
*/
- @Override
- @RuleAction(label = "CancelAlarm", description = "Cancel a running alarm.")
+ @RuleAction(label = "cancel a running alarm", description = "Cancel a running alarm.")
public void cancelAlarm() {
logger.debug("ZmActions: Action 'CancelAlarm' called");
ZmMonitorHandler localHandler = handler;
@@ -131,6 +109,10 @@ public class ZmActions implements ThingActions, IZmActions {
}
public static void cancelAlarm(@Nullable ThingActions actions) {
- invokeMethodOf(actions).cancelAlarm();
+ if (actions instanceof ZmActions) {
+ ((ZmActions) actions).cancelAlarm();
+ } else {
+ throw new IllegalArgumentException("Actions is not an instance of ZmActions");
+ }
}
}
diff --git a/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/internal/handler/ZmMonitorHandler.java b/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/internal/handler/ZmMonitorHandler.java
index a27df7130..3265a5da0 100644
--- a/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/internal/handler/ZmMonitorHandler.java
+++ b/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/internal/handler/ZmMonitorHandler.java
@@ -26,7 +26,7 @@ import javax.measure.quantity.Time;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.binding.zoneminder.action.ZmActions;
+import org.openhab.binding.zoneminder.internal.action.ZmActions;
import org.openhab.binding.zoneminder.internal.config.ZmMonitorConfig;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.library.types.DateTimeType;