From 978e122e00144272151c3083b3699629624b9ad0 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Thu, 15 Oct 2020 10:53:53 +0200 Subject: [PATCH] Rework ThingActions (#8755) * Remove duplication by making use of default Java generated exceptions * Make ThingActions labels/descriptions more consistent Signed-off-by: Wouter Born --- .../internal/actions/BridgeActions.java | 8 +- .../astro/internal/action/AstroActions.java | 30 +--- .../internal/actions/AutomowerActions.java | 48 ++---- .../OH-INF/i18n/automower.properties | 24 +-- .../actions/AVMFritzHeatingActions.java | 16 +- .../resources/OH-INF/i18n/avmfritz.properties | 4 +- .../actions/AVMFritzHeatingActionsTest.java | 19 +-- .../dmx/internal/action/DmxActions.java | 8 +- .../internal/action/DoorbirdActions.java | 48 ++---- .../ecobee/internal/action/EcobeeActions.java | 161 +++++------------- .../internal/actions/Enigma2Actions.java | 72 ++------ .../resources/OH-INF/i18n/enigma2.properties | 24 +-- .../internal/actions/Enigma2ActionsTest.java | 34 +--- .../gce/internal/action/Ipx800Actions.java | 16 +- .../heos/internal/action/HeosActions.java | 12 +- .../hue/internal/action/LightActions.java | 10 +- .../ipcamera/internal/IpCameraActions.java | 20 +-- .../internal/KaleidescapeThingActions.java | 8 +- .../lcn/internal/LcnModuleActions.java | 33 +--- .../internal/action/LGWebOSActions.java | 80 +++------ .../resources/OH-INF/i18n/lgwebos.properties | 20 +-- .../lutron/internal/action/DimmerActions.java | 8 +- .../mail/internal/action/SendMailActions.java | 30 ++-- .../max/internal/actions/MaxCubeActions.java | 24 +-- .../internal/actions/MaxDevicesActions.java | 8 +- .../internal/HeliosEasyControlsActions.java | 86 ++++------ .../mpd/internal/action/MPDActions.java | 17 +- .../mqtt/internal/action/MQTTActions.java | 10 +- .../internal/action/NetworkActions.java | 8 +- .../nuvo/internal/NuvoThingActions.java | 8 +- .../automation/modules/OnkyoThingActions.java | 9 +- .../internal/action/PushbulletActions.java | 18 +- .../OH-INF/i18n/pushbullet_en.properties | 2 +- .../internal/RadioThermostatThingActions.java | 8 +- .../internal/action/SatelEventLogActions.java | 8 +- .../resources/OH-INF/i18n/satel.properties | 2 +- .../internal/action/TelegramActions.java | 105 ++++-------- .../internal/action/XMPPActions.java | 10 +- .../internal/YIOremoteDockActions.java | 8 +- .../zoneminder/internal/action/ZmActions.java | 26 +-- 40 files changed, 305 insertions(+), 785 deletions(-) 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 658f97817..06e4053f8 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 @@ -67,11 +67,7 @@ public class BridgeActions implements ThingActions { } // 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("Actions is not an instance of BridgeActions"); - } + public static void reboot(ThingActions actions) { + ((BridgeActions) actions).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 f8415c5e6..3216c50a3 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 @@ -112,34 +112,20 @@ public class AstroActions implements ThingActions { return null; } - public static @Nullable QuantityType getElevation(@Nullable ThingActions actions, - @Nullable ZonedDateTime 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 getElevation(ThingActions actions, @Nullable ZonedDateTime date) { + return ((AstroActions) actions).getElevation(date); } - public static @Nullable QuantityType getAzimuth(@Nullable ThingActions actions, - @Nullable ZonedDateTime date) { - if (actions instanceof AstroActions) { - return ((AstroActions) actions).getAzimuth(date); - } else { - throw new IllegalArgumentException("Actions is not an instance of AstroActions"); - } + public static @Nullable QuantityType getAzimuth(ThingActions actions, @Nullable ZonedDateTime date) { + return ((AstroActions) actions).getAzimuth(date); } - public static @Nullable ZonedDateTime getEventTime(@Nullable ThingActions actions, @Nullable String phaseName, + public static @Nullable ZonedDateTime getEventTime(ThingActions actions, @Nullable String phaseName, @Nullable ZonedDateTime date, @Nullable String moment) { - if (actions instanceof AstroActions) { - if (phaseName != null) { - return ((AstroActions) actions).getEventTime(phaseName, date, moment); - } else { - throw new IllegalArgumentException("phaseName can not be null"); - } + if (phaseName != null) { + return ((AstroActions) actions).getEventTime(phaseName, date, moment); } else { - throw new IllegalArgumentException("Actions is not an instance of AstroActions"); + throw new IllegalArgumentException("phaseName can not be null"); } } } 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 1086a0bfc..31d2f4c6d 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 @@ -54,12 +54,8 @@ public class AutomowerActions implements ThingActions { } } - public static void start(@Nullable ThingActions actions, int durationMin) { - if (actions instanceof AutomowerActions) { - ((AutomowerActions) actions).start(durationMin); - } else { - throw new IllegalArgumentException("Actions is not an instance of AutomowerActions"); - } + public static void start(ThingActions actions, int durationMin) { + ((AutomowerActions) actions).start(durationMin); } @RuleAction(label = "@text/action-pause-label", description = "@text/action-pause-desc") @@ -72,12 +68,8 @@ public class AutomowerActions implements ThingActions { } } - public static void pause(@Nullable ThingActions actions) { - if (actions instanceof AutomowerActions) { - ((AutomowerActions) actions).pause(); - } else { - throw new IllegalArgumentException("Actions is not an instance of AutomowerActions"); - } + public static void pause(ThingActions actions) { + ((AutomowerActions) actions).pause(); } @RuleAction(label = "@text/action-parkuntilnextschedule-label", description = "@text/action-parkuntilnextschedule-desc") @@ -90,12 +82,8 @@ public class AutomowerActions implements ThingActions { } } - public static void parkUntilNextSchedule(@Nullable ThingActions actions) { - if (actions instanceof AutomowerActions) { - ((AutomowerActions) actions).parkUntilNextSchedule(); - } else { - throw new IllegalArgumentException("Actions is not an instance of AutomowerActions"); - } + public static void parkUntilNextSchedule(ThingActions actions) { + ((AutomowerActions) actions).parkUntilNextSchedule(); } @RuleAction(label = "@text/action-parkuntilfurthernotice-label", description = "@text/action-parkuntilfurthernotice-desc") @@ -108,12 +96,8 @@ public class AutomowerActions implements ThingActions { } } - public static void parkUntilFurtherNotice(@Nullable ThingActions actions) { - if (actions instanceof AutomowerActions) { - ((AutomowerActions) actions).parkUntilFurtherNotice(); - } else { - throw new IllegalArgumentException("Actions is not an instance of AutomowerActions"); - } + public static void parkUntilFurtherNotice(ThingActions actions) { + ((AutomowerActions) actions).parkUntilFurtherNotice(); } @RuleAction(label = "@text/action-park-label", description = "@text/action-park-desc") @@ -127,12 +111,8 @@ public class AutomowerActions implements ThingActions { } } - public static void park(@Nullable ThingActions actions, int durationMin) { - if (actions instanceof AutomowerActions) { - ((AutomowerActions) actions).park(durationMin); - } else { - throw new IllegalArgumentException("Actions is not an instance of AutomowerActions"); - } + public static void park(ThingActions actions, int durationMin) { + ((AutomowerActions) actions).park(durationMin); } @RuleAction(label = "@text/action-resumeschedule-label", description = "@text/action-resumeschedule-desc") @@ -145,11 +125,7 @@ public class AutomowerActions implements ThingActions { } } - public static void resumeSchedule(@Nullable ThingActions actions) { - if (actions instanceof AutomowerActions) { - ((AutomowerActions) actions).resumeSchedule(); - } else { - throw new IllegalArgumentException("Actions is not an instance of AutomowerActions"); - } + public static void resumeSchedule(ThingActions actions) { + ((AutomowerActions) actions).resumeSchedule(); } } diff --git a/bundles/org.openhab.binding.automower/src/main/resources/OH-INF/i18n/automower.properties b/bundles/org.openhab.binding.automower/src/main/resources/OH-INF/i18n/automower.properties index a3855ee97..1f42b1aac 100644 --- a/bundles/org.openhab.binding.automower/src/main/resources/OH-INF/i18n/automower.properties +++ b/bundles/org.openhab.binding.automower/src/main/resources/OH-INF/i18n/automower.properties @@ -40,23 +40,23 @@ comm-error-send-mower-command-failed = Unable to send automower command comm-error-mower-not-connected-to-cloud = Automower not connected to the cloud -action-start-label = Start -action-start-desc = Starts the automower for a defined amount of time, overriding its schedule +action-start-label = start the automower +action-start-desc = Starts the automower for a defined amount of time, overriding its schedule. -action-pause-label = Pause -action-pause-desc = Pauses the automower wherever it currently is +action-pause-label = pause the automower +action-pause-desc = Pauses the automower wherever it currently is. -action-parkuntilnextschedule-label = Park until next schedule -action-parkuntilnextschedule-desc = Parks the automower until the next schedule +action-parkuntilnextschedule-label = park until the next schedule +action-parkuntilnextschedule-desc = Parks the automower until the next schedule. -action-parkuntilfurthernotice-label = Park until further notice -action-parkuntilfurthernotice-desc = Parks the automower until the schedule is resumed +action-parkuntilfurthernotice-label = park until further notice +action-parkuntilfurthernotice-desc = Parks the automower until the schedule is resumed. -action-park-label = Park -action-park-desc = Parks the automower for a defined amount of time, overriding its schedule +action-park-label = park the automower +action-park-desc = Parks the automower for a defined amount of time, overriding its schedule. -action-resumeschedule-label = Resume schedule -action-resumeschedule-desc = Resumes the schedule for the automower +action-resumeschedule-label = resume the schedule +action-resumeschedule-desc = Resumes the schedule for the automower. action-input-duration-label = Duration action-input-duration-desc = The duration of the automower command in minutes diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/actions/AVMFritzHeatingActions.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/actions/AVMFritzHeatingActions.java index ef5530b48..0c42928be 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/actions/AVMFritzHeatingActions.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/actions/AVMFritzHeatingActions.java @@ -55,12 +55,8 @@ public class AVMFritzHeatingActions implements ThingActions { actionsHandler.setBoostMode(duration.longValue()); } - public static void setBoostMode(@Nullable ThingActions actions, @Nullable Long duration) { - if (actions instanceof AVMFritzHeatingActions) { - ((AVMFritzHeatingActions) actions).setBoostMode(duration); - } else { - throw new IllegalArgumentException("Actions is not an instance of AVMFritzHeatingActions"); - } + public static void setBoostMode(ThingActions actions, @Nullable Long duration) { + ((AVMFritzHeatingActions) actions).setBoostMode(duration); } @RuleAction(label = "@text/setWindowOpenModeActionLabel", description = "@text/setWindowOpenModeActionDescription") @@ -76,11 +72,7 @@ public class AVMFritzHeatingActions implements ThingActions { actionsHandler.setWindowOpenMode(duration.longValue()); } - public static void setWindowOpenMode(@Nullable ThingActions actions, @Nullable Long duration) { - if (actions instanceof AVMFritzHeatingActions) { - ((AVMFritzHeatingActions) actions).setWindowOpenMode(duration); - } else { - throw new IllegalArgumentException("Actions is not an instance of AVMFritzHeatingActions"); - } + public static void setWindowOpenMode(ThingActions actions, @Nullable Long duration) { + ((AVMFritzHeatingActions) actions).setWindowOpenMode(duration); } } diff --git a/bundles/org.openhab.binding.avmfritz/src/main/resources/OH-INF/i18n/avmfritz.properties b/bundles/org.openhab.binding.avmfritz/src/main/resources/OH-INF/i18n/avmfritz.properties index 33a8100d9..1bb193760 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/resources/OH-INF/i18n/avmfritz.properties +++ b/bundles/org.openhab.binding.avmfritz/src/main/resources/OH-INF/i18n/avmfritz.properties @@ -1,10 +1,10 @@ # thing actions -setBoostModeModeActionLabel = Set Boost Mode +setBoostModeModeActionLabel = set the Boost mode setBoostModeActionDescription = Activates the Boost mode of the heating thermostat. setBoostModeDurationInputLabel = Duration setBoostModeDurationInputDescription = Duration in seconds, min. 1, max. 86400, 0 for deactivation. -setWindowOpenModeActionLabel = Set Window Open Mode +setWindowOpenModeActionLabel = set the Window Open mode setWindowOpenModeActionDescription = Activates the Window Open mode of the heating thermostat. setWindowOpenModeDurationInputLabel = Duration setWindowOpenModeDurationInputDescription = Duration in seconds, min. 1, max. 86400, 0 for deactivation. diff --git a/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/actions/AVMFritzHeatingActionsTest.java b/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/actions/AVMFritzHeatingActionsTest.java index f0f586573..13f2ac520 100644 --- a/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/actions/AVMFritzHeatingActionsTest.java +++ b/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/actions/AVMFritzHeatingActionsTest.java @@ -52,13 +52,8 @@ public class AVMFritzHeatingActionsTest { } @Test - public void testSetBoostModeThingActionsIsNull() { - assertThrows(IllegalArgumentException.class, () -> AVMFritzHeatingActions.setBoostMode(null, Long.valueOf(5L))); - } - - @Test - public void testSetBoostModeThingActionsIsNotPushoverThingActions() { - assertThrows(IllegalArgumentException.class, + public void testSetBoostModeThingActionsIsNotAVMFritzHeatingActions() { + assertThrows(ClassCastException.class, () -> AVMFritzHeatingActions.setBoostMode(thingActionsStub, Long.valueOf(5L))); } @@ -81,14 +76,8 @@ public class AVMFritzHeatingActionsTest { } @Test - public void testSetWindowOpenModeThingActionsIsNull() { - assertThrows(IllegalArgumentException.class, - () -> AVMFritzHeatingActions.setWindowOpenMode(null, Long.valueOf(5L))); - } - - @Test - public void testSetWindowOpenModeThingActionsIsNotPushoverThingActions() { - assertThrows(IllegalArgumentException.class, + public void testSetWindowOpenModeThingActionsIsNotAVMFritzHeatingActions() { + assertThrows(ClassCastException.class, () -> AVMFritzHeatingActions.setWindowOpenMode(thingActionsStub, Long.valueOf(5L))); } diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/action/DmxActions.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/action/DmxActions.java index 0e92e881a..dc7e4151e 100644 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/action/DmxActions.java +++ b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/action/DmxActions.java @@ -66,13 +66,9 @@ public class DmxActions implements ThingActions { } } - public static void sendFade(@Nullable ThingActions actions, @Nullable String channels, @Nullable String fade, + public static void sendFade(ThingActions actions, @Nullable String channels, @Nullable String fade, @Nullable Boolean resumeAfter) { - if (actions instanceof DmxActions) { - ((DmxActions) actions).sendFade(channels, fade, resumeAfter); - } else { - throw new IllegalArgumentException("Actions is not an instance of DmxActions"); - } + ((DmxActions) actions).sendFade(channels, fade, resumeAfter); } @Override diff --git a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java index 389a7bd58..d7a8b78ef 100644 --- a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java +++ b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java @@ -61,12 +61,8 @@ public class DoorbirdActions implements ThingActions { } } - public static void restart(@Nullable ThingActions actions) { - if (actions instanceof DoorbirdActions) { - ((DoorbirdActions) actions).restart(); - } else { - throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions"); - } + public static void restart(ThingActions actions) { + ((DoorbirdActions) actions).restart(); } @RuleAction(label = "hangup a SIP call", description = "Hangup SIP call.") @@ -79,12 +75,8 @@ public class DoorbirdActions implements ThingActions { } } - public static void sipHangup(@Nullable ThingActions actions) { - if (actions instanceof DoorbirdActions) { - ((DoorbirdActions) actions).sipHangup(); - } else { - throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions"); - } + public static void sipHangup(ThingActions actions) { + ((DoorbirdActions) actions).sipHangup(); } @RuleAction(label = "get the ring time limit", description = "Get the value of RING_TIME_LIMIT.") @@ -98,12 +90,8 @@ public class DoorbirdActions implements ThingActions { } } - public static String getRingTimeLimit(@Nullable ThingActions actions) { - if (actions instanceof DoorbirdActions) { - return ((DoorbirdActions) actions).getRingTimeLimit(); - } else { - throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions"); - } + public static String getRingTimeLimit(ThingActions actions) { + return ((DoorbirdActions) actions).getRingTimeLimit(); } @RuleAction(label = "get the call time limit", description = "Get the value of CALL_TIME_LIMIT.") @@ -117,12 +105,8 @@ public class DoorbirdActions implements ThingActions { } } - public static String getCallTimeLimit(@Nullable ThingActions actions) { - if (actions instanceof DoorbirdActions) { - return ((DoorbirdActions) actions).getCallTimeLimit(); - } else { - throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions"); - } + public static String getCallTimeLimit(ThingActions actions) { + return ((DoorbirdActions) actions).getCallTimeLimit(); } @RuleAction(label = "get the last error code", description = "Get the value of LASTERRORCODE.") @@ -136,12 +120,8 @@ public class DoorbirdActions implements ThingActions { } } - public static String getLastErrorCode(@Nullable ThingActions actions) { - if (actions instanceof DoorbirdActions) { - return ((DoorbirdActions) actions).getLastErrorCode(); - } else { - throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions"); - } + public static String getLastErrorCode(ThingActions actions) { + return ((DoorbirdActions) actions).getLastErrorCode(); } @RuleAction(label = "get the last error text", description = "Get the value of LASTERRORTEXT.") @@ -155,11 +135,7 @@ public class DoorbirdActions implements ThingActions { } } - public static String getLastErrorText(@Nullable ThingActions actions) { - if (actions instanceof DoorbirdActions) { - return ((DoorbirdActions) actions).getLastErrorText(); - } else { - throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions"); - } + public static String getLastErrorText(ThingActions actions) { + return ((DoorbirdActions) actions).getLastErrorText(); } } diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java index fbf788f11..a9ae8d4eb 100644 --- a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java +++ b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java @@ -102,13 +102,9 @@ public class EcobeeActions implements ThingActions { return localHandler.actionPerformFunction(function); } - public static boolean acknowledge(@Nullable ThingActions actions, @Nullable String ackRef, @Nullable String ackType, + public static boolean acknowledge(ThingActions actions, @Nullable String ackRef, @Nullable String ackType, @Nullable Boolean remindMeLater) { - if (actions instanceof EcobeeActions) { - return ((EcobeeActions) actions).acknowledge(ackRef, ackType, remindMeLater); - } else { - throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); - } + return ((EcobeeActions) actions).acknowledge(ackRef, ackType, remindMeLater); } /** @@ -137,15 +133,11 @@ public class EcobeeActions implements ThingActions { return localHandler.actionPerformFunction(function); } - 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) { - 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"); - } + public static boolean controlPlug(ThingActions actions, @Nullable String plugName, @Nullable String plugState, + @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType, + @Nullable Number holdHours) { + return ((EcobeeActions) actions).controlPlug(plugName, plugState, startDateTime, endDateTime, holdType, + holdHours); } /** @@ -175,16 +167,12 @@ public class EcobeeActions implements ThingActions { return localHandler.actionPerformFunction(function); } - public static boolean createVacation(@Nullable ThingActions actions, @Nullable String name, + public static boolean createVacation(ThingActions actions, @Nullable String name, @Nullable QuantityType coolHoldTemp, @Nullable QuantityType heatHoldTemp, @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String fan, @Nullable Number 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"); - } + return ((EcobeeActions) actions).createVacation(name, coolHoldTemp, heatHoldTemp, startDateTime, endDateTime, + fan, fanMinOnTime); } /** @@ -206,12 +194,8 @@ public class EcobeeActions implements ThingActions { return localHandler.actionPerformFunction(function); } - public static boolean deleteVacation(@Nullable ThingActions actions, @Nullable String name) { - if (actions instanceof EcobeeActions) { - return ((EcobeeActions) actions).deleteVacation(name); - } else { - throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); - } + public static boolean deleteVacation(ThingActions actions, @Nullable String name) { + return ((EcobeeActions) actions).deleteVacation(name); } /** @@ -232,12 +216,8 @@ public class EcobeeActions implements ThingActions { return localHandler.actionPerformFunction(function); } - public static boolean resetPreferences(@Nullable ThingActions actions) { - if (actions instanceof EcobeeActions) { - return ((EcobeeActions) actions).resetPreferences(); - } else { - throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); - } + public static boolean resetPreferences(ThingActions actions) { + return ((EcobeeActions) actions).resetPreferences(); } /** @@ -259,12 +239,8 @@ public class EcobeeActions implements ThingActions { return localHandler.actionPerformFunction(function); } - public static boolean resumeProgram(@Nullable ThingActions actions, @Nullable Boolean resumeAll) { - if (actions instanceof EcobeeActions) { - return ((EcobeeActions) actions).resumeProgram(resumeAll); - } else { - throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); - } + public static boolean resumeProgram(ThingActions actions, @Nullable Boolean resumeAll) { + return ((EcobeeActions) actions).resumeProgram(resumeAll); } /** @@ -286,12 +262,8 @@ public class EcobeeActions implements ThingActions { return localHandler.actionPerformFunction(function); } - public static boolean sendMessage(@Nullable ThingActions actions, @Nullable String text) { - if (actions instanceof EcobeeActions) { - return ((EcobeeActions) actions).sendMessage(text); - } else { - throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); - } + public static boolean sendMessage(ThingActions actions, @Nullable String text) { + return ((EcobeeActions) actions).sendMessage(text); } /** @@ -312,13 +284,9 @@ public class EcobeeActions implements ThingActions { return setHold(params, null, null, null, null); } - public static boolean setHold(@Nullable ThingActions actions, @Nullable QuantityType coolHoldTemp, + public static boolean setHold(ThingActions actions, @Nullable QuantityType coolHoldTemp, @Nullable QuantityType heatHoldTemp) { - if (actions instanceof EcobeeActions) { - return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp); - } else { - throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); - } + return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp); } /** @@ -343,13 +311,9 @@ public class EcobeeActions implements ThingActions { return setHold(params, null, null, null, null); } - public static boolean setHold(@Nullable ThingActions actions, @Nullable QuantityType coolHoldTemp, + public static boolean setHold(ThingActions actions, @Nullable QuantityType coolHoldTemp, @Nullable QuantityType heatHoldTemp, @Nullable Number holdHours) { - if (actions instanceof EcobeeActions) { - return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp, holdHours); - } else { - throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); - } + return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp, holdHours); } /** @@ -371,12 +335,8 @@ public class EcobeeActions implements ThingActions { return setHold(params, null, null, null, null); } - public static boolean setHold(@Nullable ThingActions actions, @Nullable String holdClimateRef) { - if (actions instanceof EcobeeActions) { - return ((EcobeeActions) actions).setHold(holdClimateRef); - } else { - throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); - } + public static boolean setHold(ThingActions actions, @Nullable String holdClimateRef) { + return ((EcobeeActions) actions).setHold(holdClimateRef); } /** @@ -404,13 +364,8 @@ public class EcobeeActions implements ThingActions { return setHold(params, null, null, null, null); } - public static boolean setHold(@Nullable ThingActions actions, @Nullable String holdClimateRef, - @Nullable Number holdHours) { - if (actions instanceof EcobeeActions) { - return ((EcobeeActions) actions).setHold(holdClimateRef, holdHours); - } else { - throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); - } + public static boolean setHold(ThingActions actions, @Nullable String holdClimateRef, @Nullable Number holdHours) { + return ((EcobeeActions) actions).setHold(holdClimateRef, holdHours); } /** @@ -438,16 +393,12 @@ public class EcobeeActions implements ThingActions { return setHold(params, holdType, holdHours, startDateTime, endDateTime); } - public static boolean setHold(@Nullable ThingActions actions, @Nullable QuantityType coolHoldTemp, + public static boolean setHold(ThingActions actions, @Nullable QuantityType coolHoldTemp, @Nullable QuantityType heatHoldTemp, @Nullable String holdClimateRef, @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType, @Nullable Number 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"); - } + return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp, holdClimateRef, startDateTime, endDateTime, + holdType, holdHours); } /** @@ -528,14 +479,9 @@ public class EcobeeActions implements ThingActions { return localHandler.actionPerformFunction(function); } - public static boolean setHold(@Nullable ThingActions actions, @Nullable Map params, - @Nullable String holdType, @Nullable Number holdHours, @Nullable Date startDateTime, - @Nullable Date 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"); - } + public static boolean setHold(ThingActions actions, @Nullable Map params, @Nullable String holdType, + @Nullable Number holdHours, @Nullable Date startDateTime, @Nullable Date endDateTime) { + return ((EcobeeActions) actions).setHold(params, holdType, holdHours, startDateTime, endDateTime); } /** @@ -564,14 +510,9 @@ public class EcobeeActions implements ThingActions { return localHandler.actionPerformFunction(function); } - public static boolean setOccupied(@Nullable ThingActions actions, @Nullable Boolean occupied, - @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType, - @Nullable Number 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"); - } + public static boolean setOccupied(ThingActions actions, @Nullable Boolean occupied, @Nullable Date startDateTime, + @Nullable Date endDateTime, @Nullable String holdType, @Nullable Number holdHours) { + return ((EcobeeActions) actions).setOccupied(occupied, startDateTime, endDateTime, holdType, holdHours); } /** @@ -595,13 +536,9 @@ public class EcobeeActions implements ThingActions { return localHandler.actionPerformFunction(function); } - public static boolean updateSensor(@Nullable ThingActions actions, @Nullable String name, @Nullable String deviceId, + public static boolean updateSensor(ThingActions actions, @Nullable String name, @Nullable String deviceId, @Nullable String sensorId) { - if (actions instanceof EcobeeActions) { - return ((EcobeeActions) actions).updateSensor(name, deviceId, sensorId); - } else { - throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); - } + return ((EcobeeActions) actions).updateSensor(name, deviceId, sensorId); } /** @@ -618,12 +555,8 @@ public class EcobeeActions implements ThingActions { return localHandler.getAlerts(); } - public static @Nullable String getAlerts(@Nullable ThingActions actions) { - if (actions instanceof EcobeeActions) { - return ((EcobeeActions) actions).getAlerts(); - } else { - throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); - } + public static @Nullable String getAlerts(ThingActions actions) { + return ((EcobeeActions) actions).getAlerts(); } /** @@ -640,12 +573,8 @@ public class EcobeeActions implements ThingActions { return localHandler.getEvents(); } - public static @Nullable String getEvents(@Nullable ThingActions actions) { - if (actions instanceof EcobeeActions) { - return ((EcobeeActions) actions).getEvents(); - } else { - throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); - } + public static @Nullable String getEvents(ThingActions actions) { + return ((EcobeeActions) actions).getEvents(); } /** @@ -662,11 +591,7 @@ public class EcobeeActions implements ThingActions { return localHandler.getClimates(); } - public static @Nullable String getClimates(@Nullable ThingActions actions) { - if (actions instanceof EcobeeActions) { - return ((EcobeeActions) actions).getClimates(); - } else { - throw new IllegalArgumentException("Actions is not an instance of EcobeeActions"); - } + public static @Nullable String getClimates(ThingActions actions) { + return ((EcobeeActions) actions).getClimates(); } } diff --git a/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/actions/Enigma2Actions.java b/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/actions/Enigma2Actions.java index 258fd239d..821229183 100644 --- a/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/actions/Enigma2Actions.java +++ b/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/actions/Enigma2Actions.java @@ -111,75 +111,39 @@ public class Enigma2Actions implements ThingActions { } // delegation methods for "legacy" rule support - public static void sendRcCommand(@Nullable ThingActions actions, String rcButton) { - if (actions instanceof Enigma2Actions) { - ((Enigma2Actions) actions).sendRcCommand(rcButton); - } else { - throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); - } + public static void sendRcCommand(ThingActions actions, String rcButton) { + ((Enigma2Actions) actions).sendRcCommand(rcButton); } - public static void sendInfo(@Nullable ThingActions actions, String info) { - if (actions instanceof Enigma2Actions) { - ((Enigma2Actions) actions).sendInfo(info); - } else { - throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); - } + public static void sendInfo(ThingActions actions, String info) { + ((Enigma2Actions) actions).sendInfo(info); } - public static void sendInfo(@Nullable ThingActions actions, String info, int timeout) { - if (actions instanceof Enigma2Actions) { - ((Enigma2Actions) actions).sendInfo(info, timeout); - } else { - throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); - } + public static void sendInfo(ThingActions actions, String info, int timeout) { + ((Enigma2Actions) actions).sendInfo(info, timeout); } - public static void sendWarning(@Nullable ThingActions actions, String warning) { - if (actions instanceof Enigma2Actions) { - ((Enigma2Actions) actions).sendWarning(warning); - } else { - throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); - } + public static void sendWarning(ThingActions actions, String warning) { + ((Enigma2Actions) actions).sendWarning(warning); } - public static void sendWarning(@Nullable ThingActions actions, String warning, int timeout) { - if (actions instanceof Enigma2Actions) { - ((Enigma2Actions) actions).sendWarning(warning, timeout); - } else { - throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); - } + public static void sendWarning(ThingActions actions, String warning, int timeout) { + ((Enigma2Actions) actions).sendWarning(warning, timeout); } - public static void sendError(@Nullable ThingActions actions, String error) { - if (actions instanceof Enigma2Actions) { - ((Enigma2Actions) actions).sendError(error); - } else { - throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); - } + public static void sendError(ThingActions actions, String error) { + ((Enigma2Actions) actions).sendError(error); } - public static void sendError(@Nullable ThingActions actions, String error, int timeout) { - if (actions instanceof Enigma2Actions) { - ((Enigma2Actions) actions).sendError(error, timeout); - } else { - throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); - } + public static void sendError(ThingActions actions, String error, int timeout) { + ((Enigma2Actions) actions).sendError(error, timeout); } - public static void sendQuestion(@Nullable ThingActions actions, String text) { - if (actions instanceof Enigma2Actions) { - ((Enigma2Actions) actions).sendQuestion(text); - } else { - throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); - } + public static void sendQuestion(ThingActions actions, String text) { + ((Enigma2Actions) actions).sendQuestion(text); } - public static void sendQuestion(@Nullable ThingActions actions, String text, int timeout) { - if (actions instanceof Enigma2Actions) { - ((Enigma2Actions) actions).sendQuestion(text, timeout); - } else { - throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions"); - } + public static void sendQuestion(ThingActions actions, String text, int timeout) { + ((Enigma2Actions) actions).sendQuestion(text, timeout); } } diff --git a/bundles/org.openhab.binding.enigma2/src/main/resources/OH-INF/i18n/enigma2.properties b/bundles/org.openhab.binding.enigma2/src/main/resources/OH-INF/i18n/enigma2.properties index 3eca7bac7..b847c1109 100644 --- a/bundles/org.openhab.binding.enigma2/src/main/resources/OH-INF/i18n/enigma2.properties +++ b/bundles/org.openhab.binding.enigma2/src/main/resources/OH-INF/i18n/enigma2.properties @@ -17,19 +17,19 @@ channel-type.enigma2.power.label = Power channel-type.enigma2.power.description = Setting the power to on/off. # actions -action.enigma2.send-rc-button.label=sendRcCommand -action.enigma2.send-rc-button.description=Send an Remote Control Command -action-input.enigma2.rc-button.label=rcButton -action-input.enigma2.rc-button.description=The Remote Control Button +action.enigma2.send-rc-button.label=send a remote control command +action.enigma2.send-rc-button.description=Send a remote control command. +action-input.enigma2.rc-button.label=Button +action-input.enigma2.rc-button.description=The remote control button -action.enigma2.send-info.label=sendInfo -action.enigma2.send-info.description=Send an info message to the TV screen -action.enigma2.send-warning.label=sendWarning -action.enigma2.send-warning.description=Send an warning message to the TV screen -action.enigma2.send-error.label=sendError -action.enigma2.send-error.description=Send an error message to the TV screen -action.enigma2.send-question.label=sendQuestion -action.enigma2.send-question.description=Send a question message to the TV screen +action.enigma2.send-info.label=send an info message +action.enigma2.send-info.description=Send an info message to the TV screen. +action.enigma2.send-warning.label=send a warning message +action.enigma2.send-warning.description=Send a warning message to the TV screen. +action.enigma2.send-error.label=send an error message +action.enigma2.send-error.description=Send an error message to the TV screen. +action.enigma2.send-question.label=send a question message +action.enigma2.send-question.description=Send a question message to the TV screen. action-input.enigma2.text.label=text action-input.enigma2.text.description=The message text action-input.enigma2.timeout.label=timeout diff --git a/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/internal/actions/Enigma2ActionsTest.java b/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/internal/actions/Enigma2ActionsTest.java index 2a9a7cf90..a5414bebb 100644 --- a/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/internal/actions/Enigma2ActionsTest.java +++ b/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/internal/actions/Enigma2ActionsTest.java @@ -14,11 +14,9 @@ package org.openhab.binding.enigma2.internal.actions; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.*; 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.internal.Enigma2BindingConstants; @@ -29,13 +27,10 @@ import org.openhab.binding.enigma2.internal.handler.Enigma2Handler; * * @author Guido Dolfen - Initial contribution */ -@SuppressWarnings("null") @NonNullByDefault public class Enigma2ActionsTest { - @Nullable - private Enigma2Actions enigma2Actions; - @Nullable - private Enigma2Handler enigma2Handler; + private @NonNullByDefault({}) Enigma2Actions enigma2Actions; + private @NonNullByDefault({}) Enigma2Handler enigma2Handler; public static final String SOME_TEXT = "some Text"; @BeforeEach @@ -110,11 +105,6 @@ public class Enigma2ActionsTest { verify(enigma2Handler).sendRcCommand("KEY_1"); } - @Test - public void testSendRcCommandStaticWithException() { - assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendRcCommand(null, "KEY_1")); - } - @Test public void testSendInfoStatic() { Enigma2Actions.sendInfo(enigma2Actions, SOME_TEXT); @@ -127,11 +117,6 @@ public class Enigma2ActionsTest { verify(enigma2Handler).sendInfo(10, SOME_TEXT); } - @Test - public void testSendInfoStaticWithException() { - assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendInfo(null, SOME_TEXT)); - } - @Test public void testSendErrorStatic() { Enigma2Actions.sendError(enigma2Actions, SOME_TEXT); @@ -144,11 +129,6 @@ public class Enigma2ActionsTest { verify(enigma2Handler).sendError(10, SOME_TEXT); } - @Test - public void testSendErrorStaticWithException() { - assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendError(null, SOME_TEXT)); - } - @Test public void testSendWarningStatic() { Enigma2Actions.sendWarning(enigma2Actions, SOME_TEXT); @@ -161,11 +141,6 @@ public class Enigma2ActionsTest { verify(enigma2Handler).sendWarning(10, SOME_TEXT); } - @Test - public void testSendWarningStaticWithException() { - assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendWarning(null, SOME_TEXT)); - } - @Test public void testSendQuestionStatic() { Enigma2Actions.sendQuestion(enigma2Actions, SOME_TEXT); @@ -177,9 +152,4 @@ public class Enigma2ActionsTest { Enigma2Actions.sendQuestion(enigma2Actions, SOME_TEXT, 10); verify(enigma2Handler).sendQuestion(10, SOME_TEXT); } - - @Test - public void testSendQuestionStaticWithException() { - assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendQuestion(null, SOME_TEXT)); - } } 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 d27f8494d..117bf5508 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 @@ -75,19 +75,11 @@ public class Ipx800Actions implements ThingActions { } } - public static void resetCounter(@Nullable ThingActions actions, Integer counter) { - if (actions instanceof Ipx800Actions) { - ((Ipx800Actions) actions).resetCounter(counter); - } else { - throw new IllegalArgumentException("Actions is not an instance of Ipx800Actions"); - } + public static void resetCounter(ThingActions actions, Integer counter) { + ((Ipx800Actions) actions).resetCounter(counter); } - public static void reset(@Nullable ThingActions actions, @Nullable Integer placeholder) { - if (actions instanceof Ipx800Actions) { - ((Ipx800Actions) actions).reset(placeholder); - } else { - throw new IllegalArgumentException("Actions is not an instance of Ipx800Actions"); - } + public static void reset(ThingActions actions, @Nullable Integer placeholder) { + ((Ipx800Actions) actions).reset(placeholder); } } 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 72dbe8e7b..e3ef32187 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 @@ -62,7 +62,7 @@ public class HeosActions implements ThingActions { return handler.getApiConnection(); } - @RuleAction(label = "Play Input", description = "Play an input from another device") + @RuleAction(label = "play an 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, @ActionInput(name = "input", label = "Source Input", description = "Input source used") @Nullable String input, @@ -88,12 +88,8 @@ public class HeosActions implements ThingActions { } } - public static void playInputFromPlayer(@Nullable ThingActions actions, @Nullable Integer sourcePlayer, - @Nullable String input, @Nullable Integer destinationPlayer) { - if (actions instanceof HeosActions) { - ((HeosActions) actions).playInputFromPlayer(sourcePlayer, input, destinationPlayer); - } else { - throw new IllegalArgumentException("Actions is not an instance of HeosActions"); - } + public static void playInputFromPlayer(ThingActions actions, @Nullable Integer sourcePlayer, @Nullable String input, + @Nullable Integer destinationPlayer) { + ((HeosActions) actions).playInputFromPlayer(sourcePlayer, input, destinationPlayer); } } 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 2e994368e..302496309 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 @@ -76,12 +76,8 @@ public class LightActions implements ThingActions { logger.debug("send LightAction to {} with {}ms of fadeTime", channel, fadeTime); } - public static void fadingLightCommand(@Nullable ThingActions actions, @Nullable String channel, - @Nullable Command command, @Nullable DecimalType fadeTime) { - if (actions instanceof LightActions) { - ((LightActions) actions).fadingLightCommand(channel, command, fadeTime); - } else { - throw new IllegalArgumentException("Actions is not an instance of LightActions"); - } + public static void fadingLightCommand(ThingActions actions, @Nullable String channel, @Nullable Command command, + @Nullable DecimalType fadeTime) { + ((LightActions) actions).fadingLightCommand(channel, command, fadeTime); } } diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraActions.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraActions.java index 2072becff..1ea92adaf 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraActions.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraActions.java @@ -45,7 +45,7 @@ public class IpCameraActions implements ThingActions { return handler; } - @RuleAction(label = "Record MP4", description = "Record MP4 to a set filename if given, or if filename is null to ipcamera.mp4") + @RuleAction(label = "record an MP4", description = "Record MP4 to a set filename if given, or if filename is null to ipcamera.mp4") public void recordMP4( @ActionInput(name = "filename", label = "Filename", description = "Name that the recording will have once created, don't include the .mp4.") @Nullable String filename, @ActionInput(name = "secondsToRecord", label = "Seconds to Record", description = "Enter a number of how many seconds to record.") int secondsToRecord) { @@ -57,15 +57,11 @@ public class IpCameraActions implements ThingActions { } } - public static void recordMP4(@Nullable ThingActions actions, @Nullable String filename, int secondsToRecord) { - if (actions instanceof IpCameraActions) { - ((IpCameraActions) actions).recordMP4(filename, secondsToRecord); - } else { - throw new IllegalArgumentException("Instance is not a IpCamera class."); - } + public static void recordMP4(ThingActions actions, @Nullable String filename, int secondsToRecord) { + ((IpCameraActions) actions).recordMP4(filename, secondsToRecord); } - @RuleAction(label = "Record GIF", description = "Record GIF to a set filename if given, or if filename is null to ipcamera.gif") + @RuleAction(label = "record a GIF", description = "Record GIF to a set filename if given, or if filename is null to ipcamera.gif") public void recordGIF( @ActionInput(name = "filename", label = "Filename", description = "Name that the recording will have once created, don't include the .mp4.") @Nullable String filename, @ActionInput(name = "secondsToRecord", label = "Seconds to Record", description = "Enter a number of how many seconds to record.") int secondsToRecord) { @@ -77,11 +73,7 @@ public class IpCameraActions implements ThingActions { } } - public static void recordGIF(@Nullable ThingActions actions, @Nullable String filename, int secondsToRecord) { - if (actions instanceof IpCameraActions) { - ((IpCameraActions) actions).recordGIF(filename, secondsToRecord); - } else { - throw new IllegalArgumentException("Instance is not a IpCamera class."); - } + public static void recordGIF(ThingActions actions, @Nullable String filename, int secondsToRecord) { + ((IpCameraActions) actions).recordGIF(filename, secondsToRecord); } } 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 6a5fad50b..3f86492e0 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 @@ -47,12 +47,8 @@ public class KaleidescapeThingActions implements ThingActions { } /** 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 { - if (actions instanceof KaleidescapeThingActions) { - ((KaleidescapeThingActions) actions).sendKCommand(kCommand); - } else { - throw new IllegalArgumentException("Actions is not an instance of KaleidescapeThingActions"); - } + public static void sendKCommand(ThingActions actions, String kCommand) throws IllegalArgumentException { + ((KaleidescapeThingActions) actions).sendKCommand(kCommand); } @Override 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 cad59e557..9f98e14f1 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 @@ -169,40 +169,23 @@ public class LcnModuleActions implements ThingActions { } /** 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) { - if (actions instanceof LcnModuleHandler) { - ((LcnModuleActions) actions).hitKey(table, key, action); - } else { - throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions"); - } + public static void hitKey(ThingActions actions, @Nullable String table, int key, @Nullable String action) { + ((LcnModuleActions) actions).hitKey(table, key, action); } /** 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) { - if (actions instanceof LcnModuleHandler) { - ((LcnModuleActions) actions).flickerOutput(output, depth, ramp, count); - } else { - throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions"); - } + public static void flickerOutput(ThingActions actions, int output, int depth, int ramp, int count) { + ((LcnModuleActions) actions).flickerOutput(output, depth, ramp, count); } /** 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) { - if (actions instanceof LcnModuleHandler) { - ((LcnModuleActions) actions).sendDynamicText(row, text); - } else { - throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions"); - } + public static void sendDynamicText(ThingActions actions, int row, @Nullable String text) { + ((LcnModuleActions) actions).sendDynamicText(row, text); } /** 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) { - if (actions instanceof LcnModuleHandler) { - ((LcnModuleActions) actions).startRelayTimer(relaynumber, duration); - } else { - throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions"); - } + public static void startRelayTimer(ThingActions actions, int relaynumber, double duration) { + ((LcnModuleActions) actions).startRelayTimer(relaynumber, duration); } private LcnModuleHandler getHandler() throws LcnException { diff --git a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/action/LGWebOSActions.java b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/action/LGWebOSActions.java index 954a09715..219ab9076 100644 --- a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/action/LGWebOSActions.java +++ b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/action/LGWebOSActions.java @@ -281,83 +281,43 @@ public class LGWebOSActions implements ThingActions { // delegation methods for "legacy" rule support - public static void showToast(@Nullable ThingActions actions, String text) throws IOException { - if (actions instanceof LGWebOSActions) { - ((LGWebOSActions) actions).showToast(text); - } else { - throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); - } + public static void showToast(ThingActions actions, String text) throws IOException { + ((LGWebOSActions) actions).showToast(text); } - public static void showToast(@Nullable ThingActions actions, String icon, String text) throws IOException { - if (actions instanceof LGWebOSActions) { - ((LGWebOSActions) actions).showToast(icon, text); - } else { - throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); - } + public static void showToast(ThingActions actions, String icon, String text) throws IOException { + ((LGWebOSActions) actions).showToast(icon, text); } - public static void launchBrowser(@Nullable ThingActions actions, String url) { - if (actions instanceof LGWebOSActions) { - ((LGWebOSActions) actions).launchBrowser(url); - } else { - throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); - } + public static void launchBrowser(ThingActions actions, String url) { + ((LGWebOSActions) actions).launchBrowser(url); } - public static void launchApplication(@Nullable ThingActions actions, String appId) { - if (actions instanceof LGWebOSActions) { - ((LGWebOSActions) actions).launchApplication(appId); - } else { - throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); - } + public static void launchApplication(ThingActions actions, String appId) { + ((LGWebOSActions) actions).launchApplication(appId); } - public static void launchApplication(@Nullable ThingActions actions, String appId, String param) { - if (actions instanceof LGWebOSActions) { - ((LGWebOSActions) actions).launchApplication(appId, param); - } else { - throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); - } + public static void launchApplication(ThingActions actions, String appId, String param) { + ((LGWebOSActions) actions).launchApplication(appId, param); } - public static void sendText(@Nullable ThingActions actions, String text) { - if (actions instanceof LGWebOSActions) { - ((LGWebOSActions) actions).sendText(text); - } else { - throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); - } + public static void sendText(ThingActions actions, String text) { + ((LGWebOSActions) actions).sendText(text); } - public static void sendButton(@Nullable ThingActions actions, String button) { - if (actions instanceof LGWebOSActions) { - ((LGWebOSActions) actions).sendButton(button); - } else { - throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); - } + public static void sendButton(ThingActions actions, String button) { + ((LGWebOSActions) actions).sendButton(button); } - public static void increaseChannel(@Nullable ThingActions actions) { - if (actions instanceof LGWebOSActions) { - ((LGWebOSActions) actions).increaseChannel(); - } else { - throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); - } + public static void increaseChannel(ThingActions actions) { + ((LGWebOSActions) actions).increaseChannel(); } - public static void decreaseChannel(@Nullable ThingActions actions) { - if (actions instanceof LGWebOSActions) { - ((LGWebOSActions) actions).decreaseChannel(); - } else { - throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); - } + public static void decreaseChannel(ThingActions actions) { + ((LGWebOSActions) actions).decreaseChannel(); } - public static void sendRCButton(@Nullable ThingActions actions, String rcButton) { - if (actions instanceof LGWebOSActions) { - ((LGWebOSActions) actions).sendRCButton(rcButton); - } else { - throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions"); - } + public static void sendRCButton(ThingActions actions, String rcButton) { + ((LGWebOSActions) actions).sendRCButton(rcButton); } } diff --git a/bundles/org.openhab.binding.lgwebos/src/main/resources/OH-INF/i18n/lgwebos.properties b/bundles/org.openhab.binding.lgwebos/src/main/resources/OH-INF/i18n/lgwebos.properties index 17271fa2b..ebe5969fe 100644 --- a/bundles/org.openhab.binding.lgwebos/src/main/resources/OH-INF/i18n/lgwebos.properties +++ b/bundles/org.openhab.binding.lgwebos/src/main/resources/OH-INF/i18n/lgwebos.properties @@ -1,45 +1,45 @@ -actionShowToastLabel=Show Toast +actionShowToastLabel=show a toast message actionShowToastDesc=Sends a toast message to a WebOS device with openHAB icon. actionShowToastInputTextLabel=Text actionShowToastInputTextDesc=The text to display -actionShowToastWithIconLabel=Show Toast with Icon +actionShowToastWithIconLabel=show a toast message with icon actionShowToastWithIconLabel=Sends a toast message to a WebOS device with custom icon. actionShowToastInputIconLabel=Icon actionShowToastInputIconDesc=The URL to the icon to display -actionLaunchBrowserLabel=Launch Browser +actionLaunchBrowserLabel=launch the browser actionLaunchBrowserDesc=Opens the given URL in the TV's browser application. actionLaunchBrowserInputUrlLabel=URL actionLaunchBrowserInputUrlDesc=The URL to open -actionLaunchApplicationLabel=Launch Application +actionLaunchApplicationLabel=launch an application actionLaunchApplicationDesc=Opens the application with given Application ID. actionLaunchApplicationInputAppIDLabel=Application ID actionLaunchApplicationInputAppIDDesc=The Application ID -actionLaunchApplicationWithParamsLabel=Launch Application with Parameters +actionLaunchApplicationWithParamsLabel=launch an application with parameters actionLaunchApplicationWithParamsDesc=Opens the application with given Application ID and passes additional parameters. actionLaunchApplicationInputParamsLabel=JSON Parameters actionLaunchApplicationInputParamsDesc=The parameters to hand over to the application in JSON format -actionSendTextLabel=Send Text +actionSendTextLabel=send a text input actionSendTextDesc=Sends a text input to a WebOS device. actionSendTextInputTextLabel=Text actionSendTextInputTextDesc=The text to input -actionSendButtonLabel=Send Button +actionSendButtonLabel=send a button press actionSendButtonDesc=Sends a button press event to a WebOS device. actionSendButtonInputButtonLabel=Button actionSendButtonInputButtonDesc=Can be one of UP, DOWN, LEFT, RIGHT, BACK, DELETE, ENTER, HOME, or OK -actionIncreaseChannelLabel=Channel Up +actionIncreaseChannelLabel=switch one channel up actionIncreaseChannelDesc=TV will switch one channel up in the current channel list. -actionDecreaseChannelLabel=Channel Down +actionDecreaseChannelLabel=switch one channel down actionDecreaseChannelDesc=TV will switch one channel down in the current channel list. -actionSendRCButtonLabel=Remote Control button press +actionSendRCButtonLabel=simulate remote control button press actionSendRCButtonDesc=Simulates pressing of a Remote Control Button. actionSendRCButtonInputTextLabel=Remote Control button name actionSendRCButtonInputTextDesc=The Remote Control button name to send to the WebOS device. diff --git a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/action/DimmerActions.java b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/action/DimmerActions.java index 48fb70eaf..da7cdace6 100644 --- a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/action/DimmerActions.java +++ b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/action/DimmerActions.java @@ -98,12 +98,8 @@ public class DimmerActions implements ThingActions { /** * Static setLevel method for Rules DSL backward compatibility */ - public static void setLevel(@Nullable ThingActions actions, @Nullable Double level, @Nullable Double fadeTime, + public static void setLevel(ThingActions actions, @Nullable Double level, @Nullable Double fadeTime, @Nullable Double delayTime) { - if (actions instanceof DimmerActions) { - ((DimmerActions) actions).setLevel(level, fadeTime, delayTime); - } else { - throw new IllegalArgumentException("Actions is not an instance of DimmerActions"); - } + ((DimmerActions) actions).setLevel(level, fadeTime, delayTime); } } diff --git a/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/action/SendMailActions.java b/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/action/SendMailActions.java index 2c86e18ce..bc7ada427 100644 --- a/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/action/SendMailActions.java +++ b/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/action/SendMailActions.java @@ -103,12 +103,12 @@ public class SendMailActions implements ThingActions { } } - public static boolean sendMail(@Nullable ThingActions actions, @Nullable String recipient, @Nullable String subject, + public static boolean sendMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, @Nullable String text) { return SendMailActions.sendMail(actions, recipient, subject, text, new ArrayList<>()); } - public static boolean sendMail(@Nullable ThingActions actions, @Nullable String recipient, @Nullable String subject, + public static boolean sendMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, @Nullable String text, @Nullable String urlString) { List urlList = new ArrayList<>(); if (urlString != null) { @@ -117,13 +117,9 @@ public class SendMailActions implements ThingActions { return SendMailActions.sendMail(actions, recipient, subject, text, urlList); } - public static boolean sendMail(@Nullable ThingActions actions, @Nullable String recipient, @Nullable String subject, + public static boolean sendMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, @Nullable String text, @Nullable List urlStringList) { - if (actions instanceof SendMailActions) { - return ((SendMailActions) actions).sendMail(recipient, subject, text, urlStringList); - } else { - throw new IllegalArgumentException("Actions is not an instance of SendMailActions"); - } + return ((SendMailActions) actions).sendMail(recipient, subject, text, urlStringList); } @RuleAction(label = "send a HTML mail", description = "Sends a HTML mail.") @@ -184,13 +180,13 @@ public class SendMailActions implements ThingActions { } } - public static boolean sendHtmlMail(@Nullable ThingActions actions, @Nullable String recipient, - @Nullable String subject, @Nullable String html) { + public static boolean sendHtmlMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, + @Nullable String html) { return SendMailActions.sendHtmlMail(actions, recipient, subject, html, new ArrayList<>()); } - public static boolean sendHtmlMail(@Nullable ThingActions actions, @Nullable String recipient, - @Nullable String subject, @Nullable String html, @Nullable String urlString) { + public static boolean sendHtmlMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, + @Nullable String html, @Nullable String urlString) { List urlList = new ArrayList<>(); if (urlString != null) { urlList.add(urlString); @@ -198,13 +194,9 @@ public class SendMailActions implements ThingActions { return SendMailActions.sendHtmlMail(actions, recipient, subject, html, urlList); } - public static boolean sendHtmlMail(@Nullable ThingActions actions, @Nullable String recipient, - @Nullable String subject, @Nullable String html, @Nullable List urlStringList) { - if (actions instanceof SendMailActions) { - return ((SendMailActions) actions).sendHtmlMail(recipient, subject, html, urlStringList); - } else { - throw new IllegalArgumentException("Actions is not an instance of SendMailActions"); - } + public static boolean sendHtmlMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, + @Nullable String html, @Nullable List urlStringList) { + return ((SendMailActions) actions).sendHtmlMail(recipient, subject, html, urlStringList); } @Override diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/MaxCubeActions.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/MaxCubeActions.java index 0814fe1e7..5997f7c35 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/MaxCubeActions.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/MaxCubeActions.java @@ -59,12 +59,8 @@ public class MaxCubeActions implements ThingActions { return true; } - public static boolean backup(@Nullable ThingActions actions) { - if (actions instanceof MaxCubeActions) { - return ((MaxCubeActions) actions).backup(); - } else { - throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions"); - } + public static boolean backup(ThingActions actions) { + return ((MaxCubeActions) actions).backup(); } @RuleAction(label = "reset the Cube configuration", description = "Resets the MAX! Cube room and device information. Devices will need to be included again!") @@ -78,12 +74,8 @@ public class MaxCubeActions implements ThingActions { return true; } - public static boolean reset(@Nullable ThingActions actions) { - if (actions instanceof MaxCubeActions) { - return ((MaxCubeActions) actions).resetConfig(); - } else { - throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions"); - } + public static boolean reset(ThingActions actions) { + return ((MaxCubeActions) actions).resetConfig(); } @RuleAction(label = "restart the Cube", description = "Restarts the MAX! Cube.") @@ -97,11 +89,7 @@ public class MaxCubeActions implements ThingActions { return true; } - public static boolean reboot(@Nullable ThingActions actions) { - if (actions instanceof MaxCubeActions) { - return ((MaxCubeActions) actions).reboot(); - } else { - throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions"); - } + public static boolean reboot(ThingActions actions) { + return ((MaxCubeActions) actions).reboot(); } } diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/MaxDevicesActions.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/MaxDevicesActions.java index f14fdbda9..d5d6f200a 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/MaxDevicesActions.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/actions/MaxDevicesActions.java @@ -59,11 +59,7 @@ public class MaxDevicesActions implements ThingActions { return true; } - public static boolean deleteFromCube(@Nullable ThingActions actions) { - if (actions instanceof MaxDevicesActions) { - return ((MaxDevicesActions) actions).deleteFromCube(); - } else { - throw new IllegalArgumentException("Actions is not an instance of MaxDevicesActions"); - } + public static boolean deleteFromCube(ThingActions actions) { + return ((MaxDevicesActions) actions).deleteFromCube(); } } diff --git a/bundles/org.openhab.binding.modbus.helioseasycontrols/src/main/java/org/openhab/binding/modbus/helioseasycontrols/internal/HeliosEasyControlsActions.java b/bundles/org.openhab.binding.modbus.helioseasycontrols/src/main/java/org/openhab/binding/modbus/helioseasycontrols/internal/HeliosEasyControlsActions.java index ffa561ce9..8efc8bb17 100644 --- a/bundles/org.openhab.binding.modbus.helioseasycontrols/src/main/java/org/openhab/binding/modbus/helioseasycontrols/internal/HeliosEasyControlsActions.java +++ b/bundles/org.openhab.binding.modbus.helioseasycontrols/src/main/java/org/openhab/binding/modbus/helioseasycontrols/internal/HeliosEasyControlsActions.java @@ -47,67 +47,51 @@ public class HeliosEasyControlsActions implements ThingActions { private void triggerSwitch(String variableName) { try { - if (this.handler != null) { - this.handler.writeValue(variableName, "1"); + if (handler != null) { + handler.writeValue(variableName, "1"); } } catch (HeliosException e) { logger.warn("Error executing action 'resetFilterChangeTimer': {}", e.getMessage()); } } - @RuleAction(label = "Reset filter change timer", description = "Sets the filter change timer back to the configured interval") + @RuleAction(label = "reset filter change timer", description = "Sets the filter change timer back to the configured interval.") public void resetFilterChangeTimer() { - this.triggerSwitch(HeliosEasyControlsBindingConstants.FILTER_CHANGE_RESET); + triggerSwitch(HeliosEasyControlsBindingConstants.FILTER_CHANGE_RESET); } - public static void resetFilterChangeTimer(@Nullable ThingActions actions) { - if (actions instanceof HeliosEasyControlsActions) { - ((HeliosEasyControlsActions) actions).resetFilterChangeTimer(); - } else { - throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class."); - } + public static void resetFilterChangeTimer(ThingActions actions) { + ((HeliosEasyControlsActions) actions).resetFilterChangeTimer(); } - @RuleAction(label = "Reset error messages", description = "Reset error/warning/info messages") + @RuleAction(label = "reset error messages", description = "Reset error/warning/info messages.") public void resetErrors() { - this.triggerSwitch(HeliosEasyControlsBindingConstants.RESET_FLAG); + triggerSwitch(HeliosEasyControlsBindingConstants.RESET_FLAG); } - public static void resetErrors(@Nullable ThingActions actions) { - if (actions instanceof HeliosEasyControlsActions) { - ((HeliosEasyControlsActions) actions).resetErrors(); - } else { - throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class."); - } + public static void resetErrors(ThingActions actions) { + ((HeliosEasyControlsActions) actions).resetErrors(); } - @RuleAction(label = "Reset to factory defaults", description = "Reset device to factory defaults") + @RuleAction(label = "reset to factory defaults", description = "Reset device to factory defaults.") public void resetToFactoryDefaults() { - this.triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_RESET); + triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_RESET); } - public static void resetToFactoryDefaults(@Nullable ThingActions actions) { - if (actions instanceof HeliosEasyControlsActions) { - ((HeliosEasyControlsActions) actions).resetToFactoryDefaults(); - } else { - throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class."); - } + public static void resetToFactoryDefaults(ThingActions actions) { + ((HeliosEasyControlsActions) actions).resetToFactoryDefaults(); } - @RuleAction(label = "Reset individual switching times", description = "Reset individual switching times") + @RuleAction(label = "reset individual switching times", description = "Reset individual switching times.") public void resetSwitchingTimes() { - this.triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_SETTING_WZU); + triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_SETTING_WZU); } - public static void resetSwitchingTimes(@Nullable ThingActions actions) { - if (actions instanceof HeliosEasyControlsActions) { - ((HeliosEasyControlsActions) actions).resetSwitchingTimes(); - } else { - throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class."); - } + public static void resetSwitchingTimes(ThingActions actions) { + ((HeliosEasyControlsActions) actions).resetSwitchingTimes(); } - @RuleAction(label = "Set system date and time", description = "Sets the device's system date and time based on OH's system date and time") + @RuleAction(label = "set system date and time", description = "Sets the device's system date and time based on OH's system date and time.") public void setSysDateTime() { HeliosEasyControlsHandler handler = this.handler; if (handler != null) { @@ -115,12 +99,8 @@ public class HeliosEasyControlsActions implements ThingActions { } } - public static void setSysDateTime(@Nullable ThingActions actions) { - if (actions instanceof HeliosEasyControlsActions) { - ((HeliosEasyControlsActions) actions).setSysDateTime(); - } else { - throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class."); - } + public static void setSysDateTime(ThingActions actions) { + ((HeliosEasyControlsActions) actions).setSysDateTime(); } private void setBypass(boolean from, int day, int month) { @@ -130,33 +110,25 @@ public class HeliosEasyControlsActions implements ThingActions { } } - @RuleAction(label = "Set the bypass from day and month", description = "Sets the day and month from when the bypass should be active") + @RuleAction(label = "set the bypass from day and month", description = "Sets the day and month from when the bypass should be active.") public void setBypassFrom( @ActionInput(name = "day", label = "bypass from day", description = "The day from when the bypass should be active") int day, @ActionInput(name = "month", label = "bypass from month", description = "The month from when the bypass should be active") int month) { - this.setBypass(true, day, month); + setBypass(true, day, month); } - public static void setBypassFrom(@Nullable ThingActions actions, int day, int month) { - if (actions instanceof HeliosEasyControlsActions) { - ((HeliosEasyControlsActions) actions).setBypassFrom(day, month); - } else { - throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class."); - } + public static void setBypassFrom(ThingActions actions, int day, int month) { + ((HeliosEasyControlsActions) actions).setBypassFrom(day, month); } - @RuleAction(label = "Set the bypass to day and month", description = "Sets the day and month until when the bypass should be active") + @RuleAction(label = "set the bypass to day and month", description = "Sets the day and month until when the bypass should be active.") public void setBypassTo( @ActionInput(name = "day", label = "bypass to day", description = "The day until when the bypass should be active") int day, @ActionInput(name = "month", label = "bypass to month", description = "The month until when the bypass should be active") int month) { - this.setBypass(false, day, month); + setBypass(false, day, month); } - public static void setBypassTo(@Nullable ThingActions actions, int day, int month) { - if (actions instanceof HeliosEasyControlsActions) { - ((HeliosEasyControlsActions) actions).setBypassTo(day, month); - } else { - throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class."); - } + public static void setBypassTo(ThingActions actions, int day, int month) { + ((HeliosEasyControlsActions) actions).setBypassTo(day, month); } } 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 060ea6d37..6834b84be 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 @@ -73,20 +73,11 @@ public class MPDActions implements ThingActions { } } - public static void sendCommand(@Nullable ThingActions actions, @Nullable String command, - @Nullable String 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(ThingActions actions, @Nullable String command, @Nullable String parameter) { + ((MPDActions) actions).sendCommand(command, parameter); } - public static void sendCommand(@Nullable ThingActions actions, @Nullable String command) { - if (actions instanceof MPDActions) { - ((MPDActions) actions).sendCommand(command); - } else { - throw new IllegalArgumentException("Actions is not an instance of MPDActions"); - } + public static void sendCommand(ThingActions actions, @Nullable String command) { + ((MPDActions) actions).sendCommand(command); } } diff --git a/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/internal/action/MQTTActions.java b/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/internal/action/MQTTActions.java index 75b748c66..cd4928d08 100644 --- a/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/internal/action/MQTTActions.java +++ b/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/internal/action/MQTTActions.java @@ -85,16 +85,12 @@ public class MQTTActions implements ThingActions { }); } - public static void publishMQTT(@Nullable ThingActions actions, @Nullable String topic, @Nullable String value) { + public static void publishMQTT(ThingActions actions, @Nullable String topic, @Nullable String value) { publishMQTT(actions, topic, value, null); } - public static void publishMQTT(@Nullable ThingActions actions, @Nullable String topic, @Nullable String value, + public static void publishMQTT(ThingActions actions, @Nullable String topic, @Nullable String value, @Nullable Boolean retain) { - if (actions instanceof MQTTActions) { - ((MQTTActions) actions).publishMQTT(topic, value, retain); - } else { - throw new IllegalArgumentException("Actions is not an instance of MQTTActions"); - } + ((MQTTActions) actions).publishMQTT(topic, value, retain); } } 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 a28837f02..409065a1f 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 @@ -57,11 +57,7 @@ public class NetworkActions implements ThingActions { } } - public static void sendWakeOnLanPacket(@Nullable ThingActions actions) { - if (actions instanceof NetworkActions) { - ((NetworkActions) actions).sendWakeOnLanPacket(); - } else { - throw new IllegalArgumentException("Actions is not an instance of NetworkActions"); - } + public static void sendWakeOnLanPacket(ThingActions actions) { + ((NetworkActions) actions).sendWakeOnLanPacket(); } } 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 59716555b..baeeb8c1f 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 @@ -48,12 +48,8 @@ public class NuvoThingActions implements ThingActions { } /** Static alias to support the old DSL rules engine and make the action available there. */ - 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"); - } + public static void sendNuvoCommand(ThingActions actions, String rawCommand) { + ((NuvoThingActions) actions).sendNuvoCommand(rawCommand); } @Override 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 9c84aa7e6..780078e37 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 @@ -48,13 +48,8 @@ public class OnkyoThingActions implements ThingActions { 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"); - } + public static void sendRawCommand(ThingActions actions, @Nullable String command, @Nullable String value) { + ((OnkyoThingActions) actions).sendRawCommand(command, value); } @Override 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 103828e37..db18f126c 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 @@ -63,13 +63,9 @@ public class PushbulletActions implements ThingActions { return localHandler.sendPush(recipient, title, message, "note"); } - public static boolean sendPushbulletNote(@Nullable ThingActions actions, @Nullable String recipient, - @Nullable String title, @Nullable String message) { - if (actions instanceof PushbulletActions) { - return ((PushbulletActions) actions).sendPushbulletNote(recipient, title, message); - } else { - throw new IllegalArgumentException("Actions is not an instance of PushbulletActions"); - } + public static boolean sendPushbulletNote(ThingActions actions, @Nullable String recipient, @Nullable String title, + @Nullable String message) { + return ((PushbulletActions) actions).sendPushbulletNote(recipient, title, message); } @RuleAction(label = "@text/actionSendPushbulletNoteLabel", description = "@text/actionSendPushbulletNoteDesc") @@ -87,12 +83,8 @@ public class PushbulletActions implements ThingActions { return localHandler.sendPush(recipient, message, "note"); } - public static boolean sendPushbulletNote(@Nullable ThingActions actions, @Nullable String recipient, + public static boolean sendPushbulletNote(ThingActions actions, @Nullable String recipient, @Nullable String message) { - if (actions instanceof PushbulletActions) { - return ((PushbulletActions) actions).sendPushbulletNote(recipient, message); - } else { - throw new IllegalArgumentException("Actions is not an instance of PushbulletActions"); - } + return ((PushbulletActions) actions).sendPushbulletNote(recipient, message); } } diff --git a/bundles/org.openhab.binding.pushbullet/src/main/resources/OH-INF/i18n/pushbullet_en.properties b/bundles/org.openhab.binding.pushbullet/src/main/resources/OH-INF/i18n/pushbullet_en.properties index df79c02a7..67da019db 100644 --- a/bundles/org.openhab.binding.pushbullet/src/main/resources/OH-INF/i18n/pushbullet_en.properties +++ b/bundles/org.openhab.binding.pushbullet/src/main/resources/OH-INF/i18n/pushbullet_en.properties @@ -3,7 +3,7 @@ binding.pushbullet.name = Pushbullet Binding binding.pushbullet.description = The Pushbullet binding allows you to send messages to other users of the Pushbullet service. # action -actionSendPushbulletNoteLabel = publish an Pushbullet message +actionSendPushbulletNoteLabel = publish a Pushbullet message actionSendPushbulletNoteDesc = Publishes a Title to the given Pushbullet Recipient. actionSendPushbulletNoteInputRecipientLabel = Pushbullet Recipient 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 997a71b27..abf37db70 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 @@ -50,12 +50,8 @@ public class RadioThermostatThingActions implements ThingActions { } /** 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) { - if (actions instanceof RadioThermostatThingActions) { - ((RadioThermostatThingActions) actions).sendRawCommand(rawCommand); - } else { - throw new IllegalArgumentException("Actions is not an instance of RadioThermostatThingActions"); - } + public static void sendRawCommand(ThingActions actions, @Nullable String rawCommand) { + ((RadioThermostatThingActions) actions).sendRawCommand(rawCommand); } @Override diff --git a/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/action/SatelEventLogActions.java b/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/action/SatelEventLogActions.java index a2f49e1a0..f3ea9699e 100644 --- a/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/action/SatelEventLogActions.java +++ b/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/action/SatelEventLogActions.java @@ -71,11 +71,7 @@ public class SatelEventLogActions implements ThingActions { return result; } - public static Map readEvent(@Nullable ThingActions actions, @Nullable Number index) { - if (actions instanceof SatelEventLogActions) { - return ((SatelEventLogActions) actions).readEvent(index); - } else { - throw new IllegalArgumentException("Actions is not an instance of SatelEventLogActions"); - } + public static Map readEvent(ThingActions actions, @Nullable Number index) { + return ((SatelEventLogActions) actions).readEvent(index); } } diff --git a/bundles/org.openhab.binding.satel/src/main/resources/OH-INF/i18n/satel.properties b/bundles/org.openhab.binding.satel/src/main/resources/OH-INF/i18n/satel.properties index 7b4b8644d..619fdeea8 100644 --- a/bundles/org.openhab.binding.satel/src/main/resources/OH-INF/i18n/satel.properties +++ b/bundles/org.openhab.binding.satel/src/main/resources/OH-INF/i18n/satel.properties @@ -3,7 +3,7 @@ config-status.hostEmpty = Host name or IP of ETHM-1 must be provided. config-status.portEmpty = Serial port of INT-RS must be provided. # actions -actionReadEventLabel = Read event +actionReadEventLabel = read an event actionReadEventDesc = Reads a single record from the event log. actionInputIndexLabel = Event index actionInputIndexDesc = Index of the event to read diff --git a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/action/TelegramActions.java b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/action/TelegramActions.java index 42ca057f1..e155d6b52 100644 --- a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/action/TelegramActions.java +++ b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/action/TelegramActions.java @@ -393,105 +393,58 @@ public class TelegramActions implements ThingActions { // legacy delegate methods /* APIs without chatId parameter */ - public static boolean sendTelegram(@Nullable ThingActions actions, @Nullable String format, - @Nullable Object... 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 sendTelegram(ThingActions actions, @Nullable String format, @Nullable Object... args) { + return ((TelegramActions) actions).sendTelegram(format, args); } - public static boolean sendTelegramQuery(@Nullable ThingActions actions, @Nullable String message, - @Nullable String replyId, @Nullable String... 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 sendTelegramQuery(ThingActions actions, @Nullable String message, @Nullable String replyId, + @Nullable String... buttons) { + return ((TelegramActions) actions).sendTelegramQuery(message, replyId, buttons); } - public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable String photoURL, - @Nullable String caption) { - 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(ThingActions actions, @Nullable String photoURL, @Nullable String caption) { + return ((TelegramActions) actions).sendTelegramPhoto(photoURL, caption, null, null); } - public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable String photoURL, - @Nullable String caption, @Nullable String username, @Nullable String 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 sendTelegramPhoto(ThingActions actions, @Nullable String photoURL, @Nullable String caption, + @Nullable String username, @Nullable String password) { + return ((TelegramActions) actions).sendTelegramPhoto(photoURL, caption, username, password); } - public static boolean sendTelegramAnswer(@Nullable ThingActions actions, @Nullable String replyId, - @Nullable String message) { - if (actions instanceof TelegramActions) { - return ((TelegramActions) actions).sendTelegramAnswer(replyId, message); - } else { - throw new IllegalArgumentException("Actions is not an instance of TelegramActions"); - } + public static boolean sendTelegramAnswer(ThingActions actions, @Nullable String replyId, @Nullable String message) { + return ((TelegramActions) actions).sendTelegramAnswer(replyId, message); } /* APIs with chatId parameter */ - public static boolean sendTelegram(@Nullable ThingActions actions, @Nullable Long chatId, @Nullable String format, + public static boolean sendTelegram(ThingActions actions, @Nullable Long chatId, @Nullable String format, @Nullable Object... args) { - if (actions instanceof TelegramActions) { - return ((TelegramActions) actions).sendTelegram(chatId, format, args); - } else { - throw new IllegalArgumentException("Actions is not an instance of TelegramActions"); - } + return ((TelegramActions) actions).sendTelegram(chatId, format, args); } - public static boolean sendTelegramQuery(@Nullable ThingActions actions, @Nullable Long chatId, - @Nullable String message, @Nullable String replyId, @Nullable String... 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 sendTelegramQuery(ThingActions actions, @Nullable Long chatId, @Nullable String message, + @Nullable String replyId, @Nullable String... buttons) { + return ((TelegramActions) actions).sendTelegramQuery(chatId, message, replyId, buttons); } - public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable Long chatId, - @Nullable String photoURL, @Nullable String caption) { - 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(ThingActions actions, @Nullable Long chatId, @Nullable String photoURL, + @Nullable String caption) { + return ((TelegramActions) actions).sendTelegramPhoto(chatId, photoURL, caption, null, null); } - public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable Long chatId, - @Nullable String photoURL, @Nullable String caption, @Nullable String username, @Nullable String 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 sendTelegramPhoto(ThingActions actions, @Nullable Long chatId, @Nullable String photoURL, + @Nullable String caption, @Nullable String username, @Nullable String password) { + return ((TelegramActions) actions).sendTelegramPhoto(chatId, photoURL, caption, username, password); } - public static boolean sendTelegramAnswer(@Nullable ThingActions actions, @Nullable Long chatId, - @Nullable String replyId, @Nullable String 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(ThingActions actions, @Nullable Long chatId, @Nullable String replyId, + @Nullable String message) { + return ((TelegramActions) actions).sendTelegramAnswer(chatId, replyId, message); } - public static boolean sendTelegramAnswer(@Nullable ThingActions actions, @Nullable String chatId, - @Nullable String replyId, @Nullable String message) { - if (actions instanceof TelegramActions) { - return ((TelegramActions) actions).sendTelegramAnswer(Long.valueOf(chatId), replyId, message); - } else { - throw new IllegalArgumentException("Actions is not an instance of TelegramActions"); - } + public static boolean sendTelegramAnswer(ThingActions actions, @Nullable String chatId, @Nullable String replyId, + @Nullable String message) { + return ((TelegramActions) actions).sendTelegramAnswer(Long.valueOf(chatId), replyId, message); } @Override diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java index 7edf1c6e4..07d255f1b 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory; * * @author Pavel Gololobov - Initial contribution */ -@ThingActionsScope(name = "xmpp") +@ThingActionsScope(name = "xmppclient") @NonNullByDefault public class XMPPActions implements ThingActions { private static final Logger logger = LoggerFactory.getLogger(XMPPActions.class); @@ -66,11 +66,7 @@ public class XMPPActions implements ThingActions { connection.sendMessage(to, text); } - public static void publishXMPP(@Nullable ThingActions actions, @Nullable String to, @Nullable String text) { - if (actions instanceof XMPPActions) { - ((XMPPActions) actions).publishXMPP(to, text); - } else { - throw new IllegalArgumentException("Actions is not an instance of XMPPActions"); - } + public static void publishXMPP(ThingActions actions, @Nullable String to, @Nullable String text) { + ((XMPPActions) actions).publishXMPP(to, text); } } diff --git a/bundles/org.openhab.binding.yioremote/src/main/java/org/openhab/binding/yioremote/internal/YIOremoteDockActions.java b/bundles/org.openhab.binding.yioremote/src/main/java/org/openhab/binding/yioremote/internal/YIOremoteDockActions.java index 5a8277bf8..f8b81a074 100644 --- a/bundles/org.openhab.binding.yioremote/src/main/java/org/openhab/binding/yioremote/internal/YIOremoteDockActions.java +++ b/bundles/org.openhab.binding.yioremote/src/main/java/org/openhab/binding/yioremote/internal/YIOremoteDockActions.java @@ -50,11 +50,7 @@ public class YIOremoteDockActions implements ThingActions { } } - public static void sendIRCode(@Nullable ThingActions actions, @Nullable String irCode) { - if (actions instanceof YIOremoteDockActions) { - ((YIOremoteDockActions) actions).sendIRCode(irCode); - } else { - throw new IllegalArgumentException("Instance is not an YIOremoteDockActions class."); - } + public static void sendIRCode(ThingActions actions, @Nullable String irCode) { + ((YIOremoteDockActions) actions).sendIRCode(irCode); } } diff --git a/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/internal/action/ZmActions.java b/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/internal/action/ZmActions.java index 8ca8809b0..3a2bc581b 100644 --- a/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/internal/action/ZmActions.java +++ b/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/internal/action/ZmActions.java @@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory; * * @author Mark Hilbush - Initial contribution */ -@ThingActionsScope(name = "zm") +@ThingActionsScope(name = "zoneminder") @NonNullByDefault public class ZmActions implements ThingActions { private final Logger logger = LoggerFactory.getLogger(ZmActions.class); @@ -63,12 +63,8 @@ public class ZmActions implements ThingActions { localHandler.actionTriggerAlarm(duration); } - public static void triggerAlarm(@Nullable ThingActions actions, @Nullable Number alarmDuration) { - if (actions instanceof ZmActions) { - ((ZmActions) actions).triggerAlarm(alarmDuration); - } else { - throw new IllegalArgumentException("Actions is not an instance of ZmActions"); - } + public static void triggerAlarm(ThingActions actions, @Nullable Number alarmDuration) { + ((ZmActions) actions).triggerAlarm(alarmDuration); } /** @@ -86,12 +82,8 @@ public class ZmActions implements ThingActions { localHandler.actionTriggerAlarm(); } - public static void triggerAlarm(@Nullable ThingActions actions) { - if (actions instanceof ZmActions) { - ((ZmActions) actions).triggerAlarm(); - } else { - throw new IllegalArgumentException("Actions is not an instance of ZmActions"); - } + public static void triggerAlarm(ThingActions actions) { + ((ZmActions) actions).triggerAlarm(); } /** @@ -108,11 +100,7 @@ public class ZmActions implements ThingActions { localHandler.actionCancelAlarm(); } - public static void cancelAlarm(@Nullable ThingActions actions) { - if (actions instanceof ZmActions) { - ((ZmActions) actions).cancelAlarm(); - } else { - throw new IllegalArgumentException("Actions is not an instance of ZmActions"); - } + public static void cancelAlarm(ThingActions actions) { + ((ZmActions) actions).cancelAlarm(); } }