From bef1046258e666ce180d5b5c73a0f60a100eb4e7 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Wed, 14 Oct 2020 19:01:12 +0200 Subject: [PATCH] Rework ThingActions (#8732) * Remove proxy workarounds * Move ThingActions and a few other classes into the internal package * Use more consistent action labels/descriptions Related to: * openhab/openhab-core#1714 * openhab/openhab-core#1639 Signed-off-by: Wouter Born --- .../internal/actions/BridgeActions.java | 40 +--- .../internal/actions/IBridgeActions.java | 29 --- .../astro/internal/action/AstroActions.java | 61 ++---- .../astro/internal/action/IAstroActions.java | 36 ---- .../internal/actions/AutomowerActions.java | 64 +++--- .../internal/actions/IAutomowerActions.java | 36 ---- .../actions/AVMFritzHeatingActions.java | 43 +--- .../actions/IAVMFritzHeatingActions.java | 31 --- .../AVMFritzHeatingActionsHandler.java | 2 +- .../actions/AVMFritzHeatingActionsTest.java | 2 +- .../binding/dmx/action/IDmxActions.java | 27 --- .../dmx/internal/DmxBridgeHandler.java | 2 +- .../dmx/{ => internal}/action/DmxActions.java | 42 +--- .../doorbird/action/IDoorbirdActions.java | 37 ---- .../action/DoorbirdActions.java | 102 ++++----- .../internal/handler/DoorbellHandler.java | 2 +- .../binding/ecobee/action/IEcobeeActions.java | 78 ------- .../{ => internal}/action/EcobeeActions.java | 200 ++++++++++-------- .../EcobeeThermostatBridgeHandler.java | 2 +- .../enigma2/actions/IEnigma2Actions.java | 41 ---- .../internal/Enigma2HandlerFactory.java | 2 +- .../actions/Enigma2Actions.java | 91 ++++---- .../handler/Enigma2Handler.java | 4 +- .../actions/Enigma2ActionsTest.java | 4 +- .../handler/Enigma2HandlerTest.java | 4 +- .../gce/internal/action/IIpx800Actions.java | 28 --- .../gce/internal/action/Ipx800Actions.java | 49 ++--- .../heos/internal/action/HeosActions.java | 36 +--- .../heos/internal/action/IHeosActions.java | 28 --- .../hue/internal/action/ILightActions.java | 29 --- .../hue/internal/action/LightActions.java | 38 +--- .../internal/IKaleidescapeThingActions.java | 27 --- .../internal/KaleidescapeThingActions.java | 37 +--- .../lcn/internal/ILcnModuleActions.java | 33 --- .../lcn/internal/LcnModuleActions.java | 59 +++--- .../lgwebos/action/ILGWebOSActions.java | 46 ---- .../{ => internal}/action/LGWebOSActions.java | 102 ++++----- .../internal/handler/LGWebOSHandler.java | 2 +- .../binding/lutron/action/IDimmerActions.java | 30 --- .../{ => internal}/action/DimmerActions.java | 36 +--- .../internal/handler/DimmerHandler.java | 2 +- .../binding/mail/action/ISendMailActions.java | 32 --- .../binding/mail/internal/SMTPHandler.java | 2 +- .../action/SendMailActions.java | 53 ++--- .../max/internal/actions/IMaxCubeActions.java | 32 --- .../internal/actions/IMaxDevicesActions.java | 28 --- .../actions/MaxCubeActions.java | 54 ++--- .../actions/MaxDevicesActions.java | 36 +--- .../handler/MaxCubeBridgeHandler.java | 2 +- .../internal/handler/MaxDevicesHandler.java | 2 +- .../mpd/internal/action/IMPDActions.java | 29 --- .../mpd/internal/action/MPDActions.java | 42 ++-- .../binding/mqtt/action/IMQTTActions.java | 27 --- .../mqtt/handler/AbstractBrokerHandler.java | 2 +- .../{ => internal}/action/MQTTActions.java | 38 +--- .../internal/action/INetworkActions.java | 26 --- .../internal/action/NetworkActions.java | 36 +--- .../nuvo/internal/INuvoThingActions.java | 27 --- .../nuvo/internal/NuvoThingActions.java | 38 +--- .../automation/modules/OnkyoThingActions.java | 52 ++++- .../modules/OnkyoThingActionsService.java | 96 --------- .../onkyo/internal/handler/OnkyoHandler.java | 4 +- .../internal/action/IPushbulletActions.java | 29 --- .../internal/action/PushbulletActions.java | 47 +--- .../IRadioThermostatThingActions.java | 28 --- .../internal/RadioThermostatThingActions.java | 43 +--- .../satel/action/ISatelEventLogActions.java | 29 --- .../action/SatelEventLogActions.java | 26 +-- .../handler/SatelEventLogHandler.java | 2 +- .../telegram/bot/ITelegramActions.java | 48 ----- .../telegram/internal/TelegramHandler.java | 2 +- .../action}/TelegramActions.java | 130 ++++++------ .../internal/action/VolvoOnCallActions.java | 4 +- .../xmppclient/action/IXMPPActions.java | 32 --- .../xmppclient/internal/XMPPClient.java | 9 +- .../XMPPClientBindingConstants.java | 2 +- .../internal/XMPPClientHandlerFactory.java | 3 +- .../{ => internal}/action/XMPPActions.java | 42 +--- .../handler/PublishTriggerChannel.java | 2 +- .../handler/PublishTriggerChannelConfig.java | 2 +- .../handler/XMPPClientConfiguration.java | 2 +- .../handler/XMPPClientHandler.java | 4 +- .../handler/XMPPClientMessageSubscriber.java | 2 +- .../binding/zoneminder/action/IZmActions.java | 32 --- .../{ => internal}/action/ZmActions.java | 60 ++---- .../internal/handler/ZmMonitorHandler.java | 2 +- 86 files changed, 708 insertions(+), 2096 deletions(-) delete mode 100644 bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/actions/IBridgeActions.java delete mode 100644 bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/action/IAstroActions.java delete mode 100644 bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/actions/IAutomowerActions.java rename bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/{ => internal}/actions/AVMFritzHeatingActions.java (66%) delete mode 100644 bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/actions/IAVMFritzHeatingActions.java rename bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/{ => internal}/actions/AVMFritzHeatingActionsTest.java (98%) delete mode 100644 bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/action/IDmxActions.java rename bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/{ => internal}/action/DmxActions.java (61%) delete mode 100644 bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/action/IDoorbirdActions.java rename bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/{ => internal}/action/DoorbirdActions.java (52%) delete mode 100644 bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/action/IEcobeeActions.java rename bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/{ => internal}/action/EcobeeActions.java (80%) delete mode 100644 bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/actions/IEnigma2Actions.java rename bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/{ => internal}/actions/Enigma2Actions.java (74%) rename bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/{ => internal}/handler/Enigma2Handler.java (99%) rename bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/{ => internal}/actions/Enigma2ActionsTest.java (97%) rename bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/{ => internal}/handler/Enigma2HandlerTest.java (99%) delete mode 100644 bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/action/IIpx800Actions.java delete mode 100644 bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/action/IHeosActions.java delete mode 100644 bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/action/ILightActions.java delete mode 100644 bundles/org.openhab.binding.kaleidescape/src/main/java/org/openhab/binding/kaleidescape/internal/IKaleidescapeThingActions.java delete mode 100644 bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/ILcnModuleActions.java delete mode 100644 bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/action/ILGWebOSActions.java rename bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/{ => internal}/action/LGWebOSActions.java (84%) delete mode 100644 bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/action/IDimmerActions.java rename bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/{ => internal}/action/DimmerActions.java (70%) delete mode 100644 bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/action/ISendMailActions.java rename bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/{ => internal}/action/SendMailActions.java (80%) delete mode 100644 bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/IMaxCubeActions.java delete mode 100644 bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/IMaxDevicesActions.java rename bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/{ => internal}/actions/MaxCubeActions.java (61%) rename bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/{ => internal}/actions/MaxDevicesActions.java (56%) delete mode 100644 bundles/org.openhab.binding.mpd/src/main/java/org/openhab/binding/mpd/internal/action/IMPDActions.java delete mode 100644 bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/action/IMQTTActions.java rename bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/{ => internal}/action/MQTTActions.java (71%) delete mode 100644 bundles/org.openhab.binding.network/src/main/java/org/openhab/binding/network/internal/action/INetworkActions.java delete mode 100644 bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/INuvoThingActions.java delete mode 100644 bundles/org.openhab.binding.onkyo/src/main/java/org/openhab/binding/onkyo/internal/automation/modules/OnkyoThingActionsService.java delete mode 100644 bundles/org.openhab.binding.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/action/IPushbulletActions.java delete mode 100644 bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/IRadioThermostatThingActions.java delete mode 100644 bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/action/ISatelEventLogActions.java rename bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/{ => internal}/action/SatelEventLogActions.java (74%) delete mode 100644 bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/bot/ITelegramActions.java rename bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/{bot => internal/action}/TelegramActions.java (81%) delete mode 100644 bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/action/IXMPPActions.java rename bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/{ => internal}/XMPPClientBindingConstants.java (94%) rename bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/{ => internal}/action/XMPPActions.java (58%) rename bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/{ => internal}/handler/PublishTriggerChannel.java (97%) rename bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/{ => internal}/handler/PublishTriggerChannelConfig.java (92%) rename bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/{ => internal}/handler/XMPPClientConfiguration.java (93%) rename bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/{ => internal}/handler/XMPPClientHandler.java (96%) rename bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/{ => internal}/handler/XMPPClientMessageSubscriber.java (91%) delete mode 100644 bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/action/IZmActions.java rename bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/{ => internal}/action/ZmActions.java (63%) 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") QuantityType getAzimuth( @ActionInput(name = "date", label = "Date", required = false, description = "Considered date") @Nullable ZonedDateTime date) { logger.debug("Astro action 'getAzimuth' called"); @@ -81,8 +73,7 @@ public class AstroActions implements ThingActions, IAstroActions { return null; } - @Override - @RuleAction(label = "Astro : Get Elevation", description = "Get the Elevation of the sun for a given time") + @RuleAction(label = "get the elevation", description = "Get the elevation for a given time.") public @Nullable @ActionOutput(name = "getElevation", label = "Elevation", type = "org.openhab.core.library.types.QuantityType") QuantityType getElevation( @ActionInput(name = "date", label = "Date", required = false, description = "Considered date") @Nullable ZonedDateTime date) { logger.debug("Astro action 'getElevation' called"); @@ -95,8 +86,7 @@ public class AstroActions implements ThingActions, IAstroActions { return null; } - @Override - @RuleAction(label = "Sun : Get Event Time", description = "Get the date time of a given planet event") + @RuleAction(label = "get the date time of a sun event", description = "Get the date time of a sun event.") public @Nullable @ActionOutput(name = "getEventTime", type = "java.time.ZonedDateTime") ZonedDateTime getEventTime( @ActionInput(name = "phaseName", label = "Phase", required = true, description = "Requested phase") String phaseName, @ActionInput(name = "date", label = "Date", required = false, description = "Considered date") @Nullable ZonedDateTime date, @@ -124,39 +114,32 @@ public class AstroActions implements ThingActions, IAstroActions { public static @Nullable QuantityType getElevation(@Nullable ThingActions actions, @Nullable ZonedDateTime date) { - return invokeMethodOf(actions).getElevation(date); + if (actions instanceof AstroActions) { + return ((AstroActions) actions).getElevation(date); + } else { + throw new IllegalArgumentException("Actions is not an instance of AstroActions"); + } } public static @Nullable QuantityType getAzimuth(@Nullable ThingActions actions, @Nullable ZonedDateTime date) { - return invokeMethodOf(actions).getAzimuth(date); + if (actions instanceof AstroActions) { + return ((AstroActions) actions).getAzimuth(date); + } else { + throw new IllegalArgumentException("Actions is not an instance of AstroActions"); + } } public static @Nullable ZonedDateTime getEventTime(@Nullable ThingActions actions, @Nullable String phaseName, @Nullable ZonedDateTime date, @Nullable String moment) { - if (phaseName != null) { - return invokeMethodOf(actions).getEventTime(phaseName, date, moment); - } else { - throw new IllegalArgumentException("phaseName can not be null"); - } - } - - private static IAstroActions invokeMethodOf(@Nullable ThingActions actions) { - if (actions == null) { - throw new IllegalArgumentException("actions cannot be null"); - } - if (actions.getClass().getName().equals(AstroActions.class.getName())) { - if (actions instanceof IAstroActions) { - return (IAstroActions) actions; + if (actions instanceof AstroActions) { + if (phaseName != null) { + return ((AstroActions) actions).getEventTime(phaseName, date, moment); } else { - return (IAstroActions) Proxy.newProxyInstance(IAstroActions.class.getClassLoader(), - new Class[] { IAstroActions.class }, (Object proxy, Method method, Object[] args) -> { - Method m = actions.getClass().getDeclaredMethod(method.getName(), - method.getParameterTypes()); - return m.invoke(actions, args); - }); + throw new IllegalArgumentException("phaseName can not be null"); } + } else { + throw new IllegalArgumentException("Actions is not an instance of AstroActions"); } - throw new IllegalArgumentException("Actions is not an instance of AstroActions"); } } diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/action/IAstroActions.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/action/IAstroActions.java deleted file mode 100644 index c0feeffa1..000000000 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/action/IAstroActions.java +++ /dev/null @@ -1,36 +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.astro.internal.action; - -import java.time.ZonedDateTime; - -import javax.measure.quantity.Angle; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.openhab.core.library.types.QuantityType; - -/** - * The {@link IAstroActions} defines the interface for all thing actions supported by the binding. - * - * @author Gaël L'hopital - Initial contribution - */ -@NonNullByDefault -public interface IAstroActions { - public @Nullable ZonedDateTime getEventTime(String phaseName, @Nullable ZonedDateTime date, - @Nullable String moment); - - public @Nullable QuantityType getAzimuth(@Nullable ZonedDateTime date); - - public @Nullable QuantityType getElevation(@Nullable ZonedDateTime date); -} diff --git a/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/actions/AutomowerActions.java b/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/actions/AutomowerActions.java index e63f453ce..1086a0bfc 100644 --- a/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/actions/AutomowerActions.java +++ b/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/actions/AutomowerActions.java @@ -12,9 +12,6 @@ */ package org.openhab.binding.automower.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.automower.internal.things.AutomowerCommand; @@ -32,7 +29,7 @@ import org.slf4j.LoggerFactory; */ @ThingActionsScope(name = "automower") @NonNullByDefault -public class AutomowerActions implements ThingActions, IAutomowerActions { +public class AutomowerActions implements ThingActions { private final Logger logger = LoggerFactory.getLogger(AutomowerActions.class); private @Nullable AutomowerHandler handler; @@ -46,7 +43,6 @@ public class AutomowerActions implements ThingActions, IAutomowerActions { return handler; } - @Override @RuleAction(label = "@text/action-start-label", description = "@text/action-start-desc") public void start( @ActionInput(name = "duration", label = "@text/action-input-duration-label", description = "@text/action-input-duration-desc") int durationMin) { @@ -59,10 +55,13 @@ public class AutomowerActions implements ThingActions, IAutomowerActions { } public static void start(@Nullable ThingActions actions, int durationMin) { - invokeMethodOf(actions).start(durationMin); + if (actions instanceof AutomowerActions) { + ((AutomowerActions) actions).start(durationMin); + } else { + throw new IllegalArgumentException("Actions is not an instance of AutomowerActions"); + } } - @Override @RuleAction(label = "@text/action-pause-label", description = "@text/action-pause-desc") public void pause() { AutomowerHandler automowerHandler = handler; @@ -74,10 +73,13 @@ public class AutomowerActions implements ThingActions, IAutomowerActions { } public static void pause(@Nullable ThingActions actions) { - invokeMethodOf(actions).pause(); + if (actions instanceof AutomowerActions) { + ((AutomowerActions) actions).pause(); + } else { + throw new IllegalArgumentException("Actions is not an instance of AutomowerActions"); + } } - @Override @RuleAction(label = "@text/action-parkuntilnextschedule-label", description = "@text/action-parkuntilnextschedule-desc") public void parkUntilNextSchedule() { AutomowerHandler automowerHandler = handler; @@ -89,10 +91,13 @@ public class AutomowerActions implements ThingActions, IAutomowerActions { } public static void parkUntilNextSchedule(@Nullable ThingActions actions) { - invokeMethodOf(actions).parkUntilNextSchedule(); + if (actions instanceof AutomowerActions) { + ((AutomowerActions) actions).parkUntilNextSchedule(); + } else { + throw new IllegalArgumentException("Actions is not an instance of AutomowerActions"); + } } - @Override @RuleAction(label = "@text/action-parkuntilfurthernotice-label", description = "@text/action-parkuntilfurthernotice-desc") public void parkUntilFurtherNotice() { AutomowerHandler automowerHandler = handler; @@ -104,10 +109,13 @@ public class AutomowerActions implements ThingActions, IAutomowerActions { } public static void parkUntilFurtherNotice(@Nullable ThingActions actions) { - invokeMethodOf(actions).parkUntilFurtherNotice(); + if (actions instanceof AutomowerActions) { + ((AutomowerActions) actions).parkUntilFurtherNotice(); + } else { + throw new IllegalArgumentException("Actions is not an instance of AutomowerActions"); + } } - @Override @RuleAction(label = "@text/action-park-label", description = "@text/action-park-desc") public void park( @ActionInput(name = "duration", label = "@text/action-input-duration-label", description = "@text/action-input-duration-desc") int durationMin) { @@ -120,10 +128,13 @@ public class AutomowerActions implements ThingActions, IAutomowerActions { } public static void park(@Nullable ThingActions actions, int durationMin) { - invokeMethodOf(actions).park(durationMin); + if (actions instanceof AutomowerActions) { + ((AutomowerActions) actions).park(durationMin); + } else { + throw new IllegalArgumentException("Actions is not an instance of AutomowerActions"); + } } - @Override @RuleAction(label = "@text/action-resumeschedule-label", description = "@text/action-resumeschedule-desc") public void resumeSchedule() { AutomowerHandler automowerHandler = handler; @@ -135,25 +146,10 @@ public class AutomowerActions implements ThingActions, IAutomowerActions { } public static void resumeSchedule(@Nullable ThingActions actions) { - invokeMethodOf(actions).resumeSchedule(); - } - - private static IAutomowerActions invokeMethodOf(@Nullable ThingActions actions) { - if (actions == null) { - throw new IllegalArgumentException("actions cannot be null"); + if (actions instanceof AutomowerActions) { + ((AutomowerActions) actions).resumeSchedule(); + } else { + throw new IllegalArgumentException("Actions is not an instance of AutomowerActions"); } - if (actions.getClass().getName().equals(AutomowerActions.class.getName())) { - if (actions instanceof AutomowerActions) { - return (IAutomowerActions) actions; - } else { - return (IAutomowerActions) Proxy.newProxyInstance(IAutomowerActions.class.getClassLoader(), - new Class[] { IAutomowerActions.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 IAutomowerActions"); } } diff --git a/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/actions/IAutomowerActions.java b/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/actions/IAutomowerActions.java deleted file mode 100644 index 553401b13..000000000 --- a/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/actions/IAutomowerActions.java +++ /dev/null @@ -1,36 +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.automower.internal.actions; - -import org.eclipse.jdt.annotation.NonNullByDefault; - -/** - * Actions that can be executed for an automower - * - * @author Markus Pfleger - Initial contribution - */ -@NonNullByDefault -public interface IAutomowerActions { - - void resumeSchedule(); - - void park(int durationMin); - - void parkUntilFurtherNotice(); - - void parkUntilNextSchedule(); - - void pause(); - - void start(int durationMin); -} diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/actions/AVMFritzHeatingActions.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/actions/AVMFritzHeatingActions.java similarity index 66% rename from bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/actions/AVMFritzHeatingActions.java rename to bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/actions/AVMFritzHeatingActions.java index 662beefcd..ef5530b48 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/actions/AVMFritzHeatingActions.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/actions/AVMFritzHeatingActions.java @@ -10,22 +10,16 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.avmfritz.actions; - -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; +package org.openhab.binding.avmfritz.internal.actions; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.avmfritz.internal.actions.IAVMFritzHeatingActions; import org.openhab.binding.avmfritz.internal.handler.AVMFritzHeatingActionsHandler; 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 AVMFritzHeatingActions} defines thing actions for heating devices / groups of the avmfritz binding. @@ -34,9 +28,7 @@ import org.slf4j.LoggerFactory; */ @ThingActionsScope(name = "avmfritz") @NonNullByDefault -public class AVMFritzHeatingActions implements ThingActions, IAVMFritzHeatingActions { - - private final Logger logger = LoggerFactory.getLogger(AVMFritzHeatingActions.class); +public class AVMFritzHeatingActions implements ThingActions { private @Nullable AVMFritzHeatingActionsHandler handler; @@ -50,7 +42,6 @@ public class AVMFritzHeatingActions implements ThingActions, IAVMFritzHeatingAct return handler; } - @Override @RuleAction(label = "@text/setBoostModeModeActionLabel", description = "@text/setBoostModeActionDescription") public void setBoostMode( @ActionInput(name = "Duration", label = "@text/setBoostModeDurationInputLabel", description = "@text/setBoostModeDurationInputDescription", type = "java.lang.Long", required = true) @Nullable Long duration) { @@ -65,10 +56,13 @@ public class AVMFritzHeatingActions implements ThingActions, IAVMFritzHeatingAct } public static void setBoostMode(@Nullable ThingActions actions, @Nullable Long duration) { - invokeMethodOf(actions).setBoostMode(duration); + if (actions instanceof AVMFritzHeatingActions) { + ((AVMFritzHeatingActions) actions).setBoostMode(duration); + } else { + throw new IllegalArgumentException("Actions is not an instance of AVMFritzHeatingActions"); + } } - @Override @RuleAction(label = "@text/setWindowOpenModeActionLabel", description = "@text/setWindowOpenModeActionDescription") public void setWindowOpenMode( @ActionInput(name = "Duration", label = "@text/setWindowOpenModeDurationInputLabel", description = "@text/setWindowOpenModeDurationInputDescription", type = "java.lang.Long", required = true) @Nullable Long duration) { @@ -83,25 +77,10 @@ public class AVMFritzHeatingActions implements ThingActions, IAVMFritzHeatingAct } public static void setWindowOpenMode(@Nullable ThingActions actions, @Nullable Long duration) { - invokeMethodOf(actions).setWindowOpenMode(duration); - } - - private static IAVMFritzHeatingActions invokeMethodOf(@Nullable ThingActions actions) { - if (actions == null) { - throw new IllegalArgumentException("actions cannot be null"); + if (actions instanceof AVMFritzHeatingActions) { + ((AVMFritzHeatingActions) actions).setWindowOpenMode(duration); + } else { + throw new IllegalArgumentException("Actions is not an instance of AVMFritzHeatingActions"); } - if (actions.getClass().getName().equals(AVMFritzHeatingActions.class.getName())) { - if (actions instanceof IAVMFritzHeatingActions) { - return (IAVMFritzHeatingActions) actions; - } else { - return (IAVMFritzHeatingActions) Proxy.newProxyInstance(IAVMFritzHeatingActions.class.getClassLoader(), - new Class[] { IAVMFritzHeatingActions.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 AVMFritzHeatingActions"); } } diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/actions/IAVMFritzHeatingActions.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/actions/IAVMFritzHeatingActions.java deleted file mode 100644 index 0c30df92a..000000000 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/actions/IAVMFritzHeatingActions.java +++ /dev/null @@ -1,31 +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.avmfritz.internal.actions; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.avmfritz.actions.AVMFritzHeatingActions; - -/** - * The {@link IAVMFritzHeatingActions} defines the interface for all thing actions supported by the binding. - * These methods, parameters, and return types are explained in {@link AVMFritzHeatingActions}. - * - * @author Christoph Weitkamp - Initial contribution - */ -@NonNullByDefault -public interface IAVMFritzHeatingActions { - - void setBoostMode(@Nullable Long duration); - - void setWindowOpenMode(@Nullable Long duration); -} diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzHeatingActionsHandler.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzHeatingActionsHandler.java index 8be206f50..7f1cf572e 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzHeatingActionsHandler.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzHeatingActionsHandler.java @@ -16,7 +16,7 @@ import java.util.Collection; import java.util.Collections; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.binding.avmfritz.actions.AVMFritzHeatingActions; +import org.openhab.binding.avmfritz.internal.actions.AVMFritzHeatingActions; import org.openhab.core.thing.binding.ThingHandler; import org.openhab.core.thing.binding.ThingHandlerService; diff --git a/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/actions/AVMFritzHeatingActionsTest.java b/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/actions/AVMFritzHeatingActionsTest.java similarity index 98% rename from bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/actions/AVMFritzHeatingActionsTest.java rename to bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/actions/AVMFritzHeatingActionsTest.java index a18edccc4..f0f586573 100644 --- a/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/actions/AVMFritzHeatingActionsTest.java +++ b/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/actions/AVMFritzHeatingActionsTest.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.avmfritz.actions; +package org.openhab.binding.avmfritz.internal.actions; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/action/IDmxActions.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/action/IDmxActions.java deleted file mode 100644 index 944404426..000000000 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/action/IDmxActions.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.dmx.action; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * The {@link IDmxActions} defines the actions for DMX Bridges - * - * @author Laurent Garnier - Initial contribution - */ -@NonNullByDefault -public interface IDmxActions { - - public void sendFade(@Nullable String channels, @Nullable String fade, @Nullable Boolean resumeAfter); -} diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxBridgeHandler.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxBridgeHandler.java index 59a74d60a..bf06dd2ac 100644 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxBridgeHandler.java +++ b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxBridgeHandler.java @@ -21,7 +21,7 @@ import java.util.List; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import org.openhab.binding.dmx.action.DmxActions; +import org.openhab.binding.dmx.internal.action.DmxActions; import org.openhab.binding.dmx.internal.action.FadeAction; import org.openhab.binding.dmx.internal.action.ResumeAction; import org.openhab.binding.dmx.internal.config.DmxBridgeHandlerConfiguration; diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/action/DmxActions.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/action/DmxActions.java similarity index 61% rename from bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/action/DmxActions.java rename to bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/action/DmxActions.java index cbbf729f2..0e92e881a 100644 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/action/DmxActions.java +++ b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/action/DmxActions.java @@ -10,10 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.dmx.action; - -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; +package org.openhab.binding.dmx.internal.action; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -28,29 +25,23 @@ import org.slf4j.LoggerFactory; /** * The {@link DmxActions} provides actions for DMX Bridges - *

- * 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 coolHoldTemp, - @Nullable QuantityType heatHoldTemp, @Nullable Date startDateTime, @Nullable Date endDateTime, - @Nullable String fan, @Nullable Number fanMinOnTime); - - public Boolean deleteVacation(@Nullable String name); - - public Boolean resetPreferences(); - - public Boolean resumeProgram(@Nullable Boolean resumeAll); - - public Boolean setHold(@Nullable QuantityType coolHoldTemp, - @Nullable QuantityType heatHoldTemp); - - public Boolean setHold(@Nullable QuantityType coolHoldTemp, - @Nullable QuantityType heatHoldTemp, @Nullable Number holdHours); - - public Boolean setHold(@Nullable String holdClimateRef); - - public Boolean setHold(@Nullable String holdClimateRef, @Nullable Number holdHours); - - public Boolean setHold(@Nullable QuantityType coolHoldTemp, - @Nullable QuantityType heatHoldTemp, @Nullable String holdClimateRef, - @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType, - @Nullable Number holdHours); - - public Boolean setHold(@Nullable Map params, @Nullable String holdType, @Nullable Number holdHours, - @Nullable Date startDateTime, @Nullable Date endDateTime); - - public Boolean setOccupied(@Nullable Boolean occupied, @Nullable Date startDateTime, @Nullable Date endDateTime, - @Nullable String holdType, @Nullable Number holdHours); - - public Boolean updateSensor(@Nullable String name, @Nullable String deviceId, @Nullable String sensorId); - - public @Nullable String getAlerts(); - - public @Nullable String getEvents(); - - public @Nullable String getClimates(); -} diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/action/EcobeeActions.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java similarity index 80% rename from bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/action/EcobeeActions.java rename to bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java index eea101b75..fbf788f11 100644 --- a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/action/EcobeeActions.java +++ b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java @@ -10,10 +10,8 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.ecobee.action; +package org.openhab.binding.ecobee.internal.action; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -52,11 +50,6 @@ import org.slf4j.LoggerFactory; /** * The {@link EcobeeActions} defines the thing actions for the Ecobee binding. - *

- * 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 coolHoldTemp, @@ -200,8 +179,12 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { @Nullable QuantityType coolHoldTemp, @Nullable QuantityType heatHoldTemp, @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String fan, @Nullable Number fanMinOnTime) { - return invokeMethodOf(actions).createVacation(name, coolHoldTemp, heatHoldTemp, startDateTime, endDateTime, fan, - fanMinOnTime); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).createVacation(name, coolHoldTemp, heatHoldTemp, startDateTime, + endDateTime, fan, fanMinOnTime); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** @@ -210,8 +193,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { * @see Delete * Vacation */ - @Override - @RuleAction(label = "Delete Vacation", description = "The delete vacation function deletes a vacation event from a thermostat.") + @RuleAction(label = "delete a vacation", description = "The delete vacation function deletes a vacation event from a thermostat.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean deleteVacation( @ActionInput(name = "name", description = "The vacation event name to delete.") @Nullable String name) { LOGGER.debug("EcobeeActions: Action 'Delete Vacation' called"); @@ -225,7 +207,11 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { } public static boolean deleteVacation(@Nullable ThingActions actions, @Nullable String name) { - return invokeMethodOf(actions).deleteVacation(name); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).deleteVacation(name); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** @@ -234,8 +220,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { * @see Reset * Preferences */ - @Override - @RuleAction(label = "Reset Preferences", description = "The reset preferences function sets all of the user configurable settings back to the factory default values.") + @RuleAction(label = "reset the preferences", description = "The reset preferences function sets all of the user configurable settings back to the factory default values.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean resetPreferences() { LOGGER.debug("EcobeeActions: Action 'Reset Preferences' called"); EcobeeThermostatBridgeHandler localHandler = handler; @@ -248,7 +233,11 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { } public static boolean resetPreferences(@Nullable ThingActions actions) { - return invokeMethodOf(actions).resetPreferences(); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).resetPreferences(); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** @@ -257,8 +246,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { * @see Resume * Program */ - @Override - @RuleAction(label = "Resume Program", description = "Removes the currently running event providing the event is not a mandatory demand response event") + @RuleAction(label = "resume the program", description = "Removes the currently running event providing the event is not a mandatory demand response event") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean resumeProgram( @ActionInput(name = "resumeAll", description = "(opt) Should the thermostat be resumed to next event (false) or to its program (true)") @Nullable Boolean resumeAll) { LOGGER.debug("EcobeeActions: Action 'Resume Program' called"); @@ -272,7 +260,11 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { } public static boolean resumeProgram(@Nullable ThingActions actions, @Nullable Boolean resumeAll) { - return invokeMethodOf(actions).resumeProgram(resumeAll); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).resumeProgram(resumeAll); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** @@ -281,8 +273,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { * @see Send * Message */ - @Override - @RuleAction(label = "Send Message", description = "The send message function allows an alert message to be sent to the thermostat.") + @RuleAction(label = "send a message", description = "The send message function allows an alert message to be sent to the thermostat.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendMessage( @ActionInput(name = "text", description = "The message text to send. Text will be truncated to 500 characters if longer") @Nullable String text) { LOGGER.debug("EcobeeActions: Action 'SendMessage' called"); @@ -296,7 +287,11 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { } public static boolean sendMessage(@Nullable ThingActions actions, @Nullable String text) { - return invokeMethodOf(actions).sendMessage(text); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).sendMessage(text); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** @@ -304,8 +299,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { * * @see Set Hold */ - @Override - @RuleAction(label = "Set Hold", description = "The set hold function sets the thermostat into a hold with the specified temperatures.") + @RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified temperatures.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold( @ActionInput(name = "coolHoldTemp", description = "The temperature at which to set the cool hold.") @Nullable QuantityType coolHoldTemp, @ActionInput(name = "heatHoldTemp", description = "The temperature at which to set the heat hold.") @Nullable QuantityType heatHoldTemp) { @@ -320,14 +314,17 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { public static boolean setHold(@Nullable ThingActions actions, @Nullable QuantityType coolHoldTemp, @Nullable QuantityType heatHoldTemp) { - return invokeMethodOf(actions).setHold(coolHoldTemp, heatHoldTemp); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** * Set a hold by providing the cool and heat temperatures and the number of hours. */ - @Override - @RuleAction(label = "Set Hold", description = "The set hold function sets the thermostat into a hold for the specified number of hours.") + @RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold for the specified number of hours.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold( @ActionInput(name = "coolHoldTemp", description = "The temperature at which to set the cool hold.") @Nullable QuantityType coolHoldTemp, @ActionInput(name = "heatHoldTemp", description = "The temperature at which to set the heat hold.") @Nullable QuantityType heatHoldTemp, @@ -348,14 +345,17 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { public static boolean setHold(@Nullable ThingActions actions, @Nullable QuantityType coolHoldTemp, @Nullable QuantityType heatHoldTemp, @Nullable Number holdHours) { - return invokeMethodOf(actions).setHold(coolHoldTemp, heatHoldTemp, holdHours); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp, holdHours); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** * Set an indefinite hold using the supplied climateRef */ - @Override - @RuleAction(label = "Set Hold", description = "The set hold function sets the thermostat into a hold with the specified climate ref.") + @RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified climate ref.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold( @ActionInput(name = "holdClimateRef", description = "The holdClimateRef used to set the hold.") @Nullable String holdClimateRef) { EcobeeThermostatBridgeHandler localHandler = handler; @@ -372,14 +372,17 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { } public static boolean setHold(@Nullable ThingActions actions, @Nullable String holdClimateRef) { - return invokeMethodOf(actions).setHold(holdClimateRef); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).setHold(holdClimateRef); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** * Set a hold using the supplied climateRef for the supplied number of hours. */ - @Override - @RuleAction(label = "Set Hold", description = "The set hold function sets the thermostat into a hold with the specified climate ref.") + @RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified climate ref.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold( @ActionInput(name = "holdClimateRef", description = "The holdClimateRef used to set the hold.") @Nullable String holdClimateRef, @ActionInput(name = "holdHours", description = "The number of hours for the hold.") @Nullable Number holdHours) { @@ -403,14 +406,17 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { public static boolean setHold(@Nullable ThingActions actions, @Nullable String holdClimateRef, @Nullable Number holdHours) { - return invokeMethodOf(actions).setHold(holdClimateRef, holdHours); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).setHold(holdClimateRef, holdHours); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** * Set a hold */ - @Override - @RuleAction(label = "Set Hold", description = "The set hold function sets the thermostat into a hold with the specified temperature or climate ref.") + @RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified temperature or climate ref.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold( @ActionInput(name = "coolHoldTemp", description = "(opt) The temperature at which to set the cool hold.") @Nullable QuantityType coolHoldTemp, @ActionInput(name = "heatHoldTemp", description = "(opt) The temperature at which to set the heat hold.") @Nullable QuantityType heatHoldTemp, @@ -436,15 +442,18 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { @Nullable QuantityType heatHoldTemp, @Nullable String holdClimateRef, @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType, @Nullable Number holdHours) { - return invokeMethodOf(actions).setHold(coolHoldTemp, heatHoldTemp, holdClimateRef, startDateTime, endDateTime, - holdType, holdHours); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp, holdClimateRef, startDateTime, + endDateTime, holdType, holdHours); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** * Set a hold by providing a parameter map */ - @Override - @RuleAction(label = "Set Hold", description = "The set hold function sets the thermostat into a hold with the specified event parameters.") + @RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified event parameters.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold( @ActionInput(name = "params", description = "The map of hold parameters.") @Nullable Map params, @ActionInput(name = "holdType", description = "(opt) The hold duration type. Valid values: dateTime, nextTransition, indefinite, holdHours.") @Nullable String holdType, @@ -522,7 +531,11 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { public static boolean setHold(@Nullable ThingActions actions, @Nullable Map params, @Nullable String holdType, @Nullable Number holdHours, @Nullable Date startDateTime, @Nullable Date endDateTime) { - return invokeMethodOf(actions).setHold(params, holdType, holdHours, startDateTime, endDateTime); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).setHold(params, holdType, holdHours, startDateTime, endDateTime); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** @@ -532,8 +545,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { * @see Set * Occupied */ - @Override - @RuleAction(label = "Set Occupied", description = "The function switches a thermostat from occupied mode to unoccupied, or vice versa (EMS MODELS ONLY).") + @RuleAction(label = "switch the thermostat occupancy", description = "The function switches a thermostat from occupied mode to unoccupied, or vice versa (EMS MODELS ONLY).") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setOccupied( @ActionInput(name = "occupied", description = "The climate to use for the temperature, occupied (true) or unoccupied (false).") @Nullable Boolean occupied, @ActionInput(name = "startDateTime", description = "(opt) The start date in thermostat time.") @Nullable Date startDateTime, @@ -555,7 +567,11 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { public static boolean setOccupied(@Nullable ThingActions actions, @Nullable Boolean occupied, @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType, @Nullable Number holdHours) { - return invokeMethodOf(actions).setOccupied(occupied, startDateTime, endDateTime, holdType, holdHours); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).setOccupied(occupied, startDateTime, endDateTime, holdType, holdHours); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** @@ -564,8 +580,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { * @see Update * Sensor */ - @Override - @RuleAction(label = "Update Sensor", description = "The update sensor function allows the caller to update the name of an ecobee3 remote sensor.") + @RuleAction(label = "update a remote sensor name", description = "The update sensor function allows the caller to update the name of an ecobee3 remote sensor.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean updateSensor( @ActionInput(name = "name", description = "The updated name to give the sensor. Has a max length of 32, but shorter is recommended.") @Nullable String name, @ActionInput(name = "deviceId", description = "The deviceId for the sensor, typically this indicates the enclosure and corresponds to the ThermostatRemoteSensor.id field. For example: rs:100") @Nullable String deviceId, @@ -582,14 +597,17 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { public static boolean updateSensor(@Nullable ThingActions actions, @Nullable String name, @Nullable String deviceId, @Nullable String sensorId) { - return invokeMethodOf(actions).updateSensor(name, deviceId, sensorId); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).updateSensor(name, deviceId, sensorId); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** * Get the alerts list. Returns a JSON string containing all the alerts. */ - @Override - @RuleAction(label = "Get Alerts", description = "Get the alerts list") + @RuleAction(label = "get the alerts", description = "Get the alerts list.") public @ActionOutput(name = "alerts", type = "java.lang.String") @Nullable String getAlerts() { LOGGER.debug("EcobeeActions: Action 'Get Alerts' called"); EcobeeThermostatBridgeHandler localHandler = handler; @@ -601,14 +619,17 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { } public static @Nullable String getAlerts(@Nullable ThingActions actions) { - return invokeMethodOf(actions).getAlerts(); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).getAlerts(); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** * Get the events list. Returns a JSON string contains all events. */ - @Override - @RuleAction(label = "Get Events", description = "Get the events list") + @RuleAction(label = "get the events", description = "Get the events list.") public @ActionOutput(name = "events", type = "java.lang.String") @Nullable String getEvents() { LOGGER.debug("EcobeeActions: Action 'Get Events' called"); EcobeeThermostatBridgeHandler localHandler = handler; @@ -620,14 +641,17 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { } public static @Nullable String getEvents(@Nullable ThingActions actions) { - return invokeMethodOf(actions).getEvents(); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).getEvents(); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } /** * Get a list of climates. Returns a JSON string contains all climates. */ - @Override - @RuleAction(label = "Get Climates", description = "Get a list of climates") + @RuleAction(label = "get the climates", description = "Get a list of climates.") public @ActionOutput(name = "climates", type = "java.lang.String") @Nullable String getClimates() { LOGGER.debug("EcobeeActions: Action 'Get Climates' called"); EcobeeThermostatBridgeHandler localHandler = handler; @@ -639,6 +663,10 @@ public class EcobeeActions implements ThingActions, IEcobeeActions { } public static @Nullable String getClimates(@Nullable ThingActions actions) { - return invokeMethodOf(actions).getClimates(); + if (actions instanceof EcobeeActions) { + return ((EcobeeActions) actions).getClimates(); + } else { + throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); + } } } diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeThermostatBridgeHandler.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeThermostatBridgeHandler.java index 1e2b2d17f..a6df47edb 100644 --- a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeThermostatBridgeHandler.java +++ b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeThermostatBridgeHandler.java @@ -32,7 +32,7 @@ import javax.measure.Unit; import org.apache.commons.lang.WordUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.ecobee.action.EcobeeActions; +import org.openhab.binding.ecobee.internal.action.EcobeeActions; import org.openhab.binding.ecobee.internal.api.EcobeeApi; import org.openhab.binding.ecobee.internal.config.EcobeeThermostatConfiguration; import org.openhab.binding.ecobee.internal.discovery.SensorDiscoveryService; diff --git a/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/actions/IEnigma2Actions.java b/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/actions/IEnigma2Actions.java deleted file mode 100644 index 591d2565c..000000000 --- a/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/actions/IEnigma2Actions.java +++ /dev/null @@ -1,41 +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.enigma2.actions; - -import org.eclipse.jdt.annotation.NonNullByDefault; - -/** - * The {@link IEnigma2Actions} defines the interface for all thing actions supported by the binding. - * - * @author Guido Dolfen - Initial contribution - */ -@NonNullByDefault -public interface IEnigma2Actions { - void sendRcCommand(String rcButton); - - void sendInfo(String text); - - void sendInfo(String text, int timeout); - - void sendWarning(String text); - - void sendWarning(String text, int timeout); - - void sendError(String text); - - void sendError(String text, int timeout); - - void sendQuestion(String text); - - void sendQuestion(String text, int timeout); -} diff --git a/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/Enigma2HandlerFactory.java b/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/Enigma2HandlerFactory.java index 002faee91..1e8a6a7b0 100644 --- a/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/Enigma2HandlerFactory.java +++ b/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/Enigma2HandlerFactory.java @@ -16,7 +16,7 @@ import static org.openhab.binding.enigma2.internal.Enigma2BindingConstants.*; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.enigma2.handler.Enigma2Handler; +import org.openhab.binding.enigma2.internal.handler.Enigma2Handler; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.binding.BaseThingHandlerFactory; diff --git a/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/actions/Enigma2Actions.java b/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/actions/Enigma2Actions.java similarity index 74% rename from bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/actions/Enigma2Actions.java rename to bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/actions/Enigma2Actions.java index e2806fa66..258fd239d 100644 --- a/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/actions/Enigma2Actions.java +++ b/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/actions/Enigma2Actions.java @@ -10,15 +10,12 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.enigma2.actions; - -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; +package org.openhab.binding.enigma2.internal.actions; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.enigma2.handler.Enigma2Handler; import org.openhab.binding.enigma2.internal.Enigma2BindingConstants; +import org.openhab.binding.enigma2.internal.handler.Enigma2Handler; import org.openhab.core.automation.annotation.ActionInput; import org.openhab.core.automation.annotation.RuleAction; import org.openhab.core.thing.binding.ThingActions; @@ -33,7 +30,7 @@ import org.openhab.core.thing.binding.ThingHandler; */ @ThingActionsScope(name = "enigma2") @NonNullByDefault -public class Enigma2Actions implements ThingActions, IEnigma2Actions { +public class Enigma2Actions implements ThingActions { private @Nullable Enigma2Handler handler; @Override @@ -43,10 +40,9 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions { @Override public @Nullable Enigma2Handler getThingHandler() { - return this.handler; + return handler; } - @Override @RuleAction(label = "@text/actions.enigma2.send-rc-button.label", description = "@text/actions.enigma2.send-rc-button.description") @SuppressWarnings("null") public void sendRcCommand( @@ -54,7 +50,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions { handler.sendRcCommand(rcButton); } - @Override @RuleAction(label = "@text/actions.enigma2.send-info.label", description = "@text/actions.enigma2.send-info.description") @SuppressWarnings("null") public void sendInfo( @@ -62,7 +57,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions { handler.sendInfo(Enigma2BindingConstants.MESSAGE_TIMEOUT, text); } - @Override @RuleAction(label = "@text/actions.enigma2.send-info.label", description = "@text/actions.enigma2.send-info.description") @SuppressWarnings("null") public void sendInfo( @@ -71,7 +65,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions { handler.sendInfo(timeout, text); } - @Override @RuleAction(label = "@text/actions.enigma2.send-warning.label", description = "@text/actions.enigma2.send-warning.description") @SuppressWarnings("null") public void sendWarning( @@ -79,7 +72,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions { handler.sendWarning(Enigma2BindingConstants.MESSAGE_TIMEOUT, text); } - @Override @RuleAction(label = "@text/actions.enigma2.send-warning.label", description = "@text/actions.enigma2.send-warning.description") @SuppressWarnings("null") public void sendWarning( @@ -88,7 +80,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions { handler.sendWarning(timeout, text); } - @Override @RuleAction(label = "@text/actions.enigma2.send-error.label", description = "@text/actions.enigma2.send-error.description") @SuppressWarnings("null") public void sendError( @@ -96,7 +87,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions { handler.sendError(Enigma2BindingConstants.MESSAGE_TIMEOUT, text); } - @Override @RuleAction(label = "@text/actions.enigma2.send-error.label", description = "@text/actions.enigma2.send-error.description") @SuppressWarnings("null") public void sendError( @@ -105,7 +95,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions { handler.sendError(timeout, text); } - @Override @RuleAction(label = "@text/actions.enigma2.send-error.label", description = "@text/actions.enigma2.send-question.description") @SuppressWarnings("null") public void sendQuestion( @@ -113,7 +102,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions { handler.sendQuestion(Enigma2BindingConstants.MESSAGE_TIMEOUT, text); } - @Override @RuleAction(label = "@text/actions.enigma2.send-error.label", description = "@text/actions.enigma2.send-question.description") @SuppressWarnings("null") public void sendQuestion( @@ -124,57 +112,74 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions { // delegation methods for "legacy" rule support public static void sendRcCommand(@Nullable ThingActions actions, String rcButton) { - invokeMethodOf(actions).sendRcCommand(rcButton); + if (actions instanceof Enigma2Actions) { + ((Enigma2Actions) actions).sendRcCommand(rcButton); + } else { + throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); + } } public static void sendInfo(@Nullable ThingActions actions, String info) { - invokeMethodOf(actions).sendInfo(info); + if (actions instanceof Enigma2Actions) { + ((Enigma2Actions) actions).sendInfo(info); + } else { + throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); + } } public static void sendInfo(@Nullable ThingActions actions, String info, int timeout) { - invokeMethodOf(actions).sendInfo(info, timeout); + if (actions instanceof Enigma2Actions) { + ((Enigma2Actions) actions).sendInfo(info, timeout); + } else { + throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); + } } public static void sendWarning(@Nullable ThingActions actions, String warning) { - invokeMethodOf(actions).sendWarning(warning); + if (actions instanceof Enigma2Actions) { + ((Enigma2Actions) actions).sendWarning(warning); + } else { + throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); + } } public static void sendWarning(@Nullable ThingActions actions, String warning, int timeout) { - invokeMethodOf(actions).sendWarning(warning, timeout); + if (actions instanceof Enigma2Actions) { + ((Enigma2Actions) actions).sendWarning(warning, timeout); + } else { + throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); + } } public static void sendError(@Nullable ThingActions actions, String error) { - invokeMethodOf(actions).sendError(error); + if (actions instanceof Enigma2Actions) { + ((Enigma2Actions) actions).sendError(error); + } else { + throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); + } } public static void sendError(@Nullable ThingActions actions, String error, int timeout) { - invokeMethodOf(actions).sendError(error, timeout); + if (actions instanceof Enigma2Actions) { + ((Enigma2Actions) actions).sendError(error, timeout); + } else { + throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); + } } public static void sendQuestion(@Nullable ThingActions actions, String text) { - invokeMethodOf(actions).sendQuestion(text); + if (actions instanceof Enigma2Actions) { + ((Enigma2Actions) actions).sendQuestion(text); + } else { + throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); + } } public static void sendQuestion(@Nullable ThingActions actions, String text, int timeout) { - invokeMethodOf(actions).sendQuestion(text, timeout); - } - - private static IEnigma2Actions invokeMethodOf(@Nullable ThingActions actions) { - if (actions == null) { - throw new IllegalArgumentException("actions cannot be null"); + if (actions instanceof Enigma2Actions) { + ((Enigma2Actions) actions).sendQuestion(text, timeout); + } else { + throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); } - if (actions.getClass().getName().equals(Enigma2Actions.class.getName())) { - if (actions instanceof IEnigma2Actions) { - return (IEnigma2Actions) actions; - } else { - return (IEnigma2Actions) Proxy.newProxyInstance(IEnigma2Actions.class.getClassLoader(), - new Class[] { IEnigma2Actions.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 Enigma2Actions"); } } diff --git a/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/handler/Enigma2Handler.java b/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/handler/Enigma2Handler.java similarity index 99% rename from bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/handler/Enigma2Handler.java rename to bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/handler/Enigma2Handler.java index 8bf429440..1b7171a60 100644 --- a/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/handler/Enigma2Handler.java +++ b/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/handler/Enigma2Handler.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.enigma2.handler; +package org.openhab.binding.enigma2.internal.handler; import static org.openhab.binding.enigma2.internal.Enigma2BindingConstants.*; @@ -25,10 +25,10 @@ import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.enigma2.actions.Enigma2Actions; import org.openhab.binding.enigma2.internal.Enigma2Client; import org.openhab.binding.enigma2.internal.Enigma2Configuration; import org.openhab.binding.enigma2.internal.Enigma2RemoteKey; +import org.openhab.binding.enigma2.internal.actions.Enigma2Actions; import org.openhab.core.library.types.*; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; diff --git a/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/actions/Enigma2ActionsTest.java b/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/internal/actions/Enigma2ActionsTest.java similarity index 97% rename from bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/actions/Enigma2ActionsTest.java rename to bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/internal/actions/Enigma2ActionsTest.java index 827c76af9..2a9a7cf90 100644 --- a/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/actions/Enigma2ActionsTest.java +++ b/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/internal/actions/Enigma2ActionsTest.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.enigma2.actions; +package org.openhab.binding.enigma2.internal.actions; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; @@ -21,8 +21,8 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.openhab.binding.enigma2.handler.Enigma2Handler; import org.openhab.binding.enigma2.internal.Enigma2BindingConstants; +import org.openhab.binding.enigma2.internal.handler.Enigma2Handler; /** * The {@link Enigma2ActionsTest} class is responsible for testing {@link Enigma2Actions}. diff --git a/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/handler/Enigma2HandlerTest.java b/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/internal/handler/Enigma2HandlerTest.java similarity index 99% rename from bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/handler/Enigma2HandlerTest.java rename to bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/internal/handler/Enigma2HandlerTest.java index f5b2e63ef..f0c52bb38 100644 --- a/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/handler/Enigma2HandlerTest.java +++ b/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/internal/handler/Enigma2HandlerTest.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.enigma2.handler; +package org.openhab.binding.enigma2.internal.handler; import static org.eclipse.jdt.annotation.Checks.requireNonNull; import static org.hamcrest.MatcherAssert.assertThat; @@ -25,11 +25,11 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.openhab.binding.enigma2.actions.Enigma2Actions; import org.openhab.binding.enigma2.internal.Enigma2BindingConstants; import org.openhab.binding.enigma2.internal.Enigma2Client; import org.openhab.binding.enigma2.internal.Enigma2Configuration; import org.openhab.binding.enigma2.internal.Enigma2RemoteKey; +import org.openhab.binding.enigma2.internal.actions.Enigma2Actions; import org.openhab.core.config.core.Configuration; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.NextPreviousType; diff --git a/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/action/IIpx800Actions.java b/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/action/IIpx800Actions.java deleted file mode 100644 index 03cd5d15e..000000000 --- a/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/action/IIpx800Actions.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.gce.internal.action; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * The {@link IIpx800Actions} defines the interface for all thing actions supported by the binding. - * - * @author Gaël L'hopital - Initial contribution - */ -@NonNullByDefault -public interface IIpx800Actions { - public void resetCounter(Integer counter); - - public void reset(@Nullable Integer placeholder); -} diff --git a/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/action/Ipx800Actions.java b/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/action/Ipx800Actions.java index acdb937a1..d27f8494d 100644 --- a/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/action/Ipx800Actions.java +++ b/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/action/Ipx800Actions.java @@ -12,9 +12,6 @@ */ package org.openhab.binding.gce.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.gce.internal.handler.Ipx800v3Handler; @@ -27,18 +24,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * The {Ipx800Actions } defines rule actions for the GCE binding. - *

- * 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 textInputListener = createTextInputStatusListener(); private @Nullable LGWebOSHandler handler; @@ -76,7 +69,7 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions { @Override public @Nullable ThingHandler getThingHandler() { - return this.handler; + return handler; } // a NonNull getter for handler @@ -101,7 +94,6 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions { OK } - @Override @RuleAction(label = "@text/actionShowToastLabel", description = "@text/actionShowToastDesc") public void showToast( @ActionInput(name = "text", label = "@text/actionShowToastInputTextLabel", description = "@text/actionShowToastInputTextDesc") String text) @@ -109,7 +101,6 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions { getConnectedSocket().ifPresent(control -> control.showToast(text, createResponseListener())); } - @Override @RuleAction(label = "@text/actionShowToastWithIconLabel", description = "@text/actionShowToastWithIconLabel") public void showToast( @ActionInput(name = "icon", label = "@text/actionShowToastInputIconLabel", description = "@text/actionShowToastInputIconDesc") String icon, @@ -123,7 +114,6 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions { } } - @Override @RuleAction(label = "@text/actionLaunchBrowserLabel", description = "@text/actionLaunchBrowserDesc") public void launchBrowser( @ActionInput(name = "url", label = "@text/actionLaunchBrowserInputUrlLabel", description = "@text/actionLaunchBrowserInputUrlDesc") String url) { @@ -146,7 +136,6 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions { return appInfos; } - @Override @RuleAction(label = "@text/actionLaunchApplicationLabel", description = "@text/actionLaunchApplicationDesc") public void launchApplication( @ActionInput(name = "appId", label = "@text/actionLaunchApplicationInputAppIDLabel", description = "@text/actionLaunchApplicationInputAppIDDesc") String appId) { @@ -160,7 +149,6 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions { } } - @Override @RuleAction(label = "@text/actionLaunchApplicationWithParamsLabel", description = "@text/actionLaunchApplicationWithParamsDesc") public void launchApplication( @ActionInput(name = "appId", label = "@text/actionLaunchApplicationInputAppIDLabel", description = "@text/actionLaunchApplicationInputAppIDDesc") String appId, @@ -184,7 +172,6 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions { } } - @Override @RuleAction(label = "@text/actionSendTextLabel", description = "@text/actionSendTextDesc") public void sendText( @ActionInput(name = "text", label = "@text/actionSendTextInputTextLabel", description = "@text/actionSendTextInputTextDesc") String text) { @@ -195,7 +182,6 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions { }); } - @Override @RuleAction(label = "@text/actionSendButtonLabel", description = "@text/actionSendButtonDesc") public void sendButton( @ActionInput(name = "text", label = "@text/actionSendButtonInputButtonLabel", description = "@text/actionSendButtonInputButtonDesc") String button) { @@ -235,19 +221,16 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions { } } - @Override @RuleAction(label = "@text/actionIncreaseChannelLabel", description = "@text/actionIncreaseChannelDesc") public void increaseChannel() { getConnectedSocket().ifPresent(control -> control.channelUp(createResponseListener())); } - @Override @RuleAction(label = "@text/actionDecreaseChannelLabel", description = "@text/actionDecreaseChannelDesc") public void decreaseChannel() { getConnectedSocket().ifPresent(control -> control.channelDown(createResponseListener())); } - @Override @RuleAction(label = "@text/actionSendRCButtonLabel", description = "@text/actionSendRCButtonDesc") public void sendRCButton( @ActionInput(name = "text", label = "@text/actionSendRCButtonInputTextLabel", description = "@text/actionSendRCButtonInputTextDesc") String rcButton) { @@ -298,62 +281,83 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions { // delegation methods for "legacy" rule support - private static ILGWebOSActions invokeMethodOf(@Nullable ThingActions actions) { - if (actions == null) { - throw new IllegalArgumentException("actions cannot be null"); - } - if (actions.getClass().getName().equals(LGWebOSActions.class.getName())) { - if (actions instanceof ILGWebOSActions) { - return (ILGWebOSActions) actions; - } else { - return (ILGWebOSActions) Proxy.newProxyInstance(ILGWebOSActions.class.getClassLoader(), - new Class[] { ILGWebOSActions.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 LGWebOSActions"); - } - public static void showToast(@Nullable ThingActions actions, String text) throws IOException { - invokeMethodOf(actions).showToast(text); + if (actions instanceof LGWebOSActions) { + ((LGWebOSActions) actions).showToast(text); + } else { + throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); + } } public static void showToast(@Nullable ThingActions actions, String icon, String text) throws IOException { - invokeMethodOf(actions).showToast(icon, text); + if (actions instanceof LGWebOSActions) { + ((LGWebOSActions) actions).showToast(icon, text); + } else { + throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); + } } public static void launchBrowser(@Nullable ThingActions actions, String url) { - invokeMethodOf(actions).launchBrowser(url); + if (actions instanceof LGWebOSActions) { + ((LGWebOSActions) actions).launchBrowser(url); + } else { + throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); + } } public static void launchApplication(@Nullable ThingActions actions, String appId) { - invokeMethodOf(actions).launchApplication(appId); + if (actions instanceof LGWebOSActions) { + ((LGWebOSActions) actions).launchApplication(appId); + } else { + throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); + } } public static void launchApplication(@Nullable ThingActions actions, String appId, String param) { - invokeMethodOf(actions).launchApplication(appId, param); + if (actions instanceof LGWebOSActions) { + ((LGWebOSActions) actions).launchApplication(appId, param); + } else { + throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); + } } public static void sendText(@Nullable ThingActions actions, String text) { - invokeMethodOf(actions).sendText(text); + if (actions instanceof LGWebOSActions) { + ((LGWebOSActions) actions).sendText(text); + } else { + throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); + } } public static void sendButton(@Nullable ThingActions actions, String button) { - invokeMethodOf(actions).sendButton(button); + if (actions instanceof LGWebOSActions) { + ((LGWebOSActions) actions).sendButton(button); + } else { + throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); + } } public static void increaseChannel(@Nullable ThingActions actions) { - invokeMethodOf(actions).increaseChannel(); + if (actions instanceof LGWebOSActions) { + ((LGWebOSActions) actions).increaseChannel(); + } else { + throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); + } } public static void decreaseChannel(@Nullable ThingActions actions) { - invokeMethodOf(actions).decreaseChannel(); + if (actions instanceof LGWebOSActions) { + ((LGWebOSActions) actions).decreaseChannel(); + } else { + throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); + } } public static void sendRCButton(@Nullable ThingActions actions, String rcButton) { - invokeMethodOf(actions).sendRCButton(rcButton); + if (actions instanceof LGWebOSActions) { + ((LGWebOSActions) actions).sendRCButton(rcButton); + } else { + throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); + } } } diff --git a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSHandler.java b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSHandler.java index 26a1d4bd4..cf40ac53d 100644 --- a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSHandler.java +++ b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSHandler.java @@ -27,7 +27,6 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.websocket.client.WebSocketClient; -import org.openhab.binding.lgwebos.action.LGWebOSActions; import org.openhab.binding.lgwebos.internal.ChannelHandler; import org.openhab.binding.lgwebos.internal.LGWebOSBindingConstants; import org.openhab.binding.lgwebos.internal.LGWebOSStateDescriptionOptionProvider; @@ -41,6 +40,7 @@ import org.openhab.binding.lgwebos.internal.ToastControlToast; import org.openhab.binding.lgwebos.internal.VolumeControlMute; import org.openhab.binding.lgwebos.internal.VolumeControlVolume; import org.openhab.binding.lgwebos.internal.WakeOnLanUtility; +import org.openhab.binding.lgwebos.internal.action.LGWebOSActions; import org.openhab.binding.lgwebos.internal.handler.LGWebOSTVSocket.WebOSTVSocketListener; import org.openhab.binding.lgwebos.internal.handler.core.AppInfo; import org.openhab.binding.lgwebos.internal.handler.core.ResponseListener; diff --git a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/action/IDimmerActions.java b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/action/IDimmerActions.java deleted file mode 100644 index 551e8a659..000000000 --- a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/action/IDimmerActions.java +++ /dev/null @@ -1,30 +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.lutron.action; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * The {@link IDimmerActions} interface defines the interface for all thing actions supported by the dimmer thing. - * 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 IDimmerActions { - - public void setLevel(@Nullable Double level, @Nullable Double fadeTime, @Nullable Double delayTime); -} diff --git a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/action/DimmerActions.java b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/action/DimmerActions.java similarity index 70% rename from bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/action/DimmerActions.java rename to bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/action/DimmerActions.java index b7d4f40e3..48fb70eaf 100644 --- a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/action/DimmerActions.java +++ b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/action/DimmerActions.java @@ -10,10 +10,8 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.lutron.action; +package org.openhab.binding.lutron.internal.action; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; import java.math.BigDecimal; import java.math.RoundingMode; @@ -36,7 +34,7 @@ import org.slf4j.LoggerFactory; */ @ThingActionsScope(name = "lutron") @NonNullByDefault -public class DimmerActions implements ThingActions, IDimmerActions { +public class DimmerActions implements ThingActions { private final Logger logger = LoggerFactory.getLogger(DimmerActions.class); private @Nullable DimmerHandler handler; @@ -60,8 +58,7 @@ public class DimmerActions implements ThingActions, IDimmerActions { /** * The setLevel dimmer thing action */ - @Override - @RuleAction(label = "setLevel", description = "Send set level command with fade and delay times") + @RuleAction(label = "send a set level command", description = "Send set level command with fade and delay times.") public void setLevel( @ActionInput(name = "level", label = "Dimmer Level", description = "New dimmer level (0-100)") @Nullable Double level, @ActionInput(name = "fadeTime", label = "Fade Time", description = "Time to fade to new level (seconds)") @Nullable Double fadeTime, @@ -103,29 +100,10 @@ public class DimmerActions implements ThingActions, IDimmerActions { */ public static void setLevel(@Nullable ThingActions actions, @Nullable Double level, @Nullable Double fadeTime, @Nullable Double delayTime) { - invokeMethodOf(actions).setLevel(level, fadeTime, delayTime); // Replace 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 IDimmerActions invokeMethodOf(@Nullable ThingActions actions) { - if (actions == null) { - throw new IllegalArgumentException("actions cannot be null"); + if (actions instanceof DimmerActions) { + ((DimmerActions) actions).setLevel(level, fadeTime, delayTime); + } else { + throw new IllegalArgumentException("Actions is not an instance of DimmerActions"); } - if (actions.getClass().getName().equals(DimmerActions.class.getName())) { - if (actions instanceof IDimmerActions) { - return (IDimmerActions) actions; - } else { - return (IDimmerActions) Proxy.newProxyInstance(IDimmerActions.class.getClassLoader(), - new Class[] { IDimmerActions.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 DimmerActions"); } } diff --git a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/handler/DimmerHandler.java b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/handler/DimmerHandler.java index 35c01d2b1..84f002cbc 100644 --- a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/handler/DimmerHandler.java +++ b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/handler/DimmerHandler.java @@ -19,7 +19,7 @@ import java.util.Collection; import java.util.Collections; import java.util.concurrent.atomic.AtomicReference; -import org.openhab.binding.lutron.action.DimmerActions; +import org.openhab.binding.lutron.internal.action.DimmerActions; import org.openhab.binding.lutron.internal.config.DimmerConfig; import org.openhab.binding.lutron.internal.protocol.LutronCommandType; import org.openhab.binding.lutron.internal.protocol.LutronDuration; diff --git a/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/action/ISendMailActions.java b/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/action/ISendMailActions.java deleted file mode 100644 index 1a0b3a3df..000000000 --- a/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/action/ISendMailActions.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.mail.action; - -import java.util.List; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * The {@link ISendMailActions} interface defines rule actions for sending mail - * - * @author Jan N. Klug - Initial contribution - */ -@NonNullByDefault -public interface ISendMailActions { - Boolean sendMail(@Nullable String recipient, @Nullable String subject, @Nullable String text, - @Nullable List urlStringList); - - Boolean sendHtmlMail(@Nullable String recipient, @Nullable String subject, @Nullable String html, - @Nullable List urlStringList); -} diff --git a/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/SMTPHandler.java b/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/SMTPHandler.java index 69b36f6af..476cdceab 100644 --- a/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/SMTPHandler.java +++ b/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/SMTPHandler.java @@ -19,7 +19,7 @@ import org.apache.commons.mail.DefaultAuthenticator; import org.apache.commons.mail.Email; import org.apache.commons.mail.EmailException; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.binding.mail.action.SendMailActions; +import org.openhab.binding.mail.internal.action.SendMailActions; import org.openhab.binding.mail.internal.config.SMTPConfig; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; diff --git a/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/action/SendMailActions.java b/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/action/SendMailActions.java similarity index 80% rename from bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/action/SendMailActions.java rename to bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/action/SendMailActions.java index 1513025f7..2c86e18ce 100644 --- a/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/action/SendMailActions.java +++ b/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/action/SendMailActions.java @@ -10,10 +10,8 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.mail.action; +package org.openhab.binding.mail.internal.action; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.List; @@ -41,13 +39,13 @@ import org.slf4j.LoggerFactory; */ @ThingActionsScope(name = "mail") @NonNullByDefault -public class SendMailActions implements ThingActions, ISendMailActions { +public class SendMailActions implements ThingActions { private final Logger logger = LoggerFactory.getLogger(SendMailActions.class); private @Nullable SMTPHandler handler; - @RuleAction(label = "Send Text Mail", description = "sends a text mail") + @RuleAction(label = "send a text mail", description = "Sends a text mail.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendMail( @ActionInput(name = "recipient") @Nullable String recipient, @ActionInput(name = "subject") @Nullable String subject, @@ -55,7 +53,7 @@ public class SendMailActions implements ThingActions, ISendMailActions { return sendMail(recipient, subject, text, new ArrayList<>()); } - @RuleAction(label = "Send Text Mail", description = "sends a text mail with URL attachment") + @RuleAction(label = "send a text mail", description = "Sends a text mail with URL attachment.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendMail( @ActionInput(name = "recipient") @Nullable String recipient, @ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "text") @Nullable String text, @@ -67,8 +65,7 @@ public class SendMailActions implements ThingActions, ISendMailActions { return sendMail(recipient, subject, text, urlList); } - @Override - @RuleAction(label = "Send Text Mail", description = "sends a text mail with several URL attachments") + @RuleAction(label = "send a text mail", description = "Sends a text mail with several URL attachments.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendMail( @ActionInput(name = "recipient") @Nullable String recipient, @ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "text") @Nullable String text, @@ -122,10 +119,14 @@ public class SendMailActions implements ThingActions, ISendMailActions { public static boolean sendMail(@Nullable ThingActions actions, @Nullable String recipient, @Nullable String subject, @Nullable String text, @Nullable List urlStringList) { - return invokeMethodOf(actions).sendMail(recipient, subject, text, urlStringList); + if (actions instanceof SendMailActions) { + return ((SendMailActions) actions).sendMail(recipient, subject, text, urlStringList); + } else { + throw new IllegalArgumentException("Actions is not an instance of SendMailActions"); + } } - @RuleAction(label = "Send HTML Mail", description = "sends a HTML mail") + @RuleAction(label = "send a HTML mail", description = "Sends a HTML mail.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendHtmlMail( @ActionInput(name = "recipient") @Nullable String recipient, @ActionInput(name = "subject") @Nullable String subject, @@ -133,7 +134,7 @@ public class SendMailActions implements ThingActions, ISendMailActions { return sendHtmlMail(recipient, subject, html, new ArrayList<>()); } - @RuleAction(label = "Send HTML Mail", description = "sends a HTML mail with URL attachment") + @RuleAction(label = "send a HTML mail", description = "Sends a HTML mail with URL attachment.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendHtmlMail( @ActionInput(name = "recipient") @Nullable String recipient, @ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "html") @Nullable String html, @@ -145,8 +146,7 @@ public class SendMailActions implements ThingActions, ISendMailActions { return sendHtmlMail(recipient, subject, html, urlList); } - @Override - @RuleAction(label = "Send HTML Mail", description = "sends a HTML mail with several URL attachments") + @RuleAction(label = "send a HTML mail", description = "Sends a HTML mail with several URL attachments.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendHtmlMail( @ActionInput(name = "recipient") @Nullable String recipient, @ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "html") @Nullable String html, @@ -200,7 +200,11 @@ public class SendMailActions implements ThingActions, ISendMailActions { public static boolean sendHtmlMail(@Nullable ThingActions actions, @Nullable String recipient, @Nullable String subject, @Nullable String html, @Nullable List urlStringList) { - return invokeMethodOf(actions).sendHtmlMail(recipient, subject, html, urlStringList); + if (actions instanceof SendMailActions) { + return ((SendMailActions) actions).sendHtmlMail(recipient, subject, html, urlStringList); + } else { + throw new IllegalArgumentException("Actions is not an instance of SendMailActions"); + } } @Override @@ -212,25 +216,6 @@ public class SendMailActions implements ThingActions, ISendMailActions { @Override public @Nullable ThingHandler getThingHandler() { - return this.handler; - } - - private static ISendMailActions invokeMethodOf(@Nullable ThingActions actions) { - if (actions == null) { - throw new IllegalArgumentException("actions cannot be null"); - } - if (actions.getClass().getName().equals(SendMailActions.class.getName())) { - if (actions instanceof ISendMailActions) { - return (ISendMailActions) actions; - } else { - return (ISendMailActions) Proxy.newProxyInstance(ISendMailActions.class.getClassLoader(), - new Class[] { ISendMailActions.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 SendMailActions"); + return handler; } } diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/IMaxCubeActions.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/IMaxCubeActions.java deleted file mode 100644 index 69d57b529..000000000 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/IMaxCubeActions.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.max.internal.actions; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.binding.max.actions.MaxCubeActions; - -/** - * The {@link IMaxCubeActions} defines the interface for all thing actions supported by the binding. - * These methods, parameters, and return types are explained in {@link MaxCubeActions}. - * - * @author Christoph Weitkamp - Initial contribution - */ -@NonNullByDefault -public interface IMaxCubeActions { - - Boolean backup(); - - Boolean resetConfig(); - - Boolean reboot(); -} diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/IMaxDevicesActions.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/IMaxDevicesActions.java deleted file mode 100644 index 0fcb61e20..000000000 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/IMaxDevicesActions.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.max.internal.actions; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.binding.max.actions.MaxDevicesActions; - -/** - * The {@link IMaxDevicesActions} defines the interface for all thing actions supported by the binding. - * These methods, parameters, and return types are explained in {@link MaxDevicesActions}. - * - * @author Christoph Weitkamp - Initial contribution - */ -@NonNullByDefault -public interface IMaxDevicesActions { - - Boolean deleteFromCube(); -} diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/actions/MaxCubeActions.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/MaxCubeActions.java similarity index 61% rename from bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/actions/MaxCubeActions.java rename to bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/MaxCubeActions.java index 1f709b4c1..0814fe1e7 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/actions/MaxCubeActions.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/MaxCubeActions.java @@ -10,14 +10,10 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.max.actions; - -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; +package org.openhab.binding.max.internal.actions; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.max.internal.actions.IMaxCubeActions; import org.openhab.binding.max.internal.handler.MaxCubeBridgeHandler; import org.openhab.core.automation.annotation.ActionOutput; import org.openhab.core.automation.annotation.RuleAction; @@ -34,7 +30,7 @@ import org.slf4j.LoggerFactory; */ @ThingActionsScope(name = "max-cube") @NonNullByDefault -public class MaxCubeActions implements ThingActions, IMaxCubeActions { +public class MaxCubeActions implements ThingActions { private final Logger logger = LoggerFactory.getLogger(MaxCubeActions.class); @@ -49,11 +45,10 @@ public class MaxCubeActions implements ThingActions, IMaxCubeActions { @Override public @Nullable ThingHandler getThingHandler() { - return this.handler; + return handler; } - @Override - @RuleAction(label = "Backup Cube Data", description = "Creates a backup of the MAX! Cube data.") + @RuleAction(label = "backup the Cube data", description = "Creates a backup of the MAX! Cube data.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean backup() { MaxCubeBridgeHandler actionsHandler = handler; if (actionsHandler == null) { @@ -65,11 +60,14 @@ public class MaxCubeActions implements ThingActions, IMaxCubeActions { } public static boolean backup(@Nullable ThingActions actions) { - return invokeMethodOf(actions).backup(); + if (actions instanceof MaxCubeActions) { + return ((MaxCubeActions) actions).backup(); + } else { + throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions"); + } } - @Override - @RuleAction(label = "Reset Cube Configuration", description = "Resets the MAX! Cube room and device information. Devices will need to be included again!") + @RuleAction(label = "reset the Cube configuration", description = "Resets the MAX! Cube room and device information. Devices will need to be included again!") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean resetConfig() { MaxCubeBridgeHandler actionsHandler = handler; if (actionsHandler == null) { @@ -81,11 +79,14 @@ public class MaxCubeActions implements ThingActions, IMaxCubeActions { } public static boolean reset(@Nullable ThingActions actions) { - return invokeMethodOf(actions).resetConfig(); + if (actions instanceof MaxCubeActions) { + return ((MaxCubeActions) actions).resetConfig(); + } else { + throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions"); + } } - @Override - @RuleAction(label = "Restart Cube", description = "Restarts the MAX! Cube.") + @RuleAction(label = "restart the Cube", description = "Restarts the MAX! Cube.") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean reboot() { MaxCubeBridgeHandler actionsHandler = handler; if (actionsHandler == null) { @@ -97,25 +98,10 @@ public class MaxCubeActions implements ThingActions, IMaxCubeActions { } public static boolean reboot(@Nullable ThingActions actions) { - return invokeMethodOf(actions).reboot(); - } - - private static IMaxCubeActions invokeMethodOf(@Nullable ThingActions actions) { - if (actions == null) { - throw new IllegalArgumentException("actions cannot be null"); + if (actions instanceof MaxCubeActions) { + return ((MaxCubeActions) actions).reboot(); + } else { + throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions"); } - if (actions.getClass().getName().equals(MaxCubeActions.class.getName())) { - if (actions instanceof IMaxCubeActions) { - return (IMaxCubeActions) actions; - } else { - return (IMaxCubeActions) Proxy.newProxyInstance(IMaxCubeActions.class.getClassLoader(), - new Class[] { IMaxCubeActions.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 MaxCubeActions"); } } diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/actions/MaxDevicesActions.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/MaxDevicesActions.java similarity index 56% rename from bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/actions/MaxDevicesActions.java rename to bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/MaxDevicesActions.java index d9291fa75..f14fdbda9 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/actions/MaxDevicesActions.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/MaxDevicesActions.java @@ -10,14 +10,10 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.max.actions; - -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; +package org.openhab.binding.max.internal.actions; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.max.internal.actions.IMaxDevicesActions; import org.openhab.binding.max.internal.handler.MaxDevicesHandler; import org.openhab.core.automation.annotation.ActionOutput; import org.openhab.core.automation.annotation.RuleAction; @@ -34,7 +30,7 @@ import org.slf4j.LoggerFactory; */ @ThingActionsScope(name = "max-devices") @NonNullByDefault -public class MaxDevicesActions implements ThingActions, IMaxDevicesActions { +public class MaxDevicesActions implements ThingActions { private final Logger logger = LoggerFactory.getLogger(MaxDevicesActions.class); @@ -49,11 +45,10 @@ public class MaxDevicesActions implements ThingActions, IMaxDevicesActions { @Override public @Nullable ThingHandler getThingHandler() { - return this.handler; + return handler; } - @Override - @RuleAction(label = "Delete Device from Cube", description = "Deletes the device from the MAX! Cube. Device will need to be included again!") + @RuleAction(label = "delete the device from the Cube", description = "Deletes the device from the MAX! Cube. Device will need to be included again!") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean deleteFromCube() { MaxDevicesHandler actionsHandler = handler; if (actionsHandler == null) { @@ -65,25 +60,10 @@ public class MaxDevicesActions implements ThingActions, IMaxDevicesActions { } public static boolean deleteFromCube(@Nullable ThingActions actions) { - return invokeMethodOf(actions).deleteFromCube(); - } - - private static IMaxDevicesActions invokeMethodOf(@Nullable ThingActions actions) { - if (actions == null) { - throw new IllegalArgumentException("actions cannot be null"); + if (actions instanceof MaxDevicesActions) { + return ((MaxDevicesActions) actions).deleteFromCube(); + } else { + throw new IllegalArgumentException("Actions is not an instance of MaxDevicesActions"); } - if (actions.getClass().getName().equals(MaxDevicesActions.class.getName())) { - if (actions instanceof IMaxDevicesActions) { - return (IMaxDevicesActions) actions; - } else { - return (IMaxDevicesActions) Proxy.newProxyInstance(IMaxDevicesActions.class.getClassLoader(), - new Class[] { IMaxDevicesActions.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 MaxDevicesActions"); } } diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/MaxCubeBridgeHandler.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/MaxCubeBridgeHandler.java index e2deb6025..ca7aa63c9 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/MaxCubeBridgeHandler.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/MaxCubeBridgeHandler.java @@ -49,9 +49,9 @@ import java.util.stream.Stream; import javax.measure.quantity.Temperature; -import org.openhab.binding.max.actions.MaxCubeActions; import org.openhab.binding.max.internal.MaxBackupUtils; import org.openhab.binding.max.internal.MaxBindingConstants; +import org.openhab.binding.max.internal.actions.MaxCubeActions; import org.openhab.binding.max.internal.command.ACommand; import org.openhab.binding.max.internal.command.CCommand; import org.openhab.binding.max.internal.command.CubeCommand; diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/MaxDevicesHandler.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/MaxDevicesHandler.java index 860a641a2..753427ad8 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/MaxDevicesHandler.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/MaxDevicesHandler.java @@ -27,7 +27,7 @@ import java.util.Map.Entry; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import org.openhab.binding.max.actions.MaxDevicesActions; +import org.openhab.binding.max.internal.actions.MaxDevicesActions; import org.openhab.binding.max.internal.command.CCommand; import org.openhab.binding.max.internal.command.QCommand; import org.openhab.binding.max.internal.command.SConfigCommand; diff --git a/bundles/org.openhab.binding.mpd/src/main/java/org/openhab/binding/mpd/internal/action/IMPDActions.java b/bundles/org.openhab.binding.mpd/src/main/java/org/openhab/binding/mpd/internal/action/IMPDActions.java deleted file mode 100644 index 6accb2c11..000000000 --- a/bundles/org.openhab.binding.mpd/src/main/java/org/openhab/binding/mpd/internal/action/IMPDActions.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.mpd.internal.action; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * The {@link IMPDActions} interface defines rule actions for sending commands to a Music Player Daemon - * - * @author Stefan Röllin - Initial contribution - */ -@NonNullByDefault -public interface IMPDActions { - - public void sendCommand(@Nullable String command, @Nullable String parameter); - - public void sendCommand(@Nullable String command); -} diff --git a/bundles/org.openhab.binding.mpd/src/main/java/org/openhab/binding/mpd/internal/action/MPDActions.java b/bundles/org.openhab.binding.mpd/src/main/java/org/openhab/binding/mpd/internal/action/MPDActions.java index 854508537..060ea6d37 100644 --- a/bundles/org.openhab.binding.mpd/src/main/java/org/openhab/binding/mpd/internal/action/MPDActions.java +++ b/bundles/org.openhab.binding.mpd/src/main/java/org/openhab/binding/mpd/internal/action/MPDActions.java @@ -12,9 +12,6 @@ */ package org.openhab.binding.mpd.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.mpd.internal.handler.MPDHandler; @@ -33,7 +30,7 @@ import org.slf4j.LoggerFactory; */ @ThingActionsScope(name = "mpd") @NonNullByDefault -public class MPDActions implements ThingActions, IMPDActions { +public class MPDActions implements ThingActions { private final Logger logger = LoggerFactory.getLogger(MPDActions.class); @@ -51,8 +48,7 @@ public class MPDActions implements ThingActions, IMPDActions { return handler; } - @Override - @RuleAction(label = "MPD : Send command", description = "Send a command to the Music Player Daemon.") + @RuleAction(label = "send a command with a parameter", description = "Send a command to the Music Player Daemon.") public void sendCommand(@ActionInput(name = "command") @Nullable String command, @ActionInput(name = "parameter") @Nullable String parameter) { logger.debug("sendCommand called with {}", command); @@ -65,8 +61,7 @@ public class MPDActions implements ThingActions, IMPDActions { } } - @Override - @RuleAction(label = "MPD : Send command", description = "Send a command to the Music Player Daemon.") + @RuleAction(label = "send a command", description = "Send a command to the Music Player Daemon.") public void sendCommand(@ActionInput(name = "command") @Nullable String command) { logger.debug("sendCommand called with {}", command); @@ -78,31 +73,20 @@ public class MPDActions implements ThingActions, IMPDActions { } } - private static IMPDActions invokeMethodOf(@Nullable ThingActions actions) { - if (actions == null) { - throw new IllegalArgumentException("actions cannot be null"); - } - if (actions.getClass().getName().equals(MPDActions.class.getName())) { - if (actions instanceof IMPDActions) { - return (IMPDActions) actions; - } else { - return (IMPDActions) Proxy.newProxyInstance(IMPDActions.class.getClassLoader(), - new Class[] { IMPDActions.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 MPDActions"); - } - public static void sendCommand(@Nullable ThingActions actions, @Nullable String command, @Nullable String parameter) { - invokeMethodOf(actions).sendCommand(command, parameter); + if (actions instanceof MPDActions) { + ((MPDActions) actions).sendCommand(command, parameter); + } else { + throw new IllegalArgumentException("Actions is not an instance of MPDActions"); + } } public static void sendCommand(@Nullable ThingActions actions, @Nullable String command) { - invokeMethodOf(actions).sendCommand(command); + if (actions instanceof MPDActions) { + ((MPDActions) actions).sendCommand(command); + } else { + throw new IllegalArgumentException("Actions is not an instance of MPDActions"); + } } } diff --git a/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/action/IMQTTActions.java b/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/action/IMQTTActions.java deleted file mode 100644 index 9cc1463a5..000000000 --- a/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/action/IMQTTActions.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.mqtt.action; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * The {@link IMQTTActions} defines the interface for all thing actions supported by the binding. - * - * @author Laurent Garnier - Initial contribution - */ -@NonNullByDefault -public interface IMQTTActions { - - public void publishMQTT(@Nullable String topic, @Nullable String value, @Nullable Boolean retain); -} diff --git a/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/handler/AbstractBrokerHandler.java b/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/handler/AbstractBrokerHandler.java index 9b58a7cab..6468e3437 100644 --- a/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/handler/AbstractBrokerHandler.java +++ b/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/handler/AbstractBrokerHandler.java @@ -21,9 +21,9 @@ import java.util.concurrent.TimeoutException; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.mqtt.action.MQTTActions; import org.openhab.binding.mqtt.discovery.MQTTTopicDiscoveryParticipant; import org.openhab.binding.mqtt.discovery.TopicSubscribe; +import org.openhab.binding.mqtt.internal.action.MQTTActions; import org.openhab.core.io.transport.mqtt.MqttBrokerConnection; import org.openhab.core.io.transport.mqtt.MqttConnectionObserver; import org.openhab.core.io.transport.mqtt.MqttConnectionState; diff --git a/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/action/MQTTActions.java b/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/internal/action/MQTTActions.java similarity index 71% rename from bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/action/MQTTActions.java rename to bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/internal/action/MQTTActions.java index 339236a72..75b748c66 100644 --- a/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/action/MQTTActions.java +++ b/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/internal/action/MQTTActions.java @@ -10,10 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.mqtt.action; - -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; +package org.openhab.binding.mqtt.internal.action; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -29,17 +26,12 @@ import org.slf4j.LoggerFactory; /** * This is the automation engine action handler service for the publishMQTT action. - *

- * 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> getServices() { - return Collections.singletonList(OnkyoThingActionsService.class); + return Collections.singletonList(OnkyoThingActions.class); } } diff --git a/bundles/org.openhab.binding.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/action/IPushbulletActions.java b/bundles/org.openhab.binding.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/action/IPushbulletActions.java deleted file mode 100644 index 46cbbc462..000000000 --- a/bundles/org.openhab.binding.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/action/IPushbulletActions.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.pushbullet.internal.action; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * The {@link IPushbulletActions} interface defines rule actions for sending notifications - * - * @author Laurent Garnier - Initial contribution - */ -@NonNullByDefault -public interface IPushbulletActions { - - public Boolean sendPushbulletNote(@Nullable String recipient, @Nullable String title, @Nullable String message); - - public Boolean sendPushbulletNote(@Nullable String recipient, @Nullable String message); -} diff --git a/bundles/org.openhab.binding.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/action/PushbulletActions.java b/bundles/org.openhab.binding.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/action/PushbulletActions.java index f1ae9e55f..103828e37 100644 --- a/bundles/org.openhab.binding.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/action/PushbulletActions.java +++ b/bundles/org.openhab.binding.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/action/PushbulletActions.java @@ -12,9 +12,6 @@ */ package org.openhab.binding.pushbullet.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.pushbullet.internal.handler.PushbulletHandler; @@ -29,17 +26,12 @@ import org.slf4j.LoggerFactory; /** * The {@link PushbulletActions} class defines rule actions for sending notifications - *

- * 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 readEvent(@Nullable Number index); -} diff --git a/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/action/SatelEventLogActions.java b/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/action/SatelEventLogActions.java similarity index 74% rename from bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/action/SatelEventLogActions.java rename to bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/action/SatelEventLogActions.java index 95d2a4732..a2f49e1a0 100644 --- a/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/action/SatelEventLogActions.java +++ b/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/action/SatelEventLogActions.java @@ -10,10 +10,8 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.satel.action; +package org.openhab.binding.satel.internal.action; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; import java.util.HashMap; import java.util.Map; @@ -37,7 +35,7 @@ import org.slf4j.LoggerFactory; */ @ThingActionsScope(name = "satel") @NonNullByDefault -public class SatelEventLogActions implements ThingActions, ISatelEventLogActions { +public class SatelEventLogActions implements ThingActions { private final Logger logger = LoggerFactory.getLogger(getClass()); @@ -55,7 +53,6 @@ public class SatelEventLogActions implements ThingActions, ISatelEventLogActions return handler; } - @Override @RuleAction(label = "@text/actionReadEventLabel", description = "@text/actionReadEventDesc") public @ActionOutput(name = "index", type = "java.lang.Integer", label = "@text/actionOutputIndexLabel", description = "@text/actionOutputIndexDesc") @ActionOutput(name = "prev_index", type = "java.lang.Integer", label = "@text/actionOutputPrevIndexLabel", description = "@text/actionOutputPrevIndexDesc") @ActionOutput(name = "timestamp", type = "java.time.ZonedDateTime", label = "@text/actionOutputTimestampLabel", description = "@text/actionOutputTimestampDesc") @ActionOutput(name = "description", type = "java.lang.String", label = "@text/actionOutputDescriptionLabel", description = "@text/actionOutputDescriptionDesc") @ActionOutput(name = "details", type = "java.lang.String", label = "@text/actionOutputDetailsLabel", description = "@text/actionOutputDetailsDesc") Map readEvent( @ActionInput(name = "index", label = "@text/actionInputIndexLabel", description = "@text/actionInputIndexDesc") @Nullable Number index) { @@ -75,21 +72,10 @@ public class SatelEventLogActions implements ThingActions, ISatelEventLogActions } public static Map readEvent(@Nullable ThingActions actions, @Nullable Number index) { - return invokeMethodOf(actions).readEvent(index); - } - - private static ISatelEventLogActions invokeMethodOf(@Nullable ThingActions actions) { - if (actions == null) { - throw new IllegalArgumentException("actions cannot be null"); - } else if (actions instanceof ISatelEventLogActions) { - return (ISatelEventLogActions) actions; - } else if (actions.getClass().getName().equals(SatelEventLogActions.class.getName())) { - return (ISatelEventLogActions) Proxy.newProxyInstance(ISatelEventLogActions.class.getClassLoader(), - new Class[] { ISatelEventLogActions.class }, (Object proxy, Method method, Object[] args) -> { - Method m = actions.getClass().getDeclaredMethod(method.getName(), method.getParameterTypes()); - return m.invoke(actions, args); - }); + if (actions instanceof SatelEventLogActions) { + return ((SatelEventLogActions) actions).readEvent(index); + } else { + throw new IllegalArgumentException("Actions is not an instance of SatelEventLogActions"); } - throw new IllegalArgumentException("actions is not an instance of ISatelEventLogActions"); } } diff --git a/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/handler/SatelEventLogHandler.java b/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/handler/SatelEventLogHandler.java index cca874f65..339bcedcf 100644 --- a/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/handler/SatelEventLogHandler.java +++ b/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/handler/SatelEventLogHandler.java @@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.satel.action.SatelEventLogActions; +import org.openhab.binding.satel.internal.action.SatelEventLogActions; import org.openhab.binding.satel.internal.command.ReadDeviceInfoCommand; import org.openhab.binding.satel.internal.command.ReadDeviceInfoCommand.DeviceType; import org.openhab.binding.satel.internal.command.ReadEventCommand; diff --git a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/bot/ITelegramActions.java b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/bot/ITelegramActions.java deleted file mode 100644 index 9b6787aa4..000000000 --- a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/bot/ITelegramActions.java +++ /dev/null @@ -1,48 +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.telegram.bot; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * Provides the actions for the Telegram API. - * - * @author Laurent Garnier - Initial contribution - */ -@NonNullByDefault -public interface ITelegramActions { - - public boolean sendTelegramAnswer(@Nullable Long chatId, @Nullable String replyId, @Nullable String message); - - public boolean sendTelegramAnswer(@Nullable String replyId, @Nullable String message); - - public boolean sendTelegram(@Nullable Long chatId, @Nullable String message); - - public boolean sendTelegram(@Nullable String message); - - public boolean sendTelegramQuery(@Nullable Long chatId, @Nullable String message, @Nullable String replyId, - @Nullable String... buttons); - - public boolean sendTelegramQuery(@Nullable String message, @Nullable String replyId, @Nullable String... buttons); - - public boolean sendTelegram(@Nullable Long chatId, @Nullable String message, @Nullable Object... args); - - public boolean sendTelegram(@Nullable String message, @Nullable Object... args); - - public boolean sendTelegramPhoto(@Nullable Long chatId, @Nullable String photoURL, @Nullable String caption, - @Nullable String username, @Nullable String password); - - public boolean sendTelegramPhoto(@Nullable String photoURL, @Nullable String caption, @Nullable String username, - @Nullable String password); -} diff --git a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java index c4c8c94d8..e28432b72 100644 --- a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java +++ b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java @@ -34,7 +34,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpClient; -import org.openhab.binding.telegram.bot.TelegramActions; +import org.openhab.binding.telegram.internal.action.TelegramActions; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.StringType; import org.openhab.core.thing.ChannelUID; diff --git a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/bot/TelegramActions.java b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/action/TelegramActions.java similarity index 81% rename from bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/bot/TelegramActions.java rename to bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/action/TelegramActions.java index 9171dc53d..42ca057f1 100644 --- a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/bot/TelegramActions.java +++ b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/action/TelegramActions.java @@ -10,13 +10,11 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.telegram.bot; +package org.openhab.binding.telegram.internal.action; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; @@ -58,18 +56,12 @@ import com.pengrad.telegrambot.response.SendResponse; /** * Provides the actions for the Telegram API. - *

- * 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;