Rework ThingActions (#8755)

* Remove duplication by making use of default Java generated exceptions
* Make ThingActions labels/descriptions more consistent

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2020-10-15 10:53:53 +02:00 committed by GitHub
parent aef1d10f40
commit 978e122e00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 305 additions and 785 deletions

View File

@ -67,11 +67,7 @@ public class BridgeActions implements ThingActions {
} }
// Static method for Rules DSL backward compatibility // Static method for Rules DSL backward compatibility
public static void reboot(@Nullable ThingActions actions) { public static void reboot(ThingActions actions) {
if (actions instanceof BridgeActions) { ((BridgeActions) actions).reboot();
((BridgeActions) actions).reboot();
} else {
throw new IllegalArgumentException("Actions is not an instance of BridgeActions");
}
} }
} }

View File

@ -112,34 +112,20 @@ public class AstroActions implements ThingActions {
return null; return null;
} }
public static @Nullable QuantityType<Angle> getElevation(@Nullable ThingActions actions, public static @Nullable QuantityType<Angle> getElevation(ThingActions actions, @Nullable ZonedDateTime date) {
@Nullable ZonedDateTime date) { return ((AstroActions) actions).getElevation(date);
if (actions instanceof AstroActions) {
return ((AstroActions) actions).getElevation(date);
} else {
throw new IllegalArgumentException("Actions is not an instance of AstroActions");
}
} }
public static @Nullable QuantityType<Angle> getAzimuth(@Nullable ThingActions actions, public static @Nullable QuantityType<Angle> getAzimuth(ThingActions actions, @Nullable ZonedDateTime date) {
@Nullable ZonedDateTime date) { return ((AstroActions) actions).getAzimuth(date);
if (actions instanceof AstroActions) {
return ((AstroActions) actions).getAzimuth(date);
} else {
throw new IllegalArgumentException("Actions is not an instance of AstroActions");
}
} }
public static @Nullable ZonedDateTime getEventTime(@Nullable ThingActions actions, @Nullable String phaseName, public static @Nullable ZonedDateTime getEventTime(ThingActions actions, @Nullable String phaseName,
@Nullable ZonedDateTime date, @Nullable String moment) { @Nullable ZonedDateTime date, @Nullable String moment) {
if (actions instanceof AstroActions) { if (phaseName != null) {
if (phaseName != null) { return ((AstroActions) actions).getEventTime(phaseName, date, moment);
return ((AstroActions) actions).getEventTime(phaseName, date, moment);
} else {
throw new IllegalArgumentException("phaseName can not be null");
}
} else { } else {
throw new IllegalArgumentException("Actions is not an instance of AstroActions"); throw new IllegalArgumentException("phaseName can not be null");
} }
} }
} }

View File

@ -54,12 +54,8 @@ public class AutomowerActions implements ThingActions {
} }
} }
public static void start(@Nullable ThingActions actions, int durationMin) { public static void start(ThingActions actions, int durationMin) {
if (actions instanceof AutomowerActions) { ((AutomowerActions) actions).start(durationMin);
((AutomowerActions) actions).start(durationMin);
} else {
throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
}
} }
@RuleAction(label = "@text/action-pause-label", description = "@text/action-pause-desc") @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) { public static void pause(ThingActions actions) {
if (actions instanceof AutomowerActions) { ((AutomowerActions) actions).pause();
((AutomowerActions) actions).pause();
} else {
throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
}
} }
@RuleAction(label = "@text/action-parkuntilnextschedule-label", description = "@text/action-parkuntilnextschedule-desc") @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) { public static void parkUntilNextSchedule(ThingActions actions) {
if (actions instanceof AutomowerActions) { ((AutomowerActions) actions).parkUntilNextSchedule();
((AutomowerActions) actions).parkUntilNextSchedule();
} else {
throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
}
} }
@RuleAction(label = "@text/action-parkuntilfurthernotice-label", description = "@text/action-parkuntilfurthernotice-desc") @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) { public static void parkUntilFurtherNotice(ThingActions actions) {
if (actions instanceof AutomowerActions) { ((AutomowerActions) actions).parkUntilFurtherNotice();
((AutomowerActions) actions).parkUntilFurtherNotice();
} else {
throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
}
} }
@RuleAction(label = "@text/action-park-label", description = "@text/action-park-desc") @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) { public static void park(ThingActions actions, int durationMin) {
if (actions instanceof AutomowerActions) { ((AutomowerActions) actions).park(durationMin);
((AutomowerActions) actions).park(durationMin);
} else {
throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
}
} }
@RuleAction(label = "@text/action-resumeschedule-label", description = "@text/action-resumeschedule-desc") @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) { public static void resumeSchedule(ThingActions actions) {
if (actions instanceof AutomowerActions) { ((AutomowerActions) actions).resumeSchedule();
((AutomowerActions) actions).resumeSchedule();
} else {
throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
}
} }
} }

View File

@ -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 comm-error-mower-not-connected-to-cloud = Automower not connected to the cloud
action-start-label = Start action-start-label = start the automower
action-start-desc = Starts the automower for a defined amount of time, overriding its schedule action-start-desc = Starts the automower for a defined amount of time, overriding its schedule.
action-pause-label = Pause action-pause-label = pause the automower
action-pause-desc = Pauses the automower wherever it currently is action-pause-desc = Pauses the automower wherever it currently is.
action-parkuntilnextschedule-label = Park until next schedule action-parkuntilnextschedule-label = park until the next schedule
action-parkuntilnextschedule-desc = Parks the automower until the next schedule action-parkuntilnextschedule-desc = Parks the automower until the next schedule.
action-parkuntilfurthernotice-label = Park until further notice action-parkuntilfurthernotice-label = park until further notice
action-parkuntilfurthernotice-desc = Parks the automower until the schedule is resumed action-parkuntilfurthernotice-desc = Parks the automower until the schedule is resumed.
action-park-label = Park action-park-label = park the automower
action-park-desc = Parks the automower for a defined amount of time, overriding its schedule action-park-desc = Parks the automower for a defined amount of time, overriding its schedule.
action-resumeschedule-label = Resume schedule action-resumeschedule-label = resume the schedule
action-resumeschedule-desc = Resumes the schedule for the automower action-resumeschedule-desc = Resumes the schedule for the automower.
action-input-duration-label = Duration action-input-duration-label = Duration
action-input-duration-desc = The duration of the automower command in minutes action-input-duration-desc = The duration of the automower command in minutes

View File

@ -55,12 +55,8 @@ public class AVMFritzHeatingActions implements ThingActions {
actionsHandler.setBoostMode(duration.longValue()); actionsHandler.setBoostMode(duration.longValue());
} }
public static void setBoostMode(@Nullable ThingActions actions, @Nullable Long duration) { public static void setBoostMode(ThingActions actions, @Nullable Long duration) {
if (actions instanceof AVMFritzHeatingActions) { ((AVMFritzHeatingActions) actions).setBoostMode(duration);
((AVMFritzHeatingActions) actions).setBoostMode(duration);
} else {
throw new IllegalArgumentException("Actions is not an instance of AVMFritzHeatingActions");
}
} }
@RuleAction(label = "@text/setWindowOpenModeActionLabel", description = "@text/setWindowOpenModeActionDescription") @RuleAction(label = "@text/setWindowOpenModeActionLabel", description = "@text/setWindowOpenModeActionDescription")
@ -76,11 +72,7 @@ public class AVMFritzHeatingActions implements ThingActions {
actionsHandler.setWindowOpenMode(duration.longValue()); actionsHandler.setWindowOpenMode(duration.longValue());
} }
public static void setWindowOpenMode(@Nullable ThingActions actions, @Nullable Long duration) { public static void setWindowOpenMode(ThingActions actions, @Nullable Long duration) {
if (actions instanceof AVMFritzHeatingActions) { ((AVMFritzHeatingActions) actions).setWindowOpenMode(duration);
((AVMFritzHeatingActions) actions).setWindowOpenMode(duration);
} else {
throw new IllegalArgumentException("Actions is not an instance of AVMFritzHeatingActions");
}
} }
} }

View File

@ -1,10 +1,10 @@
# thing actions # thing actions
setBoostModeModeActionLabel = Set Boost Mode setBoostModeModeActionLabel = set the Boost mode
setBoostModeActionDescription = Activates the Boost mode of the heating thermostat. setBoostModeActionDescription = Activates the Boost mode of the heating thermostat.
setBoostModeDurationInputLabel = Duration setBoostModeDurationInputLabel = Duration
setBoostModeDurationInputDescription = Duration in seconds, min. 1, max. 86400, 0 for deactivation. 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. setWindowOpenModeActionDescription = Activates the Window Open mode of the heating thermostat.
setWindowOpenModeDurationInputLabel = Duration setWindowOpenModeDurationInputLabel = Duration
setWindowOpenModeDurationInputDescription = Duration in seconds, min. 1, max. 86400, 0 for deactivation. setWindowOpenModeDurationInputDescription = Duration in seconds, min. 1, max. 86400, 0 for deactivation.

View File

@ -52,13 +52,8 @@ public class AVMFritzHeatingActionsTest {
} }
@Test @Test
public void testSetBoostModeThingActionsIsNull() { public void testSetBoostModeThingActionsIsNotAVMFritzHeatingActions() {
assertThrows(IllegalArgumentException.class, () -> AVMFritzHeatingActions.setBoostMode(null, Long.valueOf(5L))); assertThrows(ClassCastException.class,
}
@Test
public void testSetBoostModeThingActionsIsNotPushoverThingActions() {
assertThrows(IllegalArgumentException.class,
() -> AVMFritzHeatingActions.setBoostMode(thingActionsStub, Long.valueOf(5L))); () -> AVMFritzHeatingActions.setBoostMode(thingActionsStub, Long.valueOf(5L)));
} }
@ -81,14 +76,8 @@ public class AVMFritzHeatingActionsTest {
} }
@Test @Test
public void testSetWindowOpenModeThingActionsIsNull() { public void testSetWindowOpenModeThingActionsIsNotAVMFritzHeatingActions() {
assertThrows(IllegalArgumentException.class, assertThrows(ClassCastException.class,
() -> AVMFritzHeatingActions.setWindowOpenMode(null, Long.valueOf(5L)));
}
@Test
public void testSetWindowOpenModeThingActionsIsNotPushoverThingActions() {
assertThrows(IllegalArgumentException.class,
() -> AVMFritzHeatingActions.setWindowOpenMode(thingActionsStub, Long.valueOf(5L))); () -> AVMFritzHeatingActions.setWindowOpenMode(thingActionsStub, Long.valueOf(5L)));
} }

View File

@ -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) { @Nullable Boolean resumeAfter) {
if (actions instanceof DmxActions) { ((DmxActions) actions).sendFade(channels, fade, resumeAfter);
((DmxActions) actions).sendFade(channels, fade, resumeAfter);
} else {
throw new IllegalArgumentException("Actions is not an instance of DmxActions");
}
} }
@Override @Override

View File

@ -61,12 +61,8 @@ public class DoorbirdActions implements ThingActions {
} }
} }
public static void restart(@Nullable ThingActions actions) { public static void restart(ThingActions actions) {
if (actions instanceof DoorbirdActions) { ((DoorbirdActions) actions).restart();
((DoorbirdActions) actions).restart();
} else {
throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
}
} }
@RuleAction(label = "hangup a SIP call", description = "Hangup SIP call.") @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) { public static void sipHangup(ThingActions actions) {
if (actions instanceof DoorbirdActions) { ((DoorbirdActions) actions).sipHangup();
((DoorbirdActions) actions).sipHangup();
} else {
throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
}
} }
@RuleAction(label = "get the ring time limit", description = "Get the value of RING_TIME_LIMIT.") @RuleAction(label = "get the ring time limit", description = "Get the value of RING_TIME_LIMIT.")
@ -98,12 +90,8 @@ public class DoorbirdActions implements ThingActions {
} }
} }
public static String getRingTimeLimit(@Nullable ThingActions actions) { public static String getRingTimeLimit(ThingActions actions) {
if (actions instanceof DoorbirdActions) { return ((DoorbirdActions) actions).getRingTimeLimit();
return ((DoorbirdActions) actions).getRingTimeLimit();
} else {
throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
}
} }
@RuleAction(label = "get the call time limit", description = "Get the value of CALL_TIME_LIMIT.") @RuleAction(label = "get the call time limit", description = "Get the value of CALL_TIME_LIMIT.")
@ -117,12 +105,8 @@ public class DoorbirdActions implements ThingActions {
} }
} }
public static String getCallTimeLimit(@Nullable ThingActions actions) { public static String getCallTimeLimit(ThingActions actions) {
if (actions instanceof DoorbirdActions) { return ((DoorbirdActions) actions).getCallTimeLimit();
return ((DoorbirdActions) actions).getCallTimeLimit();
} else {
throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
}
} }
@RuleAction(label = "get the last error code", description = "Get the value of LASTERRORCODE.") @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) { public static String getLastErrorCode(ThingActions actions) {
if (actions instanceof DoorbirdActions) { return ((DoorbirdActions) actions).getLastErrorCode();
return ((DoorbirdActions) actions).getLastErrorCode();
} else {
throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
}
} }
@RuleAction(label = "get the last error text", description = "Get the value of LASTERRORTEXT.") @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) { public static String getLastErrorText(ThingActions actions) {
if (actions instanceof DoorbirdActions) { return ((DoorbirdActions) actions).getLastErrorText();
return ((DoorbirdActions) actions).getLastErrorText();
} else {
throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
}
} }
} }

View File

@ -102,13 +102,9 @@ public class EcobeeActions implements ThingActions {
return localHandler.actionPerformFunction(function); 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) { @Nullable Boolean remindMeLater) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).acknowledge(ackRef, ackType, remindMeLater);
return ((EcobeeActions) actions).acknowledge(ackRef, ackType, remindMeLater);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -137,15 +133,11 @@ public class EcobeeActions implements ThingActions {
return localHandler.actionPerformFunction(function); return localHandler.actionPerformFunction(function);
} }
public static boolean controlPlug(@Nullable ThingActions actions, @Nullable String plugName, public static boolean controlPlug(ThingActions actions, @Nullable String plugName, @Nullable String plugState,
@Nullable String plugState, @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType,
@Nullable String holdType, @Nullable Number holdHours) { @Nullable Number holdHours) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).controlPlug(plugName, plugState, startDateTime, endDateTime, holdType,
return ((EcobeeActions) actions).controlPlug(plugName, plugState, startDateTime, endDateTime, holdType, holdHours);
holdHours);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -175,16 +167,12 @@ public class EcobeeActions implements ThingActions {
return localHandler.actionPerformFunction(function); 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<Temperature> coolHoldTemp, @Nullable QuantityType<Temperature> heatHoldTemp, @Nullable QuantityType<Temperature> coolHoldTemp, @Nullable QuantityType<Temperature> heatHoldTemp,
@Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String fan, @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String fan,
@Nullable Number fanMinOnTime) { @Nullable Number fanMinOnTime) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).createVacation(name, coolHoldTemp, heatHoldTemp, startDateTime, endDateTime,
return ((EcobeeActions) actions).createVacation(name, coolHoldTemp, heatHoldTemp, startDateTime, fan, fanMinOnTime);
endDateTime, fan, fanMinOnTime);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -206,12 +194,8 @@ public class EcobeeActions implements ThingActions {
return localHandler.actionPerformFunction(function); return localHandler.actionPerformFunction(function);
} }
public static boolean deleteVacation(@Nullable ThingActions actions, @Nullable String name) { public static boolean deleteVacation(ThingActions actions, @Nullable String name) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).deleteVacation(name);
return ((EcobeeActions) actions).deleteVacation(name);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -232,12 +216,8 @@ public class EcobeeActions implements ThingActions {
return localHandler.actionPerformFunction(function); return localHandler.actionPerformFunction(function);
} }
public static boolean resetPreferences(@Nullable ThingActions actions) { public static boolean resetPreferences(ThingActions actions) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).resetPreferences();
return ((EcobeeActions) actions).resetPreferences();
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -259,12 +239,8 @@ public class EcobeeActions implements ThingActions {
return localHandler.actionPerformFunction(function); return localHandler.actionPerformFunction(function);
} }
public static boolean resumeProgram(@Nullable ThingActions actions, @Nullable Boolean resumeAll) { public static boolean resumeProgram(ThingActions actions, @Nullable Boolean resumeAll) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).resumeProgram(resumeAll);
return ((EcobeeActions) actions).resumeProgram(resumeAll);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -286,12 +262,8 @@ public class EcobeeActions implements ThingActions {
return localHandler.actionPerformFunction(function); return localHandler.actionPerformFunction(function);
} }
public static boolean sendMessage(@Nullable ThingActions actions, @Nullable String text) { public static boolean sendMessage(ThingActions actions, @Nullable String text) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).sendMessage(text);
return ((EcobeeActions) actions).sendMessage(text);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -312,13 +284,9 @@ public class EcobeeActions implements ThingActions {
return setHold(params, null, null, null, null); return setHold(params, null, null, null, null);
} }
public static boolean setHold(@Nullable ThingActions actions, @Nullable QuantityType<Temperature> coolHoldTemp, public static boolean setHold(ThingActions actions, @Nullable QuantityType<Temperature> coolHoldTemp,
@Nullable QuantityType<Temperature> heatHoldTemp) { @Nullable QuantityType<Temperature> heatHoldTemp) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp);
return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -343,13 +311,9 @@ public class EcobeeActions implements ThingActions {
return setHold(params, null, null, null, null); return setHold(params, null, null, null, null);
} }
public static boolean setHold(@Nullable ThingActions actions, @Nullable QuantityType<Temperature> coolHoldTemp, public static boolean setHold(ThingActions actions, @Nullable QuantityType<Temperature> coolHoldTemp,
@Nullable QuantityType<Temperature> heatHoldTemp, @Nullable Number holdHours) { @Nullable QuantityType<Temperature> heatHoldTemp, @Nullable Number holdHours) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp, holdHours);
return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp, holdHours);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -371,12 +335,8 @@ public class EcobeeActions implements ThingActions {
return setHold(params, null, null, null, null); return setHold(params, null, null, null, null);
} }
public static boolean setHold(@Nullable ThingActions actions, @Nullable String holdClimateRef) { public static boolean setHold(ThingActions actions, @Nullable String holdClimateRef) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).setHold(holdClimateRef);
return ((EcobeeActions) actions).setHold(holdClimateRef);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -404,13 +364,8 @@ public class EcobeeActions implements ThingActions {
return setHold(params, null, null, null, null); return setHold(params, null, null, null, null);
} }
public static boolean setHold(@Nullable ThingActions actions, @Nullable String holdClimateRef, public static boolean setHold(ThingActions actions, @Nullable String holdClimateRef, @Nullable Number holdHours) {
@Nullable Number holdHours) { return ((EcobeeActions) actions).setHold(holdClimateRef, holdHours);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).setHold(holdClimateRef, holdHours);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -438,16 +393,12 @@ public class EcobeeActions implements ThingActions {
return setHold(params, holdType, holdHours, startDateTime, endDateTime); return setHold(params, holdType, holdHours, startDateTime, endDateTime);
} }
public static boolean setHold(@Nullable ThingActions actions, @Nullable QuantityType<Temperature> coolHoldTemp, public static boolean setHold(ThingActions actions, @Nullable QuantityType<Temperature> coolHoldTemp,
@Nullable QuantityType<Temperature> heatHoldTemp, @Nullable String holdClimateRef, @Nullable QuantityType<Temperature> heatHoldTemp, @Nullable String holdClimateRef,
@Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType, @Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType,
@Nullable Number holdHours) { @Nullable Number holdHours) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp, holdClimateRef, startDateTime, endDateTime,
return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp, holdClimateRef, startDateTime, holdType, holdHours);
endDateTime, holdType, holdHours);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -528,14 +479,9 @@ public class EcobeeActions implements ThingActions {
return localHandler.actionPerformFunction(function); return localHandler.actionPerformFunction(function);
} }
public static boolean setHold(@Nullable ThingActions actions, @Nullable Map<String, Object> params, public static boolean setHold(ThingActions actions, @Nullable Map<String, Object> params, @Nullable String holdType,
@Nullable String holdType, @Nullable Number holdHours, @Nullable Date startDateTime, @Nullable Number holdHours, @Nullable Date startDateTime, @Nullable Date endDateTime) {
@Nullable Date endDateTime) { return ((EcobeeActions) actions).setHold(params, holdType, holdHours, startDateTime, endDateTime);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).setHold(params, holdType, holdHours, startDateTime, endDateTime);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -564,14 +510,9 @@ public class EcobeeActions implements ThingActions {
return localHandler.actionPerformFunction(function); return localHandler.actionPerformFunction(function);
} }
public static boolean setOccupied(@Nullable ThingActions actions, @Nullable Boolean occupied, public static boolean setOccupied(ThingActions actions, @Nullable Boolean occupied, @Nullable Date startDateTime,
@Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType, @Nullable Date endDateTime, @Nullable String holdType, @Nullable Number holdHours) {
@Nullable Number holdHours) { return ((EcobeeActions) actions).setOccupied(occupied, startDateTime, endDateTime, holdType, holdHours);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).setOccupied(occupied, startDateTime, endDateTime, holdType, holdHours);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -595,13 +536,9 @@ public class EcobeeActions implements ThingActions {
return localHandler.actionPerformFunction(function); 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) { @Nullable String sensorId) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).updateSensor(name, deviceId, sensorId);
return ((EcobeeActions) actions).updateSensor(name, deviceId, sensorId);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -618,12 +555,8 @@ public class EcobeeActions implements ThingActions {
return localHandler.getAlerts(); return localHandler.getAlerts();
} }
public static @Nullable String getAlerts(@Nullable ThingActions actions) { public static @Nullable String getAlerts(ThingActions actions) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).getAlerts();
return ((EcobeeActions) actions).getAlerts();
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -640,12 +573,8 @@ public class EcobeeActions implements ThingActions {
return localHandler.getEvents(); return localHandler.getEvents();
} }
public static @Nullable String getEvents(@Nullable ThingActions actions) { public static @Nullable String getEvents(ThingActions actions) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).getEvents();
return ((EcobeeActions) actions).getEvents();
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
/** /**
@ -662,11 +591,7 @@ public class EcobeeActions implements ThingActions {
return localHandler.getClimates(); return localHandler.getClimates();
} }
public static @Nullable String getClimates(@Nullable ThingActions actions) { public static @Nullable String getClimates(ThingActions actions) {
if (actions instanceof EcobeeActions) { return ((EcobeeActions) actions).getClimates();
return ((EcobeeActions) actions).getClimates();
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
} }
} }

View File

@ -111,75 +111,39 @@ public class Enigma2Actions implements ThingActions {
} }
// delegation methods for "legacy" rule support // delegation methods for "legacy" rule support
public static void sendRcCommand(@Nullable ThingActions actions, String rcButton) { public static void sendRcCommand(ThingActions actions, String rcButton) {
if (actions instanceof Enigma2Actions) { ((Enigma2Actions) actions).sendRcCommand(rcButton);
((Enigma2Actions) actions).sendRcCommand(rcButton);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
} }
public static void sendInfo(@Nullable ThingActions actions, String info) { public static void sendInfo(ThingActions actions, String info) {
if (actions instanceof Enigma2Actions) { ((Enigma2Actions) actions).sendInfo(info);
((Enigma2Actions) actions).sendInfo(info);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
} }
public static void sendInfo(@Nullable ThingActions actions, String info, int timeout) { public static void sendInfo(ThingActions actions, String info, int timeout) {
if (actions instanceof Enigma2Actions) { ((Enigma2Actions) actions).sendInfo(info, timeout);
((Enigma2Actions) actions).sendInfo(info, timeout);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
} }
public static void sendWarning(@Nullable ThingActions actions, String warning) { public static void sendWarning(ThingActions actions, String warning) {
if (actions instanceof Enigma2Actions) { ((Enigma2Actions) actions).sendWarning(warning);
((Enigma2Actions) actions).sendWarning(warning);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
} }
public static void sendWarning(@Nullable ThingActions actions, String warning, int timeout) { public static void sendWarning(ThingActions actions, String warning, int timeout) {
if (actions instanceof Enigma2Actions) { ((Enigma2Actions) actions).sendWarning(warning, timeout);
((Enigma2Actions) actions).sendWarning(warning, timeout);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
} }
public static void sendError(@Nullable ThingActions actions, String error) { public static void sendError(ThingActions actions, String error) {
if (actions instanceof Enigma2Actions) { ((Enigma2Actions) actions).sendError(error);
((Enigma2Actions) actions).sendError(error);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
} }
public static void sendError(@Nullable ThingActions actions, String error, int timeout) { public static void sendError(ThingActions actions, String error, int timeout) {
if (actions instanceof Enigma2Actions) { ((Enigma2Actions) actions).sendError(error, timeout);
((Enigma2Actions) actions).sendError(error, timeout);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
} }
public static void sendQuestion(@Nullable ThingActions actions, String text) { public static void sendQuestion(ThingActions actions, String text) {
if (actions instanceof Enigma2Actions) { ((Enigma2Actions) actions).sendQuestion(text);
((Enigma2Actions) actions).sendQuestion(text);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
} }
public static void sendQuestion(@Nullable ThingActions actions, String text, int timeout) { public static void sendQuestion(ThingActions actions, String text, int timeout) {
if (actions instanceof Enigma2Actions) { ((Enigma2Actions) actions).sendQuestion(text, timeout);
((Enigma2Actions) actions).sendQuestion(text, timeout);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
} }
} }

View File

@ -17,19 +17,19 @@ channel-type.enigma2.power.label = Power
channel-type.enigma2.power.description = Setting the power to on/off. channel-type.enigma2.power.description = Setting the power to on/off.
# actions # actions
action.enigma2.send-rc-button.label=sendRcCommand action.enigma2.send-rc-button.label=send a remote control command
action.enigma2.send-rc-button.description=Send an Remote Control Command action.enigma2.send-rc-button.description=Send a remote control command.
action-input.enigma2.rc-button.label=rcButton action-input.enigma2.rc-button.label=Button
action-input.enigma2.rc-button.description=The Remote Control Button action-input.enigma2.rc-button.description=The remote control button
action.enigma2.send-info.label=sendInfo 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-info.description=Send an info message to the TV screen.
action.enigma2.send-warning.label=sendWarning action.enigma2.send-warning.label=send a warning message
action.enigma2.send-warning.description=Send an warning message to the TV screen action.enigma2.send-warning.description=Send a warning message to the TV screen.
action.enigma2.send-error.label=sendError 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-error.description=Send an error message to the TV screen.
action.enigma2.send-question.label=sendQuestion action.enigma2.send-question.label=send a question message
action.enigma2.send-question.description=Send a question message to the TV screen action.enigma2.send-question.description=Send a question message to the TV screen.
action-input.enigma2.text.label=text action-input.enigma2.text.label=text
action-input.enigma2.text.description=The message text action-input.enigma2.text.description=The message text
action-input.enigma2.timeout.label=timeout action-input.enigma2.timeout.label=timeout

View File

@ -14,11 +14,9 @@ package org.openhab.binding.enigma2.internal.actions;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.openhab.binding.enigma2.internal.Enigma2BindingConstants; import org.openhab.binding.enigma2.internal.Enigma2BindingConstants;
@ -29,13 +27,10 @@ import org.openhab.binding.enigma2.internal.handler.Enigma2Handler;
* *
* @author Guido Dolfen - Initial contribution * @author Guido Dolfen - Initial contribution
*/ */
@SuppressWarnings("null")
@NonNullByDefault @NonNullByDefault
public class Enigma2ActionsTest { public class Enigma2ActionsTest {
@Nullable private @NonNullByDefault({}) Enigma2Actions enigma2Actions;
private Enigma2Actions enigma2Actions; private @NonNullByDefault({}) Enigma2Handler enigma2Handler;
@Nullable
private Enigma2Handler enigma2Handler;
public static final String SOME_TEXT = "some Text"; public static final String SOME_TEXT = "some Text";
@BeforeEach @BeforeEach
@ -110,11 +105,6 @@ public class Enigma2ActionsTest {
verify(enigma2Handler).sendRcCommand("KEY_1"); verify(enigma2Handler).sendRcCommand("KEY_1");
} }
@Test
public void testSendRcCommandStaticWithException() {
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendRcCommand(null, "KEY_1"));
}
@Test @Test
public void testSendInfoStatic() { public void testSendInfoStatic() {
Enigma2Actions.sendInfo(enigma2Actions, SOME_TEXT); Enigma2Actions.sendInfo(enigma2Actions, SOME_TEXT);
@ -127,11 +117,6 @@ public class Enigma2ActionsTest {
verify(enigma2Handler).sendInfo(10, SOME_TEXT); verify(enigma2Handler).sendInfo(10, SOME_TEXT);
} }
@Test
public void testSendInfoStaticWithException() {
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendInfo(null, SOME_TEXT));
}
@Test @Test
public void testSendErrorStatic() { public void testSendErrorStatic() {
Enigma2Actions.sendError(enigma2Actions, SOME_TEXT); Enigma2Actions.sendError(enigma2Actions, SOME_TEXT);
@ -144,11 +129,6 @@ public class Enigma2ActionsTest {
verify(enigma2Handler).sendError(10, SOME_TEXT); verify(enigma2Handler).sendError(10, SOME_TEXT);
} }
@Test
public void testSendErrorStaticWithException() {
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendError(null, SOME_TEXT));
}
@Test @Test
public void testSendWarningStatic() { public void testSendWarningStatic() {
Enigma2Actions.sendWarning(enigma2Actions, SOME_TEXT); Enigma2Actions.sendWarning(enigma2Actions, SOME_TEXT);
@ -161,11 +141,6 @@ public class Enigma2ActionsTest {
verify(enigma2Handler).sendWarning(10, SOME_TEXT); verify(enigma2Handler).sendWarning(10, SOME_TEXT);
} }
@Test
public void testSendWarningStaticWithException() {
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendWarning(null, SOME_TEXT));
}
@Test @Test
public void testSendQuestionStatic() { public void testSendQuestionStatic() {
Enigma2Actions.sendQuestion(enigma2Actions, SOME_TEXT); Enigma2Actions.sendQuestion(enigma2Actions, SOME_TEXT);
@ -177,9 +152,4 @@ public class Enigma2ActionsTest {
Enigma2Actions.sendQuestion(enigma2Actions, SOME_TEXT, 10); Enigma2Actions.sendQuestion(enigma2Actions, SOME_TEXT, 10);
verify(enigma2Handler).sendQuestion(10, SOME_TEXT); verify(enigma2Handler).sendQuestion(10, SOME_TEXT);
} }
@Test
public void testSendQuestionStaticWithException() {
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendQuestion(null, SOME_TEXT));
}
} }

View File

@ -75,19 +75,11 @@ public class Ipx800Actions implements ThingActions {
} }
} }
public static void resetCounter(@Nullable ThingActions actions, Integer counter) { public static void resetCounter(ThingActions actions, Integer counter) {
if (actions instanceof Ipx800Actions) { ((Ipx800Actions) actions).resetCounter(counter);
((Ipx800Actions) actions).resetCounter(counter);
} else {
throw new IllegalArgumentException("Actions is not an instance of Ipx800Actions");
}
} }
public static void reset(@Nullable ThingActions actions, @Nullable Integer placeholder) { public static void reset(ThingActions actions, @Nullable Integer placeholder) {
if (actions instanceof Ipx800Actions) { ((Ipx800Actions) actions).reset(placeholder);
((Ipx800Actions) actions).reset(placeholder);
} else {
throw new IllegalArgumentException("Actions is not an instance of Ipx800Actions");
}
} }
} }

View File

@ -62,7 +62,7 @@ public class HeosActions implements ThingActions {
return handler.getApiConnection(); 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( public void playInputFromPlayer(
@ActionInput(name = "source", label = "Source Player", description = "Player used for input") @Nullable Integer sourcePlayer, @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, @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, public static void playInputFromPlayer(ThingActions actions, @Nullable Integer sourcePlayer, @Nullable String input,
@Nullable String input, @Nullable Integer destinationPlayer) { @Nullable Integer destinationPlayer) {
if (actions instanceof HeosActions) { ((HeosActions) actions).playInputFromPlayer(sourcePlayer, input, destinationPlayer);
((HeosActions) actions).playInputFromPlayer(sourcePlayer, input, destinationPlayer);
} else {
throw new IllegalArgumentException("Actions is not an instance of HeosActions");
}
} }
} }

View File

@ -76,12 +76,8 @@ public class LightActions implements ThingActions {
logger.debug("send LightAction to {} with {}ms of fadeTime", channel, fadeTime); logger.debug("send LightAction to {} with {}ms of fadeTime", channel, fadeTime);
} }
public static void fadingLightCommand(@Nullable ThingActions actions, @Nullable String channel, public static void fadingLightCommand(ThingActions actions, @Nullable String channel, @Nullable Command command,
@Nullable Command command, @Nullable DecimalType fadeTime) { @Nullable DecimalType fadeTime) {
if (actions instanceof LightActions) { ((LightActions) actions).fadingLightCommand(channel, command, fadeTime);
((LightActions) actions).fadingLightCommand(channel, command, fadeTime);
} else {
throw new IllegalArgumentException("Actions is not an instance of LightActions");
}
} }
} }

View File

@ -45,7 +45,7 @@ public class IpCameraActions implements ThingActions {
return handler; 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( 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 = "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) { @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) { public static void recordMP4(ThingActions actions, @Nullable String filename, int secondsToRecord) {
if (actions instanceof IpCameraActions) { ((IpCameraActions) actions).recordMP4(filename, secondsToRecord);
((IpCameraActions) actions).recordMP4(filename, secondsToRecord);
} else {
throw new IllegalArgumentException("Instance is not a IpCamera class.");
}
} }
@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( 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 = "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) { @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) { public static void recordGIF(ThingActions actions, @Nullable String filename, int secondsToRecord) {
if (actions instanceof IpCameraActions) { ((IpCameraActions) actions).recordGIF(filename, secondsToRecord);
((IpCameraActions) actions).recordGIF(filename, secondsToRecord);
} else {
throw new IllegalArgumentException("Instance is not a IpCamera class.");
}
} }
} }

View File

@ -47,12 +47,8 @@ public class KaleidescapeThingActions implements ThingActions {
} }
/** Static alias to support the old DSL rules engine and make the action available there. */ /** 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 { public static void sendKCommand(ThingActions actions, String kCommand) throws IllegalArgumentException {
if (actions instanceof KaleidescapeThingActions) { ((KaleidescapeThingActions) actions).sendKCommand(kCommand);
((KaleidescapeThingActions) actions).sendKCommand(kCommand);
} else {
throw new IllegalArgumentException("Actions is not an instance of KaleidescapeThingActions");
}
} }
@Override @Override

View File

@ -169,40 +169,23 @@ public class LcnModuleActions implements ThingActions {
} }
/** Static alias to support the old DSL rules engine and make the action available there. */ /** 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, public static void hitKey(ThingActions actions, @Nullable String table, int key, @Nullable String action) {
@Nullable String action) { ((LcnModuleActions) actions).hitKey(table, key, action);
if (actions instanceof LcnModuleHandler) {
((LcnModuleActions) actions).hitKey(table, key, action);
} else {
throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions");
}
} }
/** Static alias to support the old DSL rules engine and make the action available there. */ /** 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) { public static void flickerOutput(ThingActions actions, int output, int depth, int ramp, int count) {
if (actions instanceof LcnModuleHandler) { ((LcnModuleActions) actions).flickerOutput(output, depth, ramp, count);
((LcnModuleActions) actions).flickerOutput(output, depth, ramp, count);
} else {
throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions");
}
} }
/** Static alias to support the old DSL rules engine and make the action available there. */ /** 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) { public static void sendDynamicText(ThingActions actions, int row, @Nullable String text) {
if (actions instanceof LcnModuleHandler) { ((LcnModuleActions) actions).sendDynamicText(row, text);
((LcnModuleActions) actions).sendDynamicText(row, text);
} else {
throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions");
}
} }
/** Static alias to support the old DSL rules engine and make the action available there. */ /** 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) { public static void startRelayTimer(ThingActions actions, int relaynumber, double duration) {
if (actions instanceof LcnModuleHandler) { ((LcnModuleActions) actions).startRelayTimer(relaynumber, duration);
((LcnModuleActions) actions).startRelayTimer(relaynumber, duration);
} else {
throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions");
}
} }
private LcnModuleHandler getHandler() throws LcnException { private LcnModuleHandler getHandler() throws LcnException {

View File

@ -281,83 +281,43 @@ public class LGWebOSActions implements ThingActions {
// delegation methods for "legacy" rule support // delegation methods for "legacy" rule support
public static void showToast(@Nullable ThingActions actions, String text) throws IOException { public static void showToast(ThingActions actions, String text) throws IOException {
if (actions instanceof LGWebOSActions) { ((LGWebOSActions) actions).showToast(text);
((LGWebOSActions) actions).showToast(text);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
} }
public static void showToast(@Nullable ThingActions actions, String icon, String text) throws IOException { public static void showToast(ThingActions actions, String icon, String text) throws IOException {
if (actions instanceof LGWebOSActions) { ((LGWebOSActions) actions).showToast(icon, text);
((LGWebOSActions) actions).showToast(icon, text);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
} }
public static void launchBrowser(@Nullable ThingActions actions, String url) { public static void launchBrowser(ThingActions actions, String url) {
if (actions instanceof LGWebOSActions) { ((LGWebOSActions) actions).launchBrowser(url);
((LGWebOSActions) actions).launchBrowser(url);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
} }
public static void launchApplication(@Nullable ThingActions actions, String appId) { public static void launchApplication(ThingActions actions, String appId) {
if (actions instanceof LGWebOSActions) { ((LGWebOSActions) actions).launchApplication(appId);
((LGWebOSActions) actions).launchApplication(appId);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
} }
public static void launchApplication(@Nullable ThingActions actions, String appId, String param) { public static void launchApplication(ThingActions actions, String appId, String param) {
if (actions instanceof LGWebOSActions) { ((LGWebOSActions) actions).launchApplication(appId, param);
((LGWebOSActions) actions).launchApplication(appId, param);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
} }
public static void sendText(@Nullable ThingActions actions, String text) { public static void sendText(ThingActions actions, String text) {
if (actions instanceof LGWebOSActions) { ((LGWebOSActions) actions).sendText(text);
((LGWebOSActions) actions).sendText(text);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
} }
public static void sendButton(@Nullable ThingActions actions, String button) { public static void sendButton(ThingActions actions, String button) {
if (actions instanceof LGWebOSActions) { ((LGWebOSActions) actions).sendButton(button);
((LGWebOSActions) actions).sendButton(button);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
} }
public static void increaseChannel(@Nullable ThingActions actions) { public static void increaseChannel(ThingActions actions) {
if (actions instanceof LGWebOSActions) { ((LGWebOSActions) actions).increaseChannel();
((LGWebOSActions) actions).increaseChannel();
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
} }
public static void decreaseChannel(@Nullable ThingActions actions) { public static void decreaseChannel(ThingActions actions) {
if (actions instanceof LGWebOSActions) { ((LGWebOSActions) actions).decreaseChannel();
((LGWebOSActions) actions).decreaseChannel();
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
} }
public static void sendRCButton(@Nullable ThingActions actions, String rcButton) { public static void sendRCButton(ThingActions actions, String rcButton) {
if (actions instanceof LGWebOSActions) { ((LGWebOSActions) actions).sendRCButton(rcButton);
((LGWebOSActions) actions).sendRCButton(rcButton);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
} }
} }

View File

@ -1,45 +1,45 @@
actionShowToastLabel=Show Toast actionShowToastLabel=show a toast message
actionShowToastDesc=Sends a toast message to a WebOS device with openHAB icon. actionShowToastDesc=Sends a toast message to a WebOS device with openHAB icon.
actionShowToastInputTextLabel=Text actionShowToastInputTextLabel=Text
actionShowToastInputTextDesc=The text to display 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. actionShowToastWithIconLabel=Sends a toast message to a WebOS device with custom icon.
actionShowToastInputIconLabel=Icon actionShowToastInputIconLabel=Icon
actionShowToastInputIconDesc=The URL to the icon to display 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. actionLaunchBrowserDesc=Opens the given URL in the TV's browser application.
actionLaunchBrowserInputUrlLabel=URL actionLaunchBrowserInputUrlLabel=URL
actionLaunchBrowserInputUrlDesc=The URL to open actionLaunchBrowserInputUrlDesc=The URL to open
actionLaunchApplicationLabel=Launch Application actionLaunchApplicationLabel=launch an application
actionLaunchApplicationDesc=Opens the application with given Application ID. actionLaunchApplicationDesc=Opens the application with given Application ID.
actionLaunchApplicationInputAppIDLabel=Application ID actionLaunchApplicationInputAppIDLabel=Application ID
actionLaunchApplicationInputAppIDDesc=The 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. actionLaunchApplicationWithParamsDesc=Opens the application with given Application ID and passes additional parameters.
actionLaunchApplicationInputParamsLabel=JSON Parameters actionLaunchApplicationInputParamsLabel=JSON Parameters
actionLaunchApplicationInputParamsDesc=The parameters to hand over to the application in JSON format 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. actionSendTextDesc=Sends a text input to a WebOS device.
actionSendTextInputTextLabel=Text actionSendTextInputTextLabel=Text
actionSendTextInputTextDesc=The text to input actionSendTextInputTextDesc=The text to input
actionSendButtonLabel=Send Button actionSendButtonLabel=send a button press
actionSendButtonDesc=Sends a button press event to a WebOS device. actionSendButtonDesc=Sends a button press event to a WebOS device.
actionSendButtonInputButtonLabel=Button actionSendButtonInputButtonLabel=Button
actionSendButtonInputButtonDesc=Can be one of UP, DOWN, LEFT, RIGHT, BACK, DELETE, ENTER, HOME, or OK 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. 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. 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. actionSendRCButtonDesc=Simulates pressing of a Remote Control Button.
actionSendRCButtonInputTextLabel=Remote Control button name actionSendRCButtonInputTextLabel=Remote Control button name
actionSendRCButtonInputTextDesc=The Remote Control button name to send to the WebOS device. actionSendRCButtonInputTextDesc=The Remote Control button name to send to the WebOS device.

View File

@ -98,12 +98,8 @@ public class DimmerActions implements ThingActions {
/** /**
* Static setLevel method for Rules DSL backward compatibility * 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) { @Nullable Double delayTime) {
if (actions instanceof DimmerActions) { ((DimmerActions) actions).setLevel(level, fadeTime, delayTime);
((DimmerActions) actions).setLevel(level, fadeTime, delayTime);
} else {
throw new IllegalArgumentException("Actions is not an instance of DimmerActions");
}
} }
} }

View File

@ -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) { @Nullable String text) {
return SendMailActions.sendMail(actions, recipient, subject, text, new ArrayList<>()); 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) { @Nullable String text, @Nullable String urlString) {
List<String> urlList = new ArrayList<>(); List<String> urlList = new ArrayList<>();
if (urlString != null) { if (urlString != null) {
@ -117,13 +117,9 @@ public class SendMailActions implements ThingActions {
return SendMailActions.sendMail(actions, recipient, subject, text, urlList); 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<String> urlStringList) { @Nullable String text, @Nullable List<String> urlStringList) {
if (actions instanceof SendMailActions) { return ((SendMailActions) actions).sendMail(recipient, subject, text, urlStringList);
return ((SendMailActions) actions).sendMail(recipient, subject, text, urlStringList);
} else {
throw new IllegalArgumentException("Actions is not an instance of SendMailActions");
}
} }
@RuleAction(label = "send a HTML mail", description = "Sends a HTML mail.") @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, public static boolean sendHtmlMail(ThingActions actions, @Nullable String recipient, @Nullable String subject,
@Nullable String subject, @Nullable String html) { @Nullable String html) {
return SendMailActions.sendHtmlMail(actions, recipient, subject, html, new ArrayList<>()); return SendMailActions.sendHtmlMail(actions, recipient, subject, html, new ArrayList<>());
} }
public static boolean sendHtmlMail(@Nullable ThingActions actions, @Nullable String recipient, public static boolean sendHtmlMail(ThingActions actions, @Nullable String recipient, @Nullable String subject,
@Nullable String subject, @Nullable String html, @Nullable String urlString) { @Nullable String html, @Nullable String urlString) {
List<String> urlList = new ArrayList<>(); List<String> urlList = new ArrayList<>();
if (urlString != null) { if (urlString != null) {
urlList.add(urlString); urlList.add(urlString);
@ -198,13 +194,9 @@ public class SendMailActions implements ThingActions {
return SendMailActions.sendHtmlMail(actions, recipient, subject, html, urlList); return SendMailActions.sendHtmlMail(actions, recipient, subject, html, urlList);
} }
public static boolean sendHtmlMail(@Nullable ThingActions actions, @Nullable String recipient, public static boolean sendHtmlMail(ThingActions actions, @Nullable String recipient, @Nullable String subject,
@Nullable String subject, @Nullable String html, @Nullable List<String> urlStringList) { @Nullable String html, @Nullable List<String> urlStringList) {
if (actions instanceof SendMailActions) { return ((SendMailActions) actions).sendHtmlMail(recipient, subject, html, urlStringList);
return ((SendMailActions) actions).sendHtmlMail(recipient, subject, html, urlStringList);
} else {
throw new IllegalArgumentException("Actions is not an instance of SendMailActions");
}
} }
@Override @Override

View File

@ -59,12 +59,8 @@ public class MaxCubeActions implements ThingActions {
return true; return true;
} }
public static boolean backup(@Nullable ThingActions actions) { public static boolean backup(ThingActions actions) {
if (actions instanceof MaxCubeActions) { return ((MaxCubeActions) actions).backup();
return ((MaxCubeActions) actions).backup();
} else {
throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions");
}
} }
@RuleAction(label = "reset the Cube configuration", description = "Resets the MAX! Cube room and device information. Devices will need to be included again!") @RuleAction(label = "reset the Cube configuration", description = "Resets the MAX! Cube room and device information. Devices will need to be included again!")
@ -78,12 +74,8 @@ public class MaxCubeActions implements ThingActions {
return true; return true;
} }
public static boolean reset(@Nullable ThingActions actions) { public static boolean reset(ThingActions actions) {
if (actions instanceof MaxCubeActions) { return ((MaxCubeActions) actions).resetConfig();
return ((MaxCubeActions) actions).resetConfig();
} else {
throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions");
}
} }
@RuleAction(label = "restart the Cube", description = "Restarts the MAX! Cube.") @RuleAction(label = "restart the Cube", description = "Restarts the MAX! Cube.")
@ -97,11 +89,7 @@ public class MaxCubeActions implements ThingActions {
return true; return true;
} }
public static boolean reboot(@Nullable ThingActions actions) { public static boolean reboot(ThingActions actions) {
if (actions instanceof MaxCubeActions) { return ((MaxCubeActions) actions).reboot();
return ((MaxCubeActions) actions).reboot();
} else {
throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions");
}
} }
} }

View File

@ -59,11 +59,7 @@ public class MaxDevicesActions implements ThingActions {
return true; return true;
} }
public static boolean deleteFromCube(@Nullable ThingActions actions) { public static boolean deleteFromCube(ThingActions actions) {
if (actions instanceof MaxDevicesActions) { return ((MaxDevicesActions) actions).deleteFromCube();
return ((MaxDevicesActions) actions).deleteFromCube();
} else {
throw new IllegalArgumentException("Actions is not an instance of MaxDevicesActions");
}
} }
} }

View File

@ -47,67 +47,51 @@ public class HeliosEasyControlsActions implements ThingActions {
private void triggerSwitch(String variableName) { private void triggerSwitch(String variableName) {
try { try {
if (this.handler != null) { if (handler != null) {
this.handler.writeValue(variableName, "1"); handler.writeValue(variableName, "1");
} }
} catch (HeliosException e) { } catch (HeliosException e) {
logger.warn("Error executing action 'resetFilterChangeTimer': {}", e.getMessage()); 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() { public void resetFilterChangeTimer() {
this.triggerSwitch(HeliosEasyControlsBindingConstants.FILTER_CHANGE_RESET); triggerSwitch(HeliosEasyControlsBindingConstants.FILTER_CHANGE_RESET);
} }
public static void resetFilterChangeTimer(@Nullable ThingActions actions) { public static void resetFilterChangeTimer(ThingActions actions) {
if (actions instanceof HeliosEasyControlsActions) { ((HeliosEasyControlsActions) actions).resetFilterChangeTimer();
((HeliosEasyControlsActions) actions).resetFilterChangeTimer();
} else {
throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
}
} }
@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() { public void resetErrors() {
this.triggerSwitch(HeliosEasyControlsBindingConstants.RESET_FLAG); triggerSwitch(HeliosEasyControlsBindingConstants.RESET_FLAG);
} }
public static void resetErrors(@Nullable ThingActions actions) { public static void resetErrors(ThingActions actions) {
if (actions instanceof HeliosEasyControlsActions) { ((HeliosEasyControlsActions) actions).resetErrors();
((HeliosEasyControlsActions) actions).resetErrors();
} else {
throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
}
} }
@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() { public void resetToFactoryDefaults() {
this.triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_RESET); triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_RESET);
} }
public static void resetToFactoryDefaults(@Nullable ThingActions actions) { public static void resetToFactoryDefaults(ThingActions actions) {
if (actions instanceof HeliosEasyControlsActions) { ((HeliosEasyControlsActions) actions).resetToFactoryDefaults();
((HeliosEasyControlsActions) actions).resetToFactoryDefaults();
} else {
throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
}
} }
@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() { public void resetSwitchingTimes() {
this.triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_SETTING_WZU); triggerSwitch(HeliosEasyControlsBindingConstants.FACTORY_SETTING_WZU);
} }
public static void resetSwitchingTimes(@Nullable ThingActions actions) { public static void resetSwitchingTimes(ThingActions actions) {
if (actions instanceof HeliosEasyControlsActions) { ((HeliosEasyControlsActions) actions).resetSwitchingTimes();
((HeliosEasyControlsActions) actions).resetSwitchingTimes();
} else {
throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
}
} }
@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() { public void setSysDateTime() {
HeliosEasyControlsHandler handler = this.handler; HeliosEasyControlsHandler handler = this.handler;
if (handler != null) { if (handler != null) {
@ -115,12 +99,8 @@ public class HeliosEasyControlsActions implements ThingActions {
} }
} }
public static void setSysDateTime(@Nullable ThingActions actions) { public static void setSysDateTime(ThingActions actions) {
if (actions instanceof HeliosEasyControlsActions) { ((HeliosEasyControlsActions) actions).setSysDateTime();
((HeliosEasyControlsActions) actions).setSysDateTime();
} else {
throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
}
} }
private void setBypass(boolean from, int day, int month) { 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( public void setBypassFrom(
@ActionInput(name = "day", label = "bypass from day", description = "The day from when the bypass should be active") int day, @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) { @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) { public static void setBypassFrom(ThingActions actions, int day, int month) {
if (actions instanceof HeliosEasyControlsActions) { ((HeliosEasyControlsActions) actions).setBypassFrom(day, month);
((HeliosEasyControlsActions) actions).setBypassFrom(day, month);
} else {
throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
}
} }
@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( public void setBypassTo(
@ActionInput(name = "day", label = "bypass to day", description = "The day until when the bypass should be active") int day, @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) { @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) { public static void setBypassTo(ThingActions actions, int day, int month) {
if (actions instanceof HeliosEasyControlsActions) { ((HeliosEasyControlsActions) actions).setBypassTo(day, month);
((HeliosEasyControlsActions) actions).setBypassTo(day, month);
} else {
throw new IllegalArgumentException("Instance is not an HeliosEasyControlsActions class.");
}
} }
} }

View File

@ -73,20 +73,11 @@ public class MPDActions implements ThingActions {
} }
} }
public static void sendCommand(@Nullable ThingActions actions, @Nullable String command, public static void sendCommand(ThingActions actions, @Nullable String command, @Nullable String parameter) {
@Nullable String parameter) { ((MPDActions) actions).sendCommand(command, parameter);
if (actions instanceof MPDActions) {
((MPDActions) actions).sendCommand(command, parameter);
} else {
throw new IllegalArgumentException("Actions is not an instance of MPDActions");
}
} }
public static void sendCommand(@Nullable ThingActions actions, @Nullable String command) { public static void sendCommand(ThingActions actions, @Nullable String command) {
if (actions instanceof MPDActions) { ((MPDActions) actions).sendCommand(command);
((MPDActions) actions).sendCommand(command);
} else {
throw new IllegalArgumentException("Actions is not an instance of MPDActions");
}
} }
} }

View File

@ -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); 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) { @Nullable Boolean retain) {
if (actions instanceof MQTTActions) { ((MQTTActions) actions).publishMQTT(topic, value, retain);
((MQTTActions) actions).publishMQTT(topic, value, retain);
} else {
throw new IllegalArgumentException("Actions is not an instance of MQTTActions");
}
} }
} }

View File

@ -57,11 +57,7 @@ public class NetworkActions implements ThingActions {
} }
} }
public static void sendWakeOnLanPacket(@Nullable ThingActions actions) { public static void sendWakeOnLanPacket(ThingActions actions) {
if (actions instanceof NetworkActions) { ((NetworkActions) actions).sendWakeOnLanPacket();
((NetworkActions) actions).sendWakeOnLanPacket();
} else {
throw new IllegalArgumentException("Actions is not an instance of NetworkActions");
}
} }
} }

View File

@ -48,12 +48,8 @@ public class NuvoThingActions implements ThingActions {
} }
/** Static alias to support the old DSL rules engine and make the action available there. */ /** Static alias to support the old DSL rules engine and make the action available there. */
public static void sendNuvoCommand(@Nullable ThingActions actions, String rawCommand) { public static void sendNuvoCommand(ThingActions actions, String rawCommand) {
if (actions instanceof NuvoThingActions) { ((NuvoThingActions) actions).sendNuvoCommand(rawCommand);
((NuvoThingActions) actions).sendNuvoCommand(rawCommand);
} else {
throw new IllegalArgumentException("Actions is not an instance of NuvoThingActions");
}
} }
@Override @Override

View File

@ -48,13 +48,8 @@ public class OnkyoThingActions implements ThingActions {
handler.sendRawCommand(command, value); handler.sendRawCommand(command, value);
} }
public static void sendRawCommand(@Nullable ThingActions actions, @Nullable String command, public static void sendRawCommand(ThingActions actions, @Nullable String command, @Nullable String value) {
@Nullable String value) { ((OnkyoThingActions) actions).sendRawCommand(command, value);
if (actions instanceof OnkyoThingActions) {
((OnkyoThingActions) actions).sendRawCommand(command, value);
} else {
throw new IllegalArgumentException("Actions is not an instance of OnkyoThingActions");
}
} }
@Override @Override

View File

@ -63,13 +63,9 @@ public class PushbulletActions implements ThingActions {
return localHandler.sendPush(recipient, title, message, "note"); return localHandler.sendPush(recipient, title, message, "note");
} }
public static boolean sendPushbulletNote(@Nullable ThingActions actions, @Nullable String recipient, public static boolean sendPushbulletNote(ThingActions actions, @Nullable String recipient, @Nullable String title,
@Nullable String title, @Nullable String message) { @Nullable String message) {
if (actions instanceof PushbulletActions) { return ((PushbulletActions) actions).sendPushbulletNote(recipient, title, message);
return ((PushbulletActions) actions).sendPushbulletNote(recipient, title, message);
} else {
throw new IllegalArgumentException("Actions is not an instance of PushbulletActions");
}
} }
@RuleAction(label = "@text/actionSendPushbulletNoteLabel", description = "@text/actionSendPushbulletNoteDesc") @RuleAction(label = "@text/actionSendPushbulletNoteLabel", description = "@text/actionSendPushbulletNoteDesc")
@ -87,12 +83,8 @@ public class PushbulletActions implements ThingActions {
return localHandler.sendPush(recipient, message, "note"); 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) { @Nullable String message) {
if (actions instanceof PushbulletActions) { return ((PushbulletActions) actions).sendPushbulletNote(recipient, message);
return ((PushbulletActions) actions).sendPushbulletNote(recipient, message);
} else {
throw new IllegalArgumentException("Actions is not an instance of PushbulletActions");
}
} }
} }

View File

@ -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. binding.pushbullet.description = The Pushbullet binding allows you to send messages to other users of the Pushbullet service.
# action # action
actionSendPushbulletNoteLabel = publish an Pushbullet message actionSendPushbulletNoteLabel = publish a Pushbullet message
actionSendPushbulletNoteDesc = Publishes a Title to the given Pushbullet Recipient. actionSendPushbulletNoteDesc = Publishes a Title to the given Pushbullet Recipient.
actionSendPushbulletNoteInputRecipientLabel = Pushbullet Recipient actionSendPushbulletNoteInputRecipientLabel = Pushbullet Recipient

View File

@ -50,12 +50,8 @@ public class RadioThermostatThingActions implements ThingActions {
} }
/** Static alias to support the old DSL rules engine and make the action available there. */ /** 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) { public static void sendRawCommand(ThingActions actions, @Nullable String rawCommand) {
if (actions instanceof RadioThermostatThingActions) { ((RadioThermostatThingActions) actions).sendRawCommand(rawCommand);
((RadioThermostatThingActions) actions).sendRawCommand(rawCommand);
} else {
throw new IllegalArgumentException("Actions is not an instance of RadioThermostatThingActions");
}
} }
@Override @Override

View File

@ -71,11 +71,7 @@ public class SatelEventLogActions implements ThingActions {
return result; return result;
} }
public static Map<String, Object> readEvent(@Nullable ThingActions actions, @Nullable Number index) { public static Map<String, Object> readEvent(ThingActions actions, @Nullable Number index) {
if (actions instanceof SatelEventLogActions) { return ((SatelEventLogActions) actions).readEvent(index);
return ((SatelEventLogActions) actions).readEvent(index);
} else {
throw new IllegalArgumentException("Actions is not an instance of SatelEventLogActions");
}
} }
} }

View File

@ -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. config-status.portEmpty = Serial port of INT-RS must be provided.
# actions # actions
actionReadEventLabel = Read event actionReadEventLabel = read an event
actionReadEventDesc = Reads a single record from the event log. actionReadEventDesc = Reads a single record from the event log.
actionInputIndexLabel = Event index actionInputIndexLabel = Event index
actionInputIndexDesc = Index of the event to read actionInputIndexDesc = Index of the event to read

View File

@ -393,105 +393,58 @@ public class TelegramActions implements ThingActions {
// legacy delegate methods // legacy delegate methods
/* APIs without chatId parameter */ /* APIs without chatId parameter */
public static boolean sendTelegram(@Nullable ThingActions actions, @Nullable String format, public static boolean sendTelegram(ThingActions actions, @Nullable String format, @Nullable Object... args) {
@Nullable Object... args) { return ((TelegramActions) actions).sendTelegram(format, args);
if (actions instanceof TelegramActions) {
return ((TelegramActions) actions).sendTelegram(format, args);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
} }
public static boolean sendTelegramQuery(@Nullable ThingActions actions, @Nullable String message, public static boolean sendTelegramQuery(ThingActions actions, @Nullable String message, @Nullable String replyId,
@Nullable String replyId, @Nullable String... buttons) { @Nullable String... buttons) {
if (actions instanceof TelegramActions) { return ((TelegramActions) actions).sendTelegramQuery(message, replyId, buttons);
return ((TelegramActions) actions).sendTelegramQuery(message, replyId, buttons);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
} }
public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable String photoURL, public static boolean sendTelegramPhoto(ThingActions actions, @Nullable String photoURL, @Nullable String caption) {
@Nullable String caption) { return ((TelegramActions) actions).sendTelegramPhoto(photoURL, caption, null, null);
if (actions instanceof TelegramActions) {
return ((TelegramActions) actions).sendTelegramPhoto(photoURL, caption, null, null);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
} }
public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable String photoURL, public static boolean sendTelegramPhoto(ThingActions actions, @Nullable String photoURL, @Nullable String caption,
@Nullable String caption, @Nullable String username, @Nullable String password) { @Nullable String username, @Nullable String password) {
if (actions instanceof TelegramActions) { return ((TelegramActions) actions).sendTelegramPhoto(photoURL, caption, username, password);
return ((TelegramActions) actions).sendTelegramPhoto(photoURL, caption, username, password);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
} }
public static boolean sendTelegramAnswer(@Nullable ThingActions actions, @Nullable String replyId, public static boolean sendTelegramAnswer(ThingActions actions, @Nullable String replyId, @Nullable String message) {
@Nullable String message) { return ((TelegramActions) actions).sendTelegramAnswer(replyId, message);
if (actions instanceof TelegramActions) {
return ((TelegramActions) actions).sendTelegramAnswer(replyId, message);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
} }
/* APIs with chatId parameter */ /* 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) { @Nullable Object... args) {
if (actions instanceof TelegramActions) { return ((TelegramActions) actions).sendTelegram(chatId, format, args);
return ((TelegramActions) actions).sendTelegram(chatId, format, args);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
} }
public static boolean sendTelegramQuery(@Nullable ThingActions actions, @Nullable Long chatId, public static boolean sendTelegramQuery(ThingActions actions, @Nullable Long chatId, @Nullable String message,
@Nullable String message, @Nullable String replyId, @Nullable String... buttons) { @Nullable String replyId, @Nullable String... buttons) {
if (actions instanceof TelegramActions) { return ((TelegramActions) actions).sendTelegramQuery(chatId, message, replyId, buttons);
return ((TelegramActions) actions).sendTelegramQuery(chatId, message, replyId, buttons);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
} }
public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable Long chatId, public static boolean sendTelegramPhoto(ThingActions actions, @Nullable Long chatId, @Nullable String photoURL,
@Nullable String photoURL, @Nullable String caption) { @Nullable String caption) {
if (actions instanceof TelegramActions) { return ((TelegramActions) actions).sendTelegramPhoto(chatId, photoURL, caption, null, null);
return ((TelegramActions) actions).sendTelegramPhoto(chatId, photoURL, caption, null, null);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
} }
public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable Long chatId, public static boolean sendTelegramPhoto(ThingActions actions, @Nullable Long chatId, @Nullable String photoURL,
@Nullable String photoURL, @Nullable String caption, @Nullable String username, @Nullable String password) { @Nullable String caption, @Nullable String username, @Nullable String password) {
if (actions instanceof TelegramActions) { return ((TelegramActions) actions).sendTelegramPhoto(chatId, photoURL, caption, username, password);
return ((TelegramActions) actions).sendTelegramPhoto(chatId, photoURL, caption, username, password);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
} }
public static boolean sendTelegramAnswer(@Nullable ThingActions actions, @Nullable Long chatId, public static boolean sendTelegramAnswer(ThingActions actions, @Nullable Long chatId, @Nullable String replyId,
@Nullable String replyId, @Nullable String message) { @Nullable String message) {
if (actions instanceof TelegramActions) { return ((TelegramActions) actions).sendTelegramAnswer(chatId, replyId, message);
return ((TelegramActions) actions).sendTelegramAnswer(chatId, replyId, message);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
} }
public static boolean sendTelegramAnswer(@Nullable ThingActions actions, @Nullable String chatId, public static boolean sendTelegramAnswer(ThingActions actions, @Nullable String chatId, @Nullable String replyId,
@Nullable String replyId, @Nullable String message) { @Nullable String message) {
if (actions instanceof TelegramActions) { return ((TelegramActions) actions).sendTelegramAnswer(Long.valueOf(chatId), replyId, message);
return ((TelegramActions) actions).sendTelegramAnswer(Long.valueOf(chatId), replyId, message);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
} }
@Override @Override

View File

@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory;
* *
* @author Pavel Gololobov - Initial contribution * @author Pavel Gololobov - Initial contribution
*/ */
@ThingActionsScope(name = "xmpp") @ThingActionsScope(name = "xmppclient")
@NonNullByDefault @NonNullByDefault
public class XMPPActions implements ThingActions { public class XMPPActions implements ThingActions {
private static final Logger logger = LoggerFactory.getLogger(XMPPActions.class); private static final Logger logger = LoggerFactory.getLogger(XMPPActions.class);
@ -66,11 +66,7 @@ public class XMPPActions implements ThingActions {
connection.sendMessage(to, text); connection.sendMessage(to, text);
} }
public static void publishXMPP(@Nullable ThingActions actions, @Nullable String to, @Nullable String text) { public static void publishXMPP(ThingActions actions, @Nullable String to, @Nullable String text) {
if (actions instanceof XMPPActions) { ((XMPPActions) actions).publishXMPP(to, text);
((XMPPActions) actions).publishXMPP(to, text);
} else {
throw new IllegalArgumentException("Actions is not an instance of XMPPActions");
}
} }
} }

View File

@ -50,11 +50,7 @@ public class YIOremoteDockActions implements ThingActions {
} }
} }
public static void sendIRCode(@Nullable ThingActions actions, @Nullable String irCode) { public static void sendIRCode(ThingActions actions, @Nullable String irCode) {
if (actions instanceof YIOremoteDockActions) { ((YIOremoteDockActions) actions).sendIRCode(irCode);
((YIOremoteDockActions) actions).sendIRCode(irCode);
} else {
throw new IllegalArgumentException("Instance is not an YIOremoteDockActions class.");
}
} }
} }

View File

@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory;
* *
* @author Mark Hilbush - Initial contribution * @author Mark Hilbush - Initial contribution
*/ */
@ThingActionsScope(name = "zm") @ThingActionsScope(name = "zoneminder")
@NonNullByDefault @NonNullByDefault
public class ZmActions implements ThingActions { public class ZmActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(ZmActions.class); private final Logger logger = LoggerFactory.getLogger(ZmActions.class);
@ -63,12 +63,8 @@ public class ZmActions implements ThingActions {
localHandler.actionTriggerAlarm(duration); localHandler.actionTriggerAlarm(duration);
} }
public static void triggerAlarm(@Nullable ThingActions actions, @Nullable Number alarmDuration) { public static void triggerAlarm(ThingActions actions, @Nullable Number alarmDuration) {
if (actions instanceof ZmActions) { ((ZmActions) actions).triggerAlarm(alarmDuration);
((ZmActions) actions).triggerAlarm(alarmDuration);
} else {
throw new IllegalArgumentException("Actions is not an instance of ZmActions");
}
} }
/** /**
@ -86,12 +82,8 @@ public class ZmActions implements ThingActions {
localHandler.actionTriggerAlarm(); localHandler.actionTriggerAlarm();
} }
public static void triggerAlarm(@Nullable ThingActions actions) { public static void triggerAlarm(ThingActions actions) {
if (actions instanceof ZmActions) { ((ZmActions) actions).triggerAlarm();
((ZmActions) actions).triggerAlarm();
} else {
throw new IllegalArgumentException("Actions is not an instance of ZmActions");
}
} }
/** /**
@ -108,11 +100,7 @@ public class ZmActions implements ThingActions {
localHandler.actionCancelAlarm(); localHandler.actionCancelAlarm();
} }
public static void cancelAlarm(@Nullable ThingActions actions) { public static void cancelAlarm(ThingActions actions) {
if (actions instanceof ZmActions) { ((ZmActions) actions).cancelAlarm();
((ZmActions) actions).cancelAlarm();
} else {
throw new IllegalArgumentException("Actions is not an instance of ZmActions");
}
} }
} }