Rework ThingActions (#8732)

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

Related to:

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

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2020-10-14 19:01:12 +02:00 committed by GitHub
parent 4adc214c69
commit bef1046258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
86 changed files with 708 additions and 2096 deletions

View File

@ -12,9 +12,6 @@
*/
package org.openhab.binding.alarmdecoder.internal.actions;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.alarmdecoder.internal.handler.ADBridgeHandler;
@ -33,7 +30,7 @@ import org.slf4j.LoggerFactory;
*/
@ThingActionsScope(name = "alarmdecoder")
@NonNullByDefault
public class BridgeActions implements ThingActions, IBridgeActions {
public class BridgeActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(BridgeActions.class);
@ -58,8 +55,7 @@ public class BridgeActions implements ThingActions, IBridgeActions {
/**
* Reboot thing action
*/
@Override
@RuleAction(label = "Reboot", description = "Reboot the Alarm Decoder device")
@RuleAction(label = "reboot the device", description = "Reboot the Alarm Decoder device.")
public void reboot() {
ADBridgeHandler bridge = this.bridge;
if (bridge != null) {
@ -72,34 +68,10 @@ public class BridgeActions implements ThingActions, IBridgeActions {
// Static method for Rules DSL backward compatibility
public static void reboot(@Nullable ThingActions actions) {
// if (actions instanceof BridgeActions) {
// ((BridgeActions) actions).reboot();
// } else {
// throw new IllegalArgumentException("Instance is not a BridgeActions class.");
// }
invokeMethodOf(actions).reboot(); // Remove and uncomment above when core issue #1536 is fixed
}
/**
* This is only necessary to work around a bug in openhab-core (issue #1536). It should be removed once that is
* resolved.
*/
private static IBridgeActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(BridgeActions.class.getName())) {
if (actions instanceof IBridgeActions) {
return (IBridgeActions) actions;
if (actions instanceof BridgeActions) {
((BridgeActions) actions).reboot();
} else {
return (IBridgeActions) Proxy.newProxyInstance(IBridgeActions.class.getClassLoader(),
new Class[] { IBridgeActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of BridgeActions");
}
}
}

View File

@ -1,29 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.alarmdecoder.internal.actions;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* The {@link IBridgeActions} defines the interface for all thing actions supported by the bridges.
* This is only necessary to work around a bug in openhab-core (issue #1536). It should be removed once that is
* resolved.
*
* @author Bob Adair - Initial contribution
*
*/
@NonNullByDefault
public interface IBridgeActions {
public void reboot();
}

View File

@ -12,8 +12,6 @@
*/
package org.openhab.binding.astro.internal.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.time.ZonedDateTime;
import javax.measure.quantity.Angle;
@ -35,18 +33,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {AstroActions } defines rule actions for the Astro binding.
* <p>
* <b>Note:</b>The static method <b>invokeMethodOf</b> handles the case where
* the test <i>actions instanceof AstroActions</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link AstroActions} class
* can be loaded by a different classloader than the <i>actions</i> instance.
* Defines the automation thing actions for the Astro binding.
*
* @author Gaël L'hopital - Initial contribution
*/
@ThingActionsScope(name = "astro")
@NonNullByDefault
public class AstroActions implements ThingActions, IAstroActions {
public class AstroActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(AstroActions.class);
protected @Nullable AstroThingHandler handler;
@ -64,11 +57,10 @@ public class AstroActions implements ThingActions, IAstroActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
return handler;
}
@Override
@RuleAction(label = "Astro : Get Azimuth", description = "Get the azimuth of the sun for a given time")
@RuleAction(label = "get the azimuth", description = "Get the azimuth for a given time.")
public @Nullable @ActionOutput(name = "getAzimuth", label = "Azimuth", type = "org.openhab.core.library.types.QuantityType<javax.measure.quantity.Angle>") QuantityType<Angle> getAzimuth(
@ActionInput(name = "date", label = "Date", required = false, description = "Considered date") @Nullable ZonedDateTime date) {
logger.debug("Astro action 'getAzimuth' called");
@ -81,8 +73,7 @@ public class AstroActions implements ThingActions, IAstroActions {
return null;
}
@Override
@RuleAction(label = "Astro : Get Elevation", description = "Get the Elevation of the sun for a given time")
@RuleAction(label = "get the elevation", description = "Get the elevation for a given time.")
public @Nullable @ActionOutput(name = "getElevation", label = "Elevation", type = "org.openhab.core.library.types.QuantityType<javax.measure.quantity.Angle>") QuantityType<Angle> getElevation(
@ActionInput(name = "date", label = "Date", required = false, description = "Considered date") @Nullable ZonedDateTime date) {
logger.debug("Astro action 'getElevation' called");
@ -95,8 +86,7 @@ public class AstroActions implements ThingActions, IAstroActions {
return null;
}
@Override
@RuleAction(label = "Sun : Get Event Time", description = "Get the date time of a given planet event")
@RuleAction(label = "get the date time of a sun event", description = "Get the date time of a sun event.")
public @Nullable @ActionOutput(name = "getEventTime", type = "java.time.ZonedDateTime") ZonedDateTime getEventTime(
@ActionInput(name = "phaseName", label = "Phase", required = true, description = "Requested phase") String phaseName,
@ActionInput(name = "date", label = "Date", required = false, description = "Considered date") @Nullable ZonedDateTime date,
@ -124,39 +114,32 @@ public class AstroActions implements ThingActions, IAstroActions {
public static @Nullable QuantityType<Angle> getElevation(@Nullable ThingActions actions,
@Nullable ZonedDateTime date) {
return invokeMethodOf(actions).getElevation(date);
if (actions instanceof AstroActions) {
return ((AstroActions) actions).getElevation(date);
} else {
throw new IllegalArgumentException("Actions is not an instance of AstroActions");
}
}
public static @Nullable QuantityType<Angle> getAzimuth(@Nullable ThingActions actions,
@Nullable ZonedDateTime date) {
return invokeMethodOf(actions).getAzimuth(date);
if (actions instanceof AstroActions) {
return ((AstroActions) actions).getAzimuth(date);
} else {
throw new IllegalArgumentException("Actions is not an instance of AstroActions");
}
}
public static @Nullable ZonedDateTime getEventTime(@Nullable ThingActions actions, @Nullable String phaseName,
@Nullable ZonedDateTime date, @Nullable String moment) {
if (actions instanceof AstroActions) {
if (phaseName != null) {
return invokeMethodOf(actions).getEventTime(phaseName, date, moment);
return ((AstroActions) actions).getEventTime(phaseName, date, moment);
} else {
throw new IllegalArgumentException("phaseName can not be null");
}
}
private static IAstroActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(AstroActions.class.getName())) {
if (actions instanceof IAstroActions) {
return (IAstroActions) actions;
} else {
return (IAstroActions) Proxy.newProxyInstance(IAstroActions.class.getClassLoader(),
new Class[] { IAstroActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of AstroActions");
}
}
}

View File

@ -1,36 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.astro.internal.action;
import java.time.ZonedDateTime;
import javax.measure.quantity.Angle;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.library.types.QuantityType;
/**
* The {@link IAstroActions} defines the interface for all thing actions supported by the binding.
*
* @author Gaël L'hopital - Initial contribution
*/
@NonNullByDefault
public interface IAstroActions {
public @Nullable ZonedDateTime getEventTime(String phaseName, @Nullable ZonedDateTime date,
@Nullable String moment);
public @Nullable QuantityType<Angle> getAzimuth(@Nullable ZonedDateTime date);
public @Nullable QuantityType<Angle> getElevation(@Nullable ZonedDateTime date);
}

View File

@ -12,9 +12,6 @@
*/
package org.openhab.binding.automower.internal.actions;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.automower.internal.things.AutomowerCommand;
@ -32,7 +29,7 @@ import org.slf4j.LoggerFactory;
*/
@ThingActionsScope(name = "automower")
@NonNullByDefault
public class AutomowerActions implements ThingActions, IAutomowerActions {
public class AutomowerActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(AutomowerActions.class);
private @Nullable AutomowerHandler handler;
@ -46,7 +43,6 @@ public class AutomowerActions implements ThingActions, IAutomowerActions {
return handler;
}
@Override
@RuleAction(label = "@text/action-start-label", description = "@text/action-start-desc")
public void start(
@ActionInput(name = "duration", label = "@text/action-input-duration-label", description = "@text/action-input-duration-desc") int durationMin) {
@ -59,10 +55,13 @@ public class AutomowerActions implements ThingActions, IAutomowerActions {
}
public static void start(@Nullable ThingActions actions, int durationMin) {
invokeMethodOf(actions).start(durationMin);
if (actions instanceof AutomowerActions) {
((AutomowerActions) actions).start(durationMin);
} else {
throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
}
}
@Override
@RuleAction(label = "@text/action-pause-label", description = "@text/action-pause-desc")
public void pause() {
AutomowerHandler automowerHandler = handler;
@ -74,10 +73,13 @@ public class AutomowerActions implements ThingActions, IAutomowerActions {
}
public static void pause(@Nullable ThingActions actions) {
invokeMethodOf(actions).pause();
if (actions instanceof AutomowerActions) {
((AutomowerActions) actions).pause();
} else {
throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
}
}
@Override
@RuleAction(label = "@text/action-parkuntilnextschedule-label", description = "@text/action-parkuntilnextschedule-desc")
public void parkUntilNextSchedule() {
AutomowerHandler automowerHandler = handler;
@ -89,10 +91,13 @@ public class AutomowerActions implements ThingActions, IAutomowerActions {
}
public static void parkUntilNextSchedule(@Nullable ThingActions actions) {
invokeMethodOf(actions).parkUntilNextSchedule();
if (actions instanceof AutomowerActions) {
((AutomowerActions) actions).parkUntilNextSchedule();
} else {
throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
}
}
@Override
@RuleAction(label = "@text/action-parkuntilfurthernotice-label", description = "@text/action-parkuntilfurthernotice-desc")
public void parkUntilFurtherNotice() {
AutomowerHandler automowerHandler = handler;
@ -104,10 +109,13 @@ public class AutomowerActions implements ThingActions, IAutomowerActions {
}
public static void parkUntilFurtherNotice(@Nullable ThingActions actions) {
invokeMethodOf(actions).parkUntilFurtherNotice();
if (actions instanceof AutomowerActions) {
((AutomowerActions) actions).parkUntilFurtherNotice();
} else {
throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
}
}
@Override
@RuleAction(label = "@text/action-park-label", description = "@text/action-park-desc")
public void park(
@ActionInput(name = "duration", label = "@text/action-input-duration-label", description = "@text/action-input-duration-desc") int durationMin) {
@ -120,10 +128,13 @@ public class AutomowerActions implements ThingActions, IAutomowerActions {
}
public static void park(@Nullable ThingActions actions, int durationMin) {
invokeMethodOf(actions).park(durationMin);
if (actions instanceof AutomowerActions) {
((AutomowerActions) actions).park(durationMin);
} else {
throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
}
}
@Override
@RuleAction(label = "@text/action-resumeschedule-label", description = "@text/action-resumeschedule-desc")
public void resumeSchedule() {
AutomowerHandler automowerHandler = handler;
@ -135,25 +146,10 @@ public class AutomowerActions implements ThingActions, IAutomowerActions {
}
public static void resumeSchedule(@Nullable ThingActions actions) {
invokeMethodOf(actions).resumeSchedule();
}
private static IAutomowerActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(AutomowerActions.class.getName())) {
if (actions instanceof AutomowerActions) {
return (IAutomowerActions) actions;
((AutomowerActions) actions).resumeSchedule();
} else {
return (IAutomowerActions) Proxy.newProxyInstance(IAutomowerActions.class.getClassLoader(),
new Class[] { IAutomowerActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
}
}
throw new IllegalArgumentException("Actions is not an instance of IAutomowerActions");
}
}

View File

@ -1,36 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.automower.internal.actions;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* Actions that can be executed for an automower
*
* @author Markus Pfleger - Initial contribution
*/
@NonNullByDefault
public interface IAutomowerActions {
void resumeSchedule();
void park(int durationMin);
void parkUntilFurtherNotice();
void parkUntilNextSchedule();
void pause();
void start(int durationMin);
}

View File

@ -10,22 +10,16 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.avmfritz.actions;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
package org.openhab.binding.avmfritz.internal.actions;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.avmfritz.internal.actions.IAVMFritzHeatingActions;
import org.openhab.binding.avmfritz.internal.handler.AVMFritzHeatingActionsHandler;
import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.RuleAction;
import org.openhab.core.thing.binding.ThingActions;
import org.openhab.core.thing.binding.ThingActionsScope;
import org.openhab.core.thing.binding.ThingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link AVMFritzHeatingActions} defines thing actions for heating devices / groups of the avmfritz binding.
@ -34,9 +28,7 @@ import org.slf4j.LoggerFactory;
*/
@ThingActionsScope(name = "avmfritz")
@NonNullByDefault
public class AVMFritzHeatingActions implements ThingActions, IAVMFritzHeatingActions {
private final Logger logger = LoggerFactory.getLogger(AVMFritzHeatingActions.class);
public class AVMFritzHeatingActions implements ThingActions {
private @Nullable AVMFritzHeatingActionsHandler handler;
@ -50,7 +42,6 @@ public class AVMFritzHeatingActions implements ThingActions, IAVMFritzHeatingAct
return handler;
}
@Override
@RuleAction(label = "@text/setBoostModeModeActionLabel", description = "@text/setBoostModeActionDescription")
public void setBoostMode(
@ActionInput(name = "Duration", label = "@text/setBoostModeDurationInputLabel", description = "@text/setBoostModeDurationInputDescription", type = "java.lang.Long", required = true) @Nullable Long duration) {
@ -65,10 +56,13 @@ public class AVMFritzHeatingActions implements ThingActions, IAVMFritzHeatingAct
}
public static void setBoostMode(@Nullable ThingActions actions, @Nullable Long duration) {
invokeMethodOf(actions).setBoostMode(duration);
if (actions instanceof AVMFritzHeatingActions) {
((AVMFritzHeatingActions) actions).setBoostMode(duration);
} else {
throw new IllegalArgumentException("Actions is not an instance of AVMFritzHeatingActions");
}
}
@Override
@RuleAction(label = "@text/setWindowOpenModeActionLabel", description = "@text/setWindowOpenModeActionDescription")
public void setWindowOpenMode(
@ActionInput(name = "Duration", label = "@text/setWindowOpenModeDurationInputLabel", description = "@text/setWindowOpenModeDurationInputDescription", type = "java.lang.Long", required = true) @Nullable Long duration) {
@ -83,25 +77,10 @@ public class AVMFritzHeatingActions implements ThingActions, IAVMFritzHeatingAct
}
public static void setWindowOpenMode(@Nullable ThingActions actions, @Nullable Long duration) {
invokeMethodOf(actions).setWindowOpenMode(duration);
}
private static IAVMFritzHeatingActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(AVMFritzHeatingActions.class.getName())) {
if (actions instanceof IAVMFritzHeatingActions) {
return (IAVMFritzHeatingActions) actions;
if (actions instanceof AVMFritzHeatingActions) {
((AVMFritzHeatingActions) actions).setWindowOpenMode(duration);
} else {
return (IAVMFritzHeatingActions) Proxy.newProxyInstance(IAVMFritzHeatingActions.class.getClassLoader(),
new Class[] { IAVMFritzHeatingActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of AVMFritzHeatingActions");
}
}
}

View File

@ -1,31 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.avmfritz.internal.actions;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.avmfritz.actions.AVMFritzHeatingActions;
/**
* The {@link IAVMFritzHeatingActions} defines the interface for all thing actions supported by the binding.
* These methods, parameters, and return types are explained in {@link AVMFritzHeatingActions}.
*
* @author Christoph Weitkamp - Initial contribution
*/
@NonNullByDefault
public interface IAVMFritzHeatingActions {
void setBoostMode(@Nullable Long duration);
void setWindowOpenMode(@Nullable Long duration);
}

View File

@ -16,7 +16,7 @@ import java.util.Collection;
import java.util.Collections;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.avmfritz.actions.AVMFritzHeatingActions;
import org.openhab.binding.avmfritz.internal.actions.AVMFritzHeatingActions;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerService;

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.avmfritz.actions;
package org.openhab.binding.avmfritz.internal.actions;
import static org.junit.jupiter.api.Assertions.assertThrows;

View File

@ -1,27 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.dmx.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link IDmxActions} defines the actions for DMX Bridges
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public interface IDmxActions {
public void sendFade(@Nullable String channels, @Nullable String fade, @Nullable Boolean resumeAfter);
}

View File

@ -21,7 +21,7 @@ import java.util.List;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.openhab.binding.dmx.action.DmxActions;
import org.openhab.binding.dmx.internal.action.DmxActions;
import org.openhab.binding.dmx.internal.action.FadeAction;
import org.openhab.binding.dmx.internal.action.ResumeAction;
import org.openhab.binding.dmx.internal.config.DmxBridgeHandlerConfiguration;

View File

@ -10,10 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.dmx.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
package org.openhab.binding.dmx.internal.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -28,29 +25,23 @@ import org.slf4j.LoggerFactory;
/**
* The {@link DmxActions} provides actions for DMX Bridges
* <p>
* <b>Note:</b>The static method <b>invokeMethodOf</b> handles the case where
* the test <i>actions instanceof DmxActions</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link DmxActions} class
* can be loaded by a different classloader than the <i>actions</i> instance.
*
* @author Jan N. Klug - Initial contribution
*/
@ThingActionsScope(name = "dmx")
@NonNullByDefault
public class DmxActions implements ThingActions, IDmxActions {
public class DmxActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(DmxActions.class);
private @Nullable DmxBridgeHandler handler;
@Override
@RuleAction(label = "DMX Output", description = "immediately performs fade on selected DMX channels")
@RuleAction(label = "immediately fade channels", description = "Immediately performs fade on selected DMX channels.")
public void sendFade(@ActionInput(name = "channels") @Nullable String channels,
@ActionInput(name = "fade") @Nullable String fade,
@ActionInput(name = "resumeAfter") @Nullable Boolean resumeAfter) {
logger.debug("thingHandlerAction called with inputs: {} {} {}", channels, fade, resumeAfter);
DmxBridgeHandler handler = this.handler;
if (handler == null) {
logger.warn("DMX Action service ThingHandler is null!");
@ -77,27 +68,12 @@ public class DmxActions implements ThingActions, IDmxActions {
public static void sendFade(@Nullable ThingActions actions, @Nullable String channels, @Nullable String fade,
@Nullable Boolean resumeAfter) {
invokeMethodOf(actions).sendFade(channels, fade, resumeAfter);
}
private static IDmxActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(DmxActions.class.getName())) {
if (actions instanceof IDmxActions) {
return (IDmxActions) actions;
if (actions instanceof DmxActions) {
((DmxActions) actions).sendFade(channels, fade, resumeAfter);
} else {
return (IDmxActions) Proxy.newProxyInstance(IDmxActions.class.getClassLoader(),
new Class[] { IDmxActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of DmxActions");
}
}
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
@ -108,6 +84,6 @@ public class DmxActions implements ThingActions, IDmxActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
return handler;
}
}

View File

@ -1,37 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.doorbird.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* The {@link IDoorbirdActions} defines the interface for all thing actions supported by the binding.
* These methods, parameters, and return types are explained in {@link DoorbirdActions}.
*
* @author Mark Hilbush - Initial contribution
*/
@NonNullByDefault
public interface IDoorbirdActions {
public void restart();
public void sipHangup();
public String getRingTimeLimit();
public String getCallTimeLimit();
public String getLastErrorCode();
public String getLastErrorText();
}

View File

@ -10,10 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.doorbird.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
package org.openhab.binding.doorbird.internal.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -34,12 +31,12 @@ import org.slf4j.LoggerFactory;
@ThingActionsScope(name = "doorbird")
@NonNullByDefault
public class DoorbirdActions implements ThingActions {
private static final Logger LOGGER = LoggerFactory.getLogger(DoorbirdActions.class);
private final Logger logger = LoggerFactory.getLogger(DoorbirdActions.class);
private @Nullable DoorbellHandler handler;
public DoorbirdActions() {
LOGGER.debug("DoorbirdActions service created");
logger.debug("DoorbirdActions service created");
}
@Override
@ -51,113 +48,118 @@ public class DoorbirdActions implements ThingActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
return handler;
}
private static IDoorbirdActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(DoorbirdActions.class.getName())) {
if (actions instanceof IDoorbirdActions) {
return (IDoorbirdActions) actions;
} else {
return (IDoorbirdActions) Proxy.newProxyInstance(IDoorbirdActions.class.getClassLoader(),
new Class[] { IDoorbirdActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("actions is not an instance of DoorbirdActions");
}
@RuleAction(label = "Restart Doorbird", description = "Restarts the Doorbird device")
@RuleAction(label = "restart the Doorbird", description = "Restarts the Doorbird device.")
public void restart() {
LOGGER.debug("Doorbird action 'restart' called");
logger.debug("Doorbird action 'restart' called");
if (handler != null) {
handler.actionRestart();
} else {
LOGGER.info("Doorbird Action service ThingHandler is null!");
logger.info("Doorbird Action service ThingHandler is null!");
}
}
public static void restart(@Nullable ThingActions actions) {
invokeMethodOf(actions).restart();
if (actions instanceof DoorbirdActions) {
((DoorbirdActions) actions).restart();
} else {
throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
}
}
@RuleAction(label = "SIP Hangup", description = "Hangup SIP call")
@RuleAction(label = "hangup a SIP call", description = "Hangup SIP call.")
public void sipHangup() {
LOGGER.debug("Doorbird action 'sipHangup' called");
logger.debug("Doorbird action 'sipHangup' called");
if (handler != null) {
handler.actionSIPHangup();
} else {
LOGGER.info("Doorbird Action service ThingHandler is null!");
logger.info("Doorbird Action service ThingHandler is null!");
}
}
public static void sipHangup(@Nullable ThingActions actions) {
invokeMethodOf(actions).sipHangup();
if (actions instanceof DoorbirdActions) {
((DoorbirdActions) actions).sipHangup();
} else {
throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
}
}
@RuleAction(label = "Get Ring Time Limit", description = "Get the value of RING_TIME_LIMIT")
@RuleAction(label = "get the ring time limit", description = "Get the value of RING_TIME_LIMIT.")
public @ActionOutput(name = "getRingTimeLimit", type = "java.lang.String") String getRingTimeLimit() {
LOGGER.debug("Doorbird action 'getRingTimeLimit' called");
logger.debug("Doorbird action 'getRingTimeLimit' called");
if (handler != null) {
return handler.actionGetRingTimeLimit();
} else {
LOGGER.info("Doorbird Action service ThingHandler is null!");
logger.info("Doorbird Action service ThingHandler is null!");
return "";
}
}
public static String getRingTimeLimit(@Nullable ThingActions actions) {
return invokeMethodOf(actions).getRingTimeLimit();
if (actions instanceof DoorbirdActions) {
return ((DoorbirdActions) actions).getRingTimeLimit();
} else {
throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
}
}
@RuleAction(label = "Get Call Time Limit", description = "Get the value of CALL_TIME_LIMIT")
@RuleAction(label = "get the call time limit", description = "Get the value of CALL_TIME_LIMIT.")
public @ActionOutput(name = "getCallTimeLimit", type = "java.lang.String") String getCallTimeLimit() {
LOGGER.debug("Doorbird action 'getCallTimeLimit' called");
logger.debug("Doorbird action 'getCallTimeLimit' called");
if (handler != null) {
return handler.actionGetCallTimeLimit();
} else {
LOGGER.info("Doorbird Action service ThingHandler is null!");
logger.info("Doorbird Action service ThingHandler is null!");
return "";
}
}
public static String getCallTimeLimit(@Nullable ThingActions actions) {
return invokeMethodOf(actions).getCallTimeLimit();
if (actions instanceof DoorbirdActions) {
return ((DoorbirdActions) actions).getCallTimeLimit();
} else {
throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
}
}
@RuleAction(label = "Get Last Error Code", description = "Get the value of LASTERRORCODE")
@RuleAction(label = "get the last error code", description = "Get the value of LASTERRORCODE.")
public @ActionOutput(name = "getLastErrorCode", type = "java.lang.String") String getLastErrorCode() {
LOGGER.debug("Doorbird action 'getLastErrorCode' called");
logger.debug("Doorbird action 'getLastErrorCode' called");
if (handler != null) {
return handler.actionGetLastErrorCode();
} else {
LOGGER.info("Doorbird Action service ThingHandler is null!");
logger.info("Doorbird Action service ThingHandler is null!");
return "";
}
}
public static String getLastErrorCode(@Nullable ThingActions actions) {
return invokeMethodOf(actions).getLastErrorCode();
if (actions instanceof DoorbirdActions) {
return ((DoorbirdActions) actions).getLastErrorCode();
} else {
throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
}
}
@RuleAction(label = "Get Last Error Text", description = "Get the value of LASTERRORTEXT")
@RuleAction(label = "get the last error text", description = "Get the value of LASTERRORTEXT.")
public @ActionOutput(name = "getLastErrorText", type = "java.lang.String") String getLastErrorText() {
LOGGER.debug("Doorbird action 'getLastErrorText' called");
logger.debug("Doorbird action 'getLastErrorText' called");
if (handler != null) {
return handler.actionGetLastErrorText();
} else {
LOGGER.info("Doorbird Action service ThingHandler is null!");
logger.info("Doorbird Action service ThingHandler is null!");
return "";
}
}
public static String getLastErrorText(@Nullable ThingActions actions) {
return invokeMethodOf(actions).getLastErrorText();
if (actions instanceof DoorbirdActions) {
return ((DoorbirdActions) actions).getLastErrorText();
} else {
throw new IllegalArgumentException("Actions is not an instance of DoorbirdActions");
}
}
}

View File

@ -33,7 +33,7 @@ import javax.imageio.ImageIO;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.openhab.binding.doorbird.action.DoorbirdActions;
import org.openhab.binding.doorbird.internal.action.DoorbirdActions;
import org.openhab.binding.doorbird.internal.api.DoorbirdAPI;
import org.openhab.binding.doorbird.internal.api.DoorbirdImage;
import org.openhab.binding.doorbird.internal.api.SipStatus;

View File

@ -1,78 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.ecobee.action;
import java.util.Date;
import java.util.Map;
import javax.measure.quantity.Temperature;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.library.types.QuantityType;
/**
* The {@link IEcobeeActions} defines the interface for all thing actions supported by the binding.
* These methods, parameters, and return types are explained in {@link EcobeeActions}.
*
* @author Mark Hilbush - Initial contribution
*/
@NonNullByDefault
public interface IEcobeeActions {
public Boolean acknowledge(@Nullable String ackRef, @Nullable String ackType, @Nullable Boolean remindMeLater);
public Boolean controlPlug(@Nullable String plugName, @Nullable String plugState, @Nullable Date startDateTime,
@Nullable Date endDateTime, @Nullable String holdType, @Nullable Number holdHours);
public Boolean sendMessage(@Nullable String text);
public Boolean createVacation(@Nullable String name, @Nullable QuantityType<Temperature> coolHoldTemp,
@Nullable QuantityType<Temperature> heatHoldTemp, @Nullable Date startDateTime, @Nullable Date endDateTime,
@Nullable String fan, @Nullable Number fanMinOnTime);
public Boolean deleteVacation(@Nullable String name);
public Boolean resetPreferences();
public Boolean resumeProgram(@Nullable Boolean resumeAll);
public Boolean setHold(@Nullable QuantityType<Temperature> coolHoldTemp,
@Nullable QuantityType<Temperature> heatHoldTemp);
public Boolean setHold(@Nullable QuantityType<Temperature> coolHoldTemp,
@Nullable QuantityType<Temperature> heatHoldTemp, @Nullable Number holdHours);
public Boolean setHold(@Nullable String holdClimateRef);
public Boolean setHold(@Nullable String holdClimateRef, @Nullable Number holdHours);
public Boolean setHold(@Nullable QuantityType<Temperature> coolHoldTemp,
@Nullable QuantityType<Temperature> heatHoldTemp, @Nullable String holdClimateRef,
@Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType,
@Nullable Number holdHours);
public Boolean setHold(@Nullable Map<String, Object> params, @Nullable String holdType, @Nullable Number holdHours,
@Nullable Date startDateTime, @Nullable Date endDateTime);
public Boolean setOccupied(@Nullable Boolean occupied, @Nullable Date startDateTime, @Nullable Date endDateTime,
@Nullable String holdType, @Nullable Number holdHours);
public Boolean updateSensor(@Nullable String name, @Nullable String deviceId, @Nullable String sensorId);
public @Nullable String getAlerts();
public @Nullable String getEvents();
public @Nullable String getClimates();
}

View File

@ -10,10 +10,8 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.ecobee.action;
package org.openhab.binding.ecobee.internal.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@ -52,11 +50,6 @@ import org.slf4j.LoggerFactory;
/**
* The {@link EcobeeActions} defines the thing actions for the Ecobee binding.
* <p>
* <b>Note:</b>The static method <b>invokeMethod</b> handles the case where
* the test <i>actions instanceof EcobeeActions</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link EcobeeActions} class
* can be loaded by a different classloader than the <i>actions</i> instance.
*
* @author John Cocula - Initial contribution
* @author Mark Hilbush - Adapted for OH2/3
@ -64,7 +57,7 @@ import org.slf4j.LoggerFactory;
*/
@ThingActionsScope(name = "ecobee")
@NonNullByDefault
public class EcobeeActions implements ThingActions, IEcobeeActions {
public class EcobeeActions implements ThingActions {
private static final Logger LOGGER = LoggerFactory.getLogger(EcobeeActions.class);
@ -83,26 +76,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
}
private static IEcobeeActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(EcobeeActions.class.getName())) {
if (actions instanceof IEcobeeActions) {
return (IEcobeeActions) actions;
} else {
return (IEcobeeActions) Proxy.newProxyInstance(IEcobeeActions.class.getClassLoader(),
new Class[] { IEcobeeActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
return handler;
}
/**
@ -112,8 +86,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
* href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/Acknowledge.shtml">Acknowledge
* </a>
*/
@Override
@RuleAction(label = "Acknowledge", description = "Acknowledges an alert.")
@RuleAction(label = "acknowledge an alert", description = "Acknowledges an alert.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean acknowledge(
@ActionInput(name = "ackRef", description = "The acknowledge ref of alert") @Nullable String ackRef,
@ActionInput(name = "ackType", description = "The type of acknowledgement. Valid values: accept, decline, defer, unacknowledged") @Nullable String ackType,
@ -131,7 +104,11 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
public static boolean acknowledge(@Nullable ThingActions actions, @Nullable String ackRef, @Nullable String ackType,
@Nullable Boolean remindMeLater) {
return invokeMethodOf(actions).acknowledge(ackRef, ackType, remindMeLater);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).acknowledge(ackRef, ackType, remindMeLater);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
@ -140,8 +117,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
* @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/ControlPlug.shtml">Control
* Plug</a>
*/
@Override
@RuleAction(label = "Control Plug", description = "Control the on/off state of a plug by setting a hold on the plug.")
@RuleAction(label = "control a plug", description = "Control the on/off state of a plug by setting a hold on the plug.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean controlPlug(
@ActionInput(name = "plugName", description = "The name of the plug. Ensure each plug has a unique name.") @Nullable String plugName,
@ActionInput(name = "plugState", description = "The state to put the plug into. Valid values: on, off, resume.") @Nullable String plugState,
@ -164,8 +140,12 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
public static boolean controlPlug(@Nullable ThingActions actions, @Nullable String plugName,
@Nullable String plugState, @Nullable Date startDateTime, @Nullable Date endDateTime,
@Nullable String holdType, @Nullable Number holdHours) {
return invokeMethodOf(actions).controlPlug(plugName, plugState, startDateTime, endDateTime, holdType,
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).controlPlug(plugName, plugState, startDateTime, endDateTime, holdType,
holdHours);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
@ -174,8 +154,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
* @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/CreateVacation.shtml">Create
* Vacation</a>
*/
@Override
@RuleAction(label = "Create Vacation", description = "The create vacation function creates a vacation event on the thermostat.")
@RuleAction(label = "create a vacation", description = "The create vacation function creates a vacation event on the thermostat.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean createVacation(
@ActionInput(name = "name", description = "The vacation event name. It must be unique.") @Nullable String name,
@ActionInput(name = "coolHoldTemp", description = "The temperature at which to set the cool vacation hold.") @Nullable QuantityType<Temperature> coolHoldTemp,
@ -200,8 +179,12 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
@Nullable QuantityType<Temperature> coolHoldTemp, @Nullable QuantityType<Temperature> heatHoldTemp,
@Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String fan,
@Nullable Number fanMinOnTime) {
return invokeMethodOf(actions).createVacation(name, coolHoldTemp, heatHoldTemp, startDateTime, endDateTime, fan,
fanMinOnTime);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).createVacation(name, coolHoldTemp, heatHoldTemp, startDateTime,
endDateTime, fan, fanMinOnTime);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
@ -210,8 +193,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
* @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/DeleteVacation.shtml">Delete
* Vacation</a>
*/
@Override
@RuleAction(label = "Delete Vacation", description = "The delete vacation function deletes a vacation event from a thermostat.")
@RuleAction(label = "delete a vacation", description = "The delete vacation function deletes a vacation event from a thermostat.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean deleteVacation(
@ActionInput(name = "name", description = "The vacation event name to delete.") @Nullable String name) {
LOGGER.debug("EcobeeActions: Action 'Delete Vacation' called");
@ -225,7 +207,11 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
}
public static boolean deleteVacation(@Nullable ThingActions actions, @Nullable String name) {
return invokeMethodOf(actions).deleteVacation(name);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).deleteVacation(name);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
@ -234,8 +220,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
* @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/ResetPreferences.shtml">Reset
* Preferences</a>
*/
@Override
@RuleAction(label = "Reset Preferences", description = "The reset preferences function sets all of the user configurable settings back to the factory default values.")
@RuleAction(label = "reset the preferences", description = "The reset preferences function sets all of the user configurable settings back to the factory default values.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean resetPreferences() {
LOGGER.debug("EcobeeActions: Action 'Reset Preferences' called");
EcobeeThermostatBridgeHandler localHandler = handler;
@ -248,7 +233,11 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
}
public static boolean resetPreferences(@Nullable ThingActions actions) {
return invokeMethodOf(actions).resetPreferences();
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).resetPreferences();
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
@ -257,8 +246,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
* @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/ResumeProgram.shtml">Resume
* Program</a>
*/
@Override
@RuleAction(label = "Resume Program", description = "Removes the currently running event providing the event is not a mandatory demand response event")
@RuleAction(label = "resume the program", description = "Removes the currently running event providing the event is not a mandatory demand response event")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean resumeProgram(
@ActionInput(name = "resumeAll", description = "(opt) Should the thermostat be resumed to next event (false) or to its program (true)") @Nullable Boolean resumeAll) {
LOGGER.debug("EcobeeActions: Action 'Resume Program' called");
@ -272,7 +260,11 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
}
public static boolean resumeProgram(@Nullable ThingActions actions, @Nullable Boolean resumeAll) {
return invokeMethodOf(actions).resumeProgram(resumeAll);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).resumeProgram(resumeAll);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
@ -281,8 +273,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
* @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/SendMessage.shtml">Send
* Message</a>
*/
@Override
@RuleAction(label = "Send Message", description = "The send message function allows an alert message to be sent to the thermostat.")
@RuleAction(label = "send a message", description = "The send message function allows an alert message to be sent to the thermostat.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendMessage(
@ActionInput(name = "text", description = "The message text to send. Text will be truncated to 500 characters if longer") @Nullable String text) {
LOGGER.debug("EcobeeActions: Action 'SendMessage' called");
@ -296,7 +287,11 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
}
public static boolean sendMessage(@Nullable ThingActions actions, @Nullable String text) {
return invokeMethodOf(actions).sendMessage(text);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).sendMessage(text);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
@ -304,8 +299,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
*
* @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/SetHold.shtml">Set Hold</a>
*/
@Override
@RuleAction(label = "Set Hold", description = "The set hold function sets the thermostat into a hold with the specified temperatures.")
@RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified temperatures.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold(
@ActionInput(name = "coolHoldTemp", description = "The temperature at which to set the cool hold.") @Nullable QuantityType<Temperature> coolHoldTemp,
@ActionInput(name = "heatHoldTemp", description = "The temperature at which to set the heat hold.") @Nullable QuantityType<Temperature> heatHoldTemp) {
@ -320,14 +314,17 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
public static boolean setHold(@Nullable ThingActions actions, @Nullable QuantityType<Temperature> coolHoldTemp,
@Nullable QuantityType<Temperature> heatHoldTemp) {
return invokeMethodOf(actions).setHold(coolHoldTemp, heatHoldTemp);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
* Set a hold by providing the cool and heat temperatures and the number of hours.
*/
@Override
@RuleAction(label = "Set Hold", description = "The set hold function sets the thermostat into a hold for the specified number of hours.")
@RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold for the specified number of hours.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold(
@ActionInput(name = "coolHoldTemp", description = "The temperature at which to set the cool hold.") @Nullable QuantityType<Temperature> coolHoldTemp,
@ActionInput(name = "heatHoldTemp", description = "The temperature at which to set the heat hold.") @Nullable QuantityType<Temperature> heatHoldTemp,
@ -348,14 +345,17 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
public static boolean setHold(@Nullable ThingActions actions, @Nullable QuantityType<Temperature> coolHoldTemp,
@Nullable QuantityType<Temperature> heatHoldTemp, @Nullable Number holdHours) {
return invokeMethodOf(actions).setHold(coolHoldTemp, heatHoldTemp, holdHours);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp, holdHours);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
* Set an indefinite hold using the supplied climateRef
*/
@Override
@RuleAction(label = "Set Hold", description = "The set hold function sets the thermostat into a hold with the specified climate ref.")
@RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified climate ref.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold(
@ActionInput(name = "holdClimateRef", description = "The holdClimateRef used to set the hold.") @Nullable String holdClimateRef) {
EcobeeThermostatBridgeHandler localHandler = handler;
@ -372,14 +372,17 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
}
public static boolean setHold(@Nullable ThingActions actions, @Nullable String holdClimateRef) {
return invokeMethodOf(actions).setHold(holdClimateRef);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).setHold(holdClimateRef);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
* Set a hold using the supplied climateRef for the supplied number of hours.
*/
@Override
@RuleAction(label = "Set Hold", description = "The set hold function sets the thermostat into a hold with the specified climate ref.")
@RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified climate ref.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold(
@ActionInput(name = "holdClimateRef", description = "The holdClimateRef used to set the hold.") @Nullable String holdClimateRef,
@ActionInput(name = "holdHours", description = "The number of hours for the hold.") @Nullable Number holdHours) {
@ -403,14 +406,17 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
public static boolean setHold(@Nullable ThingActions actions, @Nullable String holdClimateRef,
@Nullable Number holdHours) {
return invokeMethodOf(actions).setHold(holdClimateRef, holdHours);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).setHold(holdClimateRef, holdHours);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
* Set a hold
*/
@Override
@RuleAction(label = "Set Hold", description = "The set hold function sets the thermostat into a hold with the specified temperature or climate ref.")
@RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified temperature or climate ref.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold(
@ActionInput(name = "coolHoldTemp", description = "(opt) The temperature at which to set the cool hold.") @Nullable QuantityType<Temperature> coolHoldTemp,
@ActionInput(name = "heatHoldTemp", description = "(opt) The temperature at which to set the heat hold.") @Nullable QuantityType<Temperature> heatHoldTemp,
@ -436,15 +442,18 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
@Nullable QuantityType<Temperature> heatHoldTemp, @Nullable String holdClimateRef,
@Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType,
@Nullable Number holdHours) {
return invokeMethodOf(actions).setHold(coolHoldTemp, heatHoldTemp, holdClimateRef, startDateTime, endDateTime,
holdType, holdHours);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).setHold(coolHoldTemp, heatHoldTemp, holdClimateRef, startDateTime,
endDateTime, holdType, holdHours);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
* Set a hold by providing a parameter map
*/
@Override
@RuleAction(label = "Set Hold", description = "The set hold function sets the thermostat into a hold with the specified event parameters.")
@RuleAction(label = "set the thermostat into hold", description = "The set hold function sets the thermostat into a hold with the specified event parameters.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setHold(
@ActionInput(name = "params", description = "The map of hold parameters.") @Nullable Map<String, Object> params,
@ActionInput(name = "holdType", description = "(opt) The hold duration type. Valid values: dateTime, nextTransition, indefinite, holdHours.") @Nullable String holdType,
@ -522,7 +531,11 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
public static boolean setHold(@Nullable ThingActions actions, @Nullable Map<String, Object> params,
@Nullable String holdType, @Nullable Number holdHours, @Nullable Date startDateTime,
@Nullable Date endDateTime) {
return invokeMethodOf(actions).setHold(params, holdType, holdHours, startDateTime, endDateTime);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).setHold(params, holdType, holdHours, startDateTime, endDateTime);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
@ -532,8 +545,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
* @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/SetOccupied.shtml">Set
* Occupied</a>
*/
@Override
@RuleAction(label = "Set Occupied", description = "The function switches a thermostat from occupied mode to unoccupied, or vice versa (EMS MODELS ONLY).")
@RuleAction(label = "switch the thermostat occupancy", description = "The function switches a thermostat from occupied mode to unoccupied, or vice versa (EMS MODELS ONLY).")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean setOccupied(
@ActionInput(name = "occupied", description = "The climate to use for the temperature, occupied (true) or unoccupied (false).") @Nullable Boolean occupied,
@ActionInput(name = "startDateTime", description = "(opt) The start date in thermostat time.") @Nullable Date startDateTime,
@ -555,7 +567,11 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
public static boolean setOccupied(@Nullable ThingActions actions, @Nullable Boolean occupied,
@Nullable Date startDateTime, @Nullable Date endDateTime, @Nullable String holdType,
@Nullable Number holdHours) {
return invokeMethodOf(actions).setOccupied(occupied, startDateTime, endDateTime, holdType, holdHours);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).setOccupied(occupied, startDateTime, endDateTime, holdType, holdHours);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
@ -564,8 +580,7 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
* @see <a href="https://www.ecobee.com/home/developer/api/documentation/v1/functions/UpdateSensor.shtml">Update
* Sensor</a>
*/
@Override
@RuleAction(label = "Update Sensor", description = "The update sensor function allows the caller to update the name of an ecobee3 remote sensor.")
@RuleAction(label = "update a remote sensor name", description = "The update sensor function allows the caller to update the name of an ecobee3 remote sensor.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean updateSensor(
@ActionInput(name = "name", description = "The updated name to give the sensor. Has a max length of 32, but shorter is recommended.") @Nullable String name,
@ActionInput(name = "deviceId", description = "The deviceId for the sensor, typically this indicates the enclosure and corresponds to the ThermostatRemoteSensor.id field. For example: rs:100") @Nullable String deviceId,
@ -582,14 +597,17 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
public static boolean updateSensor(@Nullable ThingActions actions, @Nullable String name, @Nullable String deviceId,
@Nullable String sensorId) {
return invokeMethodOf(actions).updateSensor(name, deviceId, sensorId);
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).updateSensor(name, deviceId, sensorId);
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
* Get the alerts list. Returns a JSON string containing all the alerts.
*/
@Override
@RuleAction(label = "Get Alerts", description = "Get the alerts list")
@RuleAction(label = "get the alerts", description = "Get the alerts list.")
public @ActionOutput(name = "alerts", type = "java.lang.String") @Nullable String getAlerts() {
LOGGER.debug("EcobeeActions: Action 'Get Alerts' called");
EcobeeThermostatBridgeHandler localHandler = handler;
@ -601,14 +619,17 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
}
public static @Nullable String getAlerts(@Nullable ThingActions actions) {
return invokeMethodOf(actions).getAlerts();
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).getAlerts();
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
* Get the events list. Returns a JSON string contains all events.
*/
@Override
@RuleAction(label = "Get Events", description = "Get the events list")
@RuleAction(label = "get the events", description = "Get the events list.")
public @ActionOutput(name = "events", type = "java.lang.String") @Nullable String getEvents() {
LOGGER.debug("EcobeeActions: Action 'Get Events' called");
EcobeeThermostatBridgeHandler localHandler = handler;
@ -620,14 +641,17 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
}
public static @Nullable String getEvents(@Nullable ThingActions actions) {
return invokeMethodOf(actions).getEvents();
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).getEvents();
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
/**
* Get a list of climates. Returns a JSON string contains all climates.
*/
@Override
@RuleAction(label = "Get Climates", description = "Get a list of climates")
@RuleAction(label = "get the climates", description = "Get a list of climates.")
public @ActionOutput(name = "climates", type = "java.lang.String") @Nullable String getClimates() {
LOGGER.debug("EcobeeActions: Action 'Get Climates' called");
EcobeeThermostatBridgeHandler localHandler = handler;
@ -639,6 +663,10 @@ public class EcobeeActions implements ThingActions, IEcobeeActions {
}
public static @Nullable String getClimates(@Nullable ThingActions actions) {
return invokeMethodOf(actions).getClimates();
if (actions instanceof EcobeeActions) {
return ((EcobeeActions) actions).getClimates();
} else {
throw new IllegalArgumentException("Actions is not an instance of EcobeeActions");
}
}
}

View File

@ -32,7 +32,7 @@ import javax.measure.Unit;
import org.apache.commons.lang.WordUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.ecobee.action.EcobeeActions;
import org.openhab.binding.ecobee.internal.action.EcobeeActions;
import org.openhab.binding.ecobee.internal.api.EcobeeApi;
import org.openhab.binding.ecobee.internal.config.EcobeeThermostatConfiguration;
import org.openhab.binding.ecobee.internal.discovery.SensorDiscoveryService;

View File

@ -1,41 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.enigma2.actions;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* The {@link IEnigma2Actions} defines the interface for all thing actions supported by the binding.
*
* @author Guido Dolfen - Initial contribution
*/
@NonNullByDefault
public interface IEnigma2Actions {
void sendRcCommand(String rcButton);
void sendInfo(String text);
void sendInfo(String text, int timeout);
void sendWarning(String text);
void sendWarning(String text, int timeout);
void sendError(String text);
void sendError(String text, int timeout);
void sendQuestion(String text);
void sendQuestion(String text, int timeout);
}

View File

@ -16,7 +16,7 @@ import static org.openhab.binding.enigma2.internal.Enigma2BindingConstants.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enigma2.handler.Enigma2Handler;
import org.openhab.binding.enigma2.internal.handler.Enigma2Handler;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.binding.BaseThingHandlerFactory;

View File

@ -10,15 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.enigma2.actions;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
package org.openhab.binding.enigma2.internal.actions;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enigma2.handler.Enigma2Handler;
import org.openhab.binding.enigma2.internal.Enigma2BindingConstants;
import org.openhab.binding.enigma2.internal.handler.Enigma2Handler;
import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.RuleAction;
import org.openhab.core.thing.binding.ThingActions;
@ -33,7 +30,7 @@ import org.openhab.core.thing.binding.ThingHandler;
*/
@ThingActionsScope(name = "enigma2")
@NonNullByDefault
public class Enigma2Actions implements ThingActions, IEnigma2Actions {
public class Enigma2Actions implements ThingActions {
private @Nullable Enigma2Handler handler;
@Override
@ -43,10 +40,9 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions {
@Override
public @Nullable Enigma2Handler getThingHandler() {
return this.handler;
return handler;
}
@Override
@RuleAction(label = "@text/actions.enigma2.send-rc-button.label", description = "@text/actions.enigma2.send-rc-button.description")
@SuppressWarnings("null")
public void sendRcCommand(
@ -54,7 +50,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions {
handler.sendRcCommand(rcButton);
}
@Override
@RuleAction(label = "@text/actions.enigma2.send-info.label", description = "@text/actions.enigma2.send-info.description")
@SuppressWarnings("null")
public void sendInfo(
@ -62,7 +57,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions {
handler.sendInfo(Enigma2BindingConstants.MESSAGE_TIMEOUT, text);
}
@Override
@RuleAction(label = "@text/actions.enigma2.send-info.label", description = "@text/actions.enigma2.send-info.description")
@SuppressWarnings("null")
public void sendInfo(
@ -71,7 +65,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions {
handler.sendInfo(timeout, text);
}
@Override
@RuleAction(label = "@text/actions.enigma2.send-warning.label", description = "@text/actions.enigma2.send-warning.description")
@SuppressWarnings("null")
public void sendWarning(
@ -79,7 +72,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions {
handler.sendWarning(Enigma2BindingConstants.MESSAGE_TIMEOUT, text);
}
@Override
@RuleAction(label = "@text/actions.enigma2.send-warning.label", description = "@text/actions.enigma2.send-warning.description")
@SuppressWarnings("null")
public void sendWarning(
@ -88,7 +80,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions {
handler.sendWarning(timeout, text);
}
@Override
@RuleAction(label = "@text/actions.enigma2.send-error.label", description = "@text/actions.enigma2.send-error.description")
@SuppressWarnings("null")
public void sendError(
@ -96,7 +87,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions {
handler.sendError(Enigma2BindingConstants.MESSAGE_TIMEOUT, text);
}
@Override
@RuleAction(label = "@text/actions.enigma2.send-error.label", description = "@text/actions.enigma2.send-error.description")
@SuppressWarnings("null")
public void sendError(
@ -105,7 +95,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions {
handler.sendError(timeout, text);
}
@Override
@RuleAction(label = "@text/actions.enigma2.send-error.label", description = "@text/actions.enigma2.send-question.description")
@SuppressWarnings("null")
public void sendQuestion(
@ -113,7 +102,6 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions {
handler.sendQuestion(Enigma2BindingConstants.MESSAGE_TIMEOUT, text);
}
@Override
@RuleAction(label = "@text/actions.enigma2.send-error.label", description = "@text/actions.enigma2.send-question.description")
@SuppressWarnings("null")
public void sendQuestion(
@ -124,57 +112,74 @@ public class Enigma2Actions implements ThingActions, IEnigma2Actions {
// delegation methods for "legacy" rule support
public static void sendRcCommand(@Nullable ThingActions actions, String rcButton) {
invokeMethodOf(actions).sendRcCommand(rcButton);
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendRcCommand(rcButton);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
}
public static void sendInfo(@Nullable ThingActions actions, String info) {
invokeMethodOf(actions).sendInfo(info);
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendInfo(info);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
}
public static void sendInfo(@Nullable ThingActions actions, String info, int timeout) {
invokeMethodOf(actions).sendInfo(info, timeout);
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendInfo(info, timeout);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
}
public static void sendWarning(@Nullable ThingActions actions, String warning) {
invokeMethodOf(actions).sendWarning(warning);
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendWarning(warning);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
}
public static void sendWarning(@Nullable ThingActions actions, String warning, int timeout) {
invokeMethodOf(actions).sendWarning(warning, timeout);
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendWarning(warning, timeout);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
}
public static void sendError(@Nullable ThingActions actions, String error) {
invokeMethodOf(actions).sendError(error);
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendError(error);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
}
public static void sendError(@Nullable ThingActions actions, String error, int timeout) {
invokeMethodOf(actions).sendError(error, timeout);
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendError(error, timeout);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
}
public static void sendQuestion(@Nullable ThingActions actions, String text) {
invokeMethodOf(actions).sendQuestion(text);
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendQuestion(text);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
}
public static void sendQuestion(@Nullable ThingActions actions, String text, int timeout) {
invokeMethodOf(actions).sendQuestion(text, timeout);
}
private static IEnigma2Actions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(Enigma2Actions.class.getName())) {
if (actions instanceof IEnigma2Actions) {
return (IEnigma2Actions) actions;
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendQuestion(text, timeout);
} else {
return (IEnigma2Actions) Proxy.newProxyInstance(IEnigma2Actions.class.getClassLoader(),
new Class[] { IEnigma2Actions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
}
}

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.enigma2.handler;
package org.openhab.binding.enigma2.internal.handler;
import static org.openhab.binding.enigma2.internal.Enigma2BindingConstants.*;
@ -25,10 +25,10 @@ import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enigma2.actions.Enigma2Actions;
import org.openhab.binding.enigma2.internal.Enigma2Client;
import org.openhab.binding.enigma2.internal.Enigma2Configuration;
import org.openhab.binding.enigma2.internal.Enigma2RemoteKey;
import org.openhab.binding.enigma2.internal.actions.Enigma2Actions;
import org.openhab.core.library.types.*;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.enigma2.actions;
package org.openhab.binding.enigma2.internal.actions;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@ -21,8 +21,8 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.enigma2.handler.Enigma2Handler;
import org.openhab.binding.enigma2.internal.Enigma2BindingConstants;
import org.openhab.binding.enigma2.internal.handler.Enigma2Handler;
/**
* The {@link Enigma2ActionsTest} class is responsible for testing {@link Enigma2Actions}.

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.enigma2.handler;
package org.openhab.binding.enigma2.internal.handler;
import static org.eclipse.jdt.annotation.Checks.requireNonNull;
import static org.hamcrest.MatcherAssert.assertThat;
@ -25,11 +25,11 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.enigma2.actions.Enigma2Actions;
import org.openhab.binding.enigma2.internal.Enigma2BindingConstants;
import org.openhab.binding.enigma2.internal.Enigma2Client;
import org.openhab.binding.enigma2.internal.Enigma2Configuration;
import org.openhab.binding.enigma2.internal.Enigma2RemoteKey;
import org.openhab.binding.enigma2.internal.actions.Enigma2Actions;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.NextPreviousType;

View File

@ -1,28 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.gce.internal.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link IIpx800Actions} defines the interface for all thing actions supported by the binding.
*
* @author Gaël L'hopital - Initial contribution
*/
@NonNullByDefault
public interface IIpx800Actions {
public void resetCounter(Integer counter);
public void reset(@Nullable Integer placeholder);
}

View File

@ -12,9 +12,6 @@
*/
package org.openhab.binding.gce.internal.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.gce.internal.handler.Ipx800v3Handler;
@ -27,18 +24,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {Ipx800Actions } defines rule actions for the GCE binding.
* <p>
* <b>Note:</b>The static method <b>invokeMethodOf</b> handles the case where
* the test <i>actions instanceof Ipx800Actions</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link Ipx800Actions} class
* can be loaded by a different classloader than the <i>actions</i> instance.
* Defines rule actions for the GCE binding.
*
* @author Gaël L'hopital - Initial contribution
*/
@ThingActionsScope(name = "gce")
@NonNullByDefault
public class Ipx800Actions implements ThingActions, IIpx800Actions {
public class Ipx800Actions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(Ipx800Actions.class);
protected @Nullable Ipx800v3Handler handler;
@ -56,11 +48,10 @@ public class Ipx800Actions implements ThingActions, IIpx800Actions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
return handler;
}
@Override
@RuleAction(label = "GCE : Reset counter", description = "Resets to 0 value of a given counter")
@RuleAction(label = "reset a counter", description = "Resets to 0 value of a given counter.")
public void resetCounter(
@ActionInput(name = "counter", label = "Counter", required = true, description = "Id of the counter", type = "java.lang.Integer") Integer counter) {
logger.debug("IPX800 action 'resetCounter' called");
@ -72,8 +63,7 @@ public class Ipx800Actions implements ThingActions, IIpx800Actions {
}
}
@Override
@RuleAction(label = "GCE : Reset PLC", description = "Restarts the IPX800")
@RuleAction(label = "reset the PLC", description = "Restarts the IPX800.")
public void reset(
@ActionInput(name = "placeholder", label = "Placeholder", required = false, description = "This parameter is not used", type = "java.lang.Integer") @Nullable Integer placeholder) {
logger.debug("IPX800 action 'reset' called");
@ -86,29 +76,18 @@ public class Ipx800Actions implements ThingActions, IIpx800Actions {
}
public static void resetCounter(@Nullable ThingActions actions, Integer counter) {
invokeMethodOf(actions).resetCounter(counter);
if (actions instanceof Ipx800Actions) {
((Ipx800Actions) actions).resetCounter(counter);
} else {
throw new IllegalArgumentException("Actions is not an instance of Ipx800Actions");
}
}
public static void reset(@Nullable ThingActions actions, @Nullable Integer placeholder) {
invokeMethodOf(actions).reset(placeholder);
}
private static IIpx800Actions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(Ipx800Actions.class.getName())) {
if (actions instanceof IIpx800Actions) {
return (IIpx800Actions) actions;
if (actions instanceof Ipx800Actions) {
((Ipx800Actions) actions).reset(placeholder);
} else {
return (IIpx800Actions) Proxy.newProxyInstance(IIpx800Actions.class.getClassLoader(),
new Class[] { IIpx800Actions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of Ipx800Actions");
}
}
}

View File

@ -13,8 +13,6 @@
package org.openhab.binding.heos.internal.action;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -32,17 +30,12 @@ import org.slf4j.LoggerFactory;
/**
* The class is responsible to call corresponding action on HEOS Handler
* <p>
* <b>Note:</b>The static method <b>invokeMethodOf</b> handles the case where
* the test <i>actions instanceof HeosActions</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link HeosActions} class
* can be loaded by a different classloader than the <i>actions</i> instance.
*
* @author Martin van Wingerden - Initial contribution
*/
@ThingActionsScope(name = "heos")
@NonNullByDefault
public class HeosActions implements ThingActions, IHeosActions {
public class HeosActions implements ThingActions {
private final static Logger logger = LoggerFactory.getLogger(HeosActions.class);
@ -57,10 +50,11 @@ public class HeosActions implements ThingActions, IHeosActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
return handler;
}
private @Nullable HeosFacade getConnection() throws HeosNotConnectedException {
HeosBridgeHandler handler = this.handler;
if (handler == null) {
return null;
}
@ -68,7 +62,6 @@ public class HeosActions implements ThingActions, IHeosActions {
return handler.getApiConnection();
}
@Override
@RuleAction(label = "Play Input", description = "Play an input from another device")
public void playInputFromPlayer(
@ActionInput(name = "source", label = "Source Player", description = "Player used for input") @Nullable Integer sourcePlayer,
@ -97,25 +90,10 @@ public class HeosActions implements ThingActions, IHeosActions {
public static void playInputFromPlayer(@Nullable ThingActions actions, @Nullable Integer sourcePlayer,
@Nullable String input, @Nullable Integer destinationPlayer) {
invokeMethodOf(actions).playInputFromPlayer(sourcePlayer, input, destinationPlayer);
}
private static IHeosActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(HeosActions.class.getName())) {
if (actions instanceof IHeosActions) {
return (IHeosActions) actions;
if (actions instanceof HeosActions) {
((HeosActions) actions).playInputFromPlayer(sourcePlayer, input, destinationPlayer);
} else {
return (IHeosActions) Proxy.newProxyInstance(IHeosActions.class.getClassLoader(),
new Class[] { IHeosActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of HeosActions");
}
}
}

View File

@ -1,28 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.heos.internal.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link IHeosActions} defines the interface for all thing actions supported by the binding.
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public interface IHeosActions {
public void playInputFromPlayer(@Nullable Integer sourcePlayer, @Nullable String input,
@Nullable Integer destinationPlayer);
}

View File

@ -1,29 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.hue.internal.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.types.Command;
/**
* The {@link ILightActions} defines the interface for all thing actions supported by the binding.
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public interface ILightActions {
public void fadingLightCommand(@Nullable String channel, @Nullable Command command, @Nullable DecimalType fadeTime);
}

View File

@ -12,9 +12,6 @@
*/
package org.openhab.binding.hue.internal.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.hue.internal.handler.HueLightHandler;
@ -30,18 +27,13 @@ import org.slf4j.LoggerFactory;
/**
* The {@link LightActions} defines the thing actions for the hue binding.
* <p>
* <b>Note:</b>The static method <b>invokeMethodOf</b> handles the case where
* the test <i>actions instanceof LightActions</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link LightActions} class
* can be loaded by a different classloader than the <i>actions</i> instance.
*
* @author Jochen Leopold - Initial contribution
* @author Laurent Garnier - new method invokeMethodOf + interface ILightActions
*/
@ThingActionsScope(name = "hue")
@NonNullByDefault
public class LightActions implements ThingActions, ILightActions {
public class LightActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(LightActions.class);
private @Nullable HueLightHandler handler;
@ -52,10 +44,9 @@ public class LightActions implements ThingActions, ILightActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
return handler;
}
@Override
@RuleAction(label = "@text/actionLabel", description = "@text/actionDesc")
public void fadingLightCommand(
@ActionInput(name = "channel", label = "@text/actionInputChannelLabel", description = "@text/actionInputChannelDesc") @Nullable String channel,
@ -85,27 +76,12 @@ public class LightActions implements ThingActions, ILightActions {
logger.debug("send LightAction to {} with {}ms of fadeTime", channel, fadeTime);
}
private static ILightActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(LightActions.class.getName())) {
if (actions instanceof ILightActions) {
return (ILightActions) actions;
} else {
return (ILightActions) Proxy.newProxyInstance(ILightActions.class.getClassLoader(),
new Class[] { ILightActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of LightActions");
}
public static void fadingLightCommand(@Nullable ThingActions actions, @Nullable String channel,
@Nullable Command command, @Nullable DecimalType fadeTime) {
invokeMethodOf(actions).fadingLightCommand(channel, command, fadeTime);
if (actions instanceof LightActions) {
((LightActions) actions).fadingLightCommand(channel, command, fadeTime);
} else {
throw new IllegalArgumentException("Actions is not an instance of LightActions");
}
}
}

View File

@ -1,27 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.kaleidescape.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* The {@link IKaleidescapeThingActions} defines the interface for all thing actions supported by the binding.
* These methods, parameters, and return types are explained in {@link KaleidescapeThingActions}.
*
* @author Michael Lobstein - Initial contribution
*/
@NonNullByDefault
public interface IKaleidescapeThingActions {
void sendKCommand(String kCommand);
}

View File

@ -12,9 +12,6 @@
*/
package org.openhab.binding.kaleidescape.internal;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.kaleidescape.internal.handler.KaleidescapeHandler;
@ -30,16 +27,15 @@ import org.slf4j.LoggerFactory;
* Some automation actions to be used with a {@link KaleidescapeThingActions}
*
* @author Michael Lobstein - initial contribution
*
*/
@ThingActionsScope(name = "kaleidescape")
@NonNullByDefault
public class KaleidescapeThingActions implements ThingActions, IKaleidescapeThingActions {
public class KaleidescapeThingActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(KaleidescapeThingActions.class);
private @Nullable KaleidescapeHandler handler;
@RuleAction(label = "sendKCommand", description = "Action that sends raw command to the kaleidescape zone")
@RuleAction(label = "send a raw command", description = "Action that sends raw command to the kaleidescape zone.")
public void sendKCommand(@ActionInput(name = "sendKCommand") String kCommand) {
KaleidescapeHandler localHandler = handler;
if (localHandler != null) {
@ -52,7 +48,11 @@ public class KaleidescapeThingActions implements ThingActions, IKaleidescapeThin
/** Static alias to support the old DSL rules engine and make the action available there. */
public static void sendKCommand(@Nullable ThingActions actions, String kCommand) throws IllegalArgumentException {
invokeMethodOf(actions).sendKCommand(kCommand);
if (actions instanceof KaleidescapeThingActions) {
((KaleidescapeThingActions) actions).sendKCommand(kCommand);
} else {
throw new IllegalArgumentException("Actions is not an instance of KaleidescapeThingActions");
}
}
@Override
@ -62,27 +62,6 @@ public class KaleidescapeThingActions implements ThingActions, IKaleidescapeThin
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
}
private static IKaleidescapeThingActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(KaleidescapeThingActions.class.getName())) {
if (actions instanceof KaleidescapeThingActions) {
return (IKaleidescapeThingActions) actions;
} else {
return (IKaleidescapeThingActions) Proxy.newProxyInstance(
IKaleidescapeThingActions.class.getClassLoader(),
new Class[] { IKaleidescapeThingActions.class },
(Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of KaleidescapeThingActions");
return handler;
}
}

View File

@ -1,33 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lcn.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link ILcnModuleActions} defines the interface for all thing actions supported by the binding.
* These methods, parameters, and return types are explained in {@link LcnModuleActions}.
*
* @author Fabian Wolter - Initial contribution
*/
@NonNullByDefault
public interface ILcnModuleActions {
void hitKey(@Nullable String table, int key, @Nullable String action);
void flickerOutput(int output, int depth, int ramp, int count);
void sendDynamicText(int row, @Nullable String textInput);
void startRelayTimer(int relaynumber, double duration);
}

View File

@ -12,8 +12,6 @@
*/
package org.openhab.binding.lcn.internal;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.nio.ByteBuffer;
import java.util.Arrays;
@ -40,7 +38,7 @@ import org.slf4j.LoggerFactory;
*/
@ThingActionsScope(name = "lcn")
@NonNullByDefault
public class LcnModuleActions implements ThingActions, ILcnModuleActions {
public class LcnModuleActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(LcnModuleActions.class);
private static final int DYN_TEXT_CHUNK_COUNT = 5;
private static final int DYN_TEXT_HEADER_LENGTH = 6;
@ -57,8 +55,7 @@ public class LcnModuleActions implements ThingActions, ILcnModuleActions {
return moduleHandler;
}
@Override
@RuleAction(label = "LCN Hit Key", description = "Sends a \"hit key\" command to an LCN module")
@RuleAction(label = "send a hit key command", description = "Sends a \"hit key\" command to an LCN module.")
public void hitKey(
@ActionInput(name = "table", required = true, type = "java.lang.String", label = "Table", description = "The key table (A-D)") @Nullable String table,
@ActionInput(name = "key", required = true, type = "java.lang.Integer", label = "Key", description = "The key number (1-8)") int key,
@ -104,8 +101,7 @@ public class LcnModuleActions implements ThingActions, ILcnModuleActions {
}
}
@Override
@RuleAction(label = "LCN Flicker Output", description = "Let a dimmer output flicker for a given count of flashes")
@RuleAction(label = "flicker a dimmer output", description = "Let a dimmer output flicker for a given count of flashes.")
public void flickerOutput(
@ActionInput(name = "output", type = "java.lang.Integer", required = true, label = "Output", description = "The output number (1-4)") int output,
@ActionInput(name = "depth", type = "java.lang.Integer", label = "Depth", description = "0=25% 1=50% 2=100%") int depth,
@ -118,8 +114,7 @@ public class LcnModuleActions implements ThingActions, ILcnModuleActions {
}
}
@Override
@RuleAction(label = "LCN Dynamic Text", description = "Send custom text to an LCN-GTxD display")
@RuleAction(label = "send a custom text", description = "Send custom text to an LCN-GTxD display.")
public void sendDynamicText(
@ActionInput(name = "row", type = "java.lang.Integer", required = true, label = "Row", description = "Display the text on the LCN-GTxD in the given row number (1-4)") int row,
@ActionInput(name = "text", type = "java.lang.String", label = "Text", description = "The text to display (max. 60 chars/bytes)") @Nullable String textInput) {
@ -162,8 +157,7 @@ public class LcnModuleActions implements ThingActions, ILcnModuleActions {
* @param relaynumber 1-based number of the relay to use
* @param duration duration of the relay timer in milliseconds
*/
@Override
@RuleAction(label = "LCN Relay Timer", description = "Start an LCN relay timer")
@RuleAction(label = "start a relay timer", description = "Start an LCN relay timer.")
public void startRelayTimer(
@ActionInput(name = "relaynumber", required = true, type = "java.lang.Integer", label = "Relay Number", description = "The relay number (1-8)") int relayNumber,
@ActionInput(name = "duration", required = true, type = "java.lang.Double", label = "Duration [ms]", description = "The timer duration in milliseconds") double duration) {
@ -174,44 +168,41 @@ public class LcnModuleActions implements ThingActions, ILcnModuleActions {
}
}
private static ILcnModuleActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(LcnModuleActions.class.getName())) {
if (actions instanceof LcnModuleActions) {
return (ILcnModuleActions) actions;
} else {
return (ILcnModuleActions) Proxy.newProxyInstance(ILcnModuleActions.class.getClassLoader(),
new Class[] { ILcnModuleActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions");
}
/** Static alias to support the old DSL rules engine and make the action available there. */
public static void hitKey(@Nullable ThingActions actions, @Nullable String table, int key,
@Nullable String action) {
invokeMethodOf(actions).hitKey(table, key, action);
if (actions instanceof LcnModuleHandler) {
((LcnModuleActions) actions).hitKey(table, key, action);
} else {
throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions");
}
}
/** Static alias to support the old DSL rules engine and make the action available there. */
public static void flickerOutput(@Nullable ThingActions actions, int output, int depth, int ramp, int count) {
invokeMethodOf(actions).flickerOutput(output, depth, ramp, count);
if (actions instanceof LcnModuleHandler) {
((LcnModuleActions) actions).flickerOutput(output, depth, ramp, count);
} else {
throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions");
}
}
/** Static alias to support the old DSL rules engine and make the action available there. */
public static void sendDynamicText(@Nullable ThingActions actions, int row, @Nullable String text) {
invokeMethodOf(actions).sendDynamicText(row, text);
if (actions instanceof LcnModuleHandler) {
((LcnModuleActions) actions).sendDynamicText(row, text);
} else {
throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions");
}
}
/** Static alias to support the old DSL rules engine and make the action available there. */
public static void startRelayTimer(@Nullable ThingActions actions, int relaynumber, double duration) {
invokeMethodOf(actions).startRelayTimer(relaynumber, duration);
if (actions instanceof LcnModuleHandler) {
((LcnModuleActions) actions).startRelayTimer(relaynumber, duration);
} else {
throw new IllegalArgumentException("Actions is not an instance of LcnModuleActions");
}
}
private LcnModuleHandler getHandler() throws LcnException {

View File

@ -1,46 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lgwebos.action;
import java.io.IOException;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* The {@link ILGWebOSActions} defines the interface for all thing actions supported by the binding.
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public interface ILGWebOSActions {
public void showToast(String text) throws IOException;
public void showToast(String icon, String text) throws IOException;
public void launchBrowser(String url);
public void launchApplication(String appId);
public void launchApplication(String appId, String params);
public void sendText(String text);
public void sendButton(String button);
public void increaseChannel();
public void decreaseChannel();
public void sendRCButton(String rcButton);
}

View File

@ -10,14 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lgwebos.action;
package org.openhab.binding.lgwebos.internal.action;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
@ -53,18 +51,13 @@ import com.google.gson.JsonParser;
/**
* The {@link LGWebOSActions} defines the thing actions for the LGwebOS binding.
* <p>
* <b>Note:</b>The static method <b>invokeMethodOf</b> handles the case where
* the test <i>actions instanceof LGWebOSActions</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link LGWebOSActions} class
* can be loaded by a different classloader than the <i>actions</i> instance.
*
* @author Sebastian Prehn - Initial contribution
* @author Laurent Garnier - new method invokeMethodOf + interface ILGWebOSActions
*/
@ThingActionsScope(name = "lgwebos")
@NonNullByDefault
public class LGWebOSActions implements ThingActions, ILGWebOSActions {
public class LGWebOSActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(LGWebOSActions.class);
private final ResponseListener<TextInputStatusInfo> textInputListener = createTextInputStatusListener();
private @Nullable LGWebOSHandler handler;
@ -76,7 +69,7 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
return handler;
}
// a NonNull getter for handler
@ -101,7 +94,6 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions {
OK
}
@Override
@RuleAction(label = "@text/actionShowToastLabel", description = "@text/actionShowToastDesc")
public void showToast(
@ActionInput(name = "text", label = "@text/actionShowToastInputTextLabel", description = "@text/actionShowToastInputTextDesc") String text)
@ -109,7 +101,6 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions {
getConnectedSocket().ifPresent(control -> control.showToast(text, createResponseListener()));
}
@Override
@RuleAction(label = "@text/actionShowToastWithIconLabel", description = "@text/actionShowToastWithIconLabel")
public void showToast(
@ActionInput(name = "icon", label = "@text/actionShowToastInputIconLabel", description = "@text/actionShowToastInputIconDesc") String icon,
@ -123,7 +114,6 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions {
}
}
@Override
@RuleAction(label = "@text/actionLaunchBrowserLabel", description = "@text/actionLaunchBrowserDesc")
public void launchBrowser(
@ActionInput(name = "url", label = "@text/actionLaunchBrowserInputUrlLabel", description = "@text/actionLaunchBrowserInputUrlDesc") String url) {
@ -146,7 +136,6 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions {
return appInfos;
}
@Override
@RuleAction(label = "@text/actionLaunchApplicationLabel", description = "@text/actionLaunchApplicationDesc")
public void launchApplication(
@ActionInput(name = "appId", label = "@text/actionLaunchApplicationInputAppIDLabel", description = "@text/actionLaunchApplicationInputAppIDDesc") String appId) {
@ -160,7 +149,6 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions {
}
}
@Override
@RuleAction(label = "@text/actionLaunchApplicationWithParamsLabel", description = "@text/actionLaunchApplicationWithParamsDesc")
public void launchApplication(
@ActionInput(name = "appId", label = "@text/actionLaunchApplicationInputAppIDLabel", description = "@text/actionLaunchApplicationInputAppIDDesc") String appId,
@ -184,7 +172,6 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions {
}
}
@Override
@RuleAction(label = "@text/actionSendTextLabel", description = "@text/actionSendTextDesc")
public void sendText(
@ActionInput(name = "text", label = "@text/actionSendTextInputTextLabel", description = "@text/actionSendTextInputTextDesc") String text) {
@ -195,7 +182,6 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions {
});
}
@Override
@RuleAction(label = "@text/actionSendButtonLabel", description = "@text/actionSendButtonDesc")
public void sendButton(
@ActionInput(name = "text", label = "@text/actionSendButtonInputButtonLabel", description = "@text/actionSendButtonInputButtonDesc") String button) {
@ -235,19 +221,16 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions {
}
}
@Override
@RuleAction(label = "@text/actionIncreaseChannelLabel", description = "@text/actionIncreaseChannelDesc")
public void increaseChannel() {
getConnectedSocket().ifPresent(control -> control.channelUp(createResponseListener()));
}
@Override
@RuleAction(label = "@text/actionDecreaseChannelLabel", description = "@text/actionDecreaseChannelDesc")
public void decreaseChannel() {
getConnectedSocket().ifPresent(control -> control.channelDown(createResponseListener()));
}
@Override
@RuleAction(label = "@text/actionSendRCButtonLabel", description = "@text/actionSendRCButtonDesc")
public void sendRCButton(
@ActionInput(name = "text", label = "@text/actionSendRCButtonInputTextLabel", description = "@text/actionSendRCButtonInputTextDesc") String rcButton) {
@ -298,62 +281,83 @@ public class LGWebOSActions implements ThingActions, ILGWebOSActions {
// delegation methods for "legacy" rule support
private static ILGWebOSActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(LGWebOSActions.class.getName())) {
if (actions instanceof ILGWebOSActions) {
return (ILGWebOSActions) actions;
public static void showToast(@Nullable ThingActions actions, String text) throws IOException {
if (actions instanceof LGWebOSActions) {
((LGWebOSActions) actions).showToast(text);
} else {
return (ILGWebOSActions) Proxy.newProxyInstance(ILGWebOSActions.class.getClassLoader(),
new Class[] { ILGWebOSActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
public static void showToast(@Nullable ThingActions actions, String text) throws IOException {
invokeMethodOf(actions).showToast(text);
}
public static void showToast(@Nullable ThingActions actions, String icon, String text) throws IOException {
invokeMethodOf(actions).showToast(icon, text);
if (actions instanceof LGWebOSActions) {
((LGWebOSActions) actions).showToast(icon, text);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
}
public static void launchBrowser(@Nullable ThingActions actions, String url) {
invokeMethodOf(actions).launchBrowser(url);
if (actions instanceof LGWebOSActions) {
((LGWebOSActions) actions).launchBrowser(url);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
}
public static void launchApplication(@Nullable ThingActions actions, String appId) {
invokeMethodOf(actions).launchApplication(appId);
if (actions instanceof LGWebOSActions) {
((LGWebOSActions) actions).launchApplication(appId);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
}
public static void launchApplication(@Nullable ThingActions actions, String appId, String param) {
invokeMethodOf(actions).launchApplication(appId, param);
if (actions instanceof LGWebOSActions) {
((LGWebOSActions) actions).launchApplication(appId, param);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
}
public static void sendText(@Nullable ThingActions actions, String text) {
invokeMethodOf(actions).sendText(text);
if (actions instanceof LGWebOSActions) {
((LGWebOSActions) actions).sendText(text);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
}
public static void sendButton(@Nullable ThingActions actions, String button) {
invokeMethodOf(actions).sendButton(button);
if (actions instanceof LGWebOSActions) {
((LGWebOSActions) actions).sendButton(button);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
}
public static void increaseChannel(@Nullable ThingActions actions) {
invokeMethodOf(actions).increaseChannel();
if (actions instanceof LGWebOSActions) {
((LGWebOSActions) actions).increaseChannel();
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
}
public static void decreaseChannel(@Nullable ThingActions actions) {
invokeMethodOf(actions).decreaseChannel();
if (actions instanceof LGWebOSActions) {
((LGWebOSActions) actions).decreaseChannel();
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
}
public static void sendRCButton(@Nullable ThingActions actions, String rcButton) {
invokeMethodOf(actions).sendRCButton(rcButton);
if (actions instanceof LGWebOSActions) {
((LGWebOSActions) actions).sendRCButton(rcButton);
} else {
throw new IllegalArgumentException("Actions is not an instance of LGWebOSActions");
}
}
}

View File

@ -27,7 +27,6 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.openhab.binding.lgwebos.action.LGWebOSActions;
import org.openhab.binding.lgwebos.internal.ChannelHandler;
import org.openhab.binding.lgwebos.internal.LGWebOSBindingConstants;
import org.openhab.binding.lgwebos.internal.LGWebOSStateDescriptionOptionProvider;
@ -41,6 +40,7 @@ import org.openhab.binding.lgwebos.internal.ToastControlToast;
import org.openhab.binding.lgwebos.internal.VolumeControlMute;
import org.openhab.binding.lgwebos.internal.VolumeControlVolume;
import org.openhab.binding.lgwebos.internal.WakeOnLanUtility;
import org.openhab.binding.lgwebos.internal.action.LGWebOSActions;
import org.openhab.binding.lgwebos.internal.handler.LGWebOSTVSocket.WebOSTVSocketListener;
import org.openhab.binding.lgwebos.internal.handler.core.AppInfo;
import org.openhab.binding.lgwebos.internal.handler.core.ResponseListener;

View File

@ -1,30 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lutron.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link IDimmerActions} interface defines the interface for all thing actions supported by the dimmer thing.
* This is only necessary to work around a bug in openhab-core (issue #1536). It should be removed once that is
* resolved.
*
* @author Bob Adair - Initial contribution
*
*/
@NonNullByDefault
public interface IDimmerActions {
public void setLevel(@Nullable Double level, @Nullable Double fadeTime, @Nullable Double delayTime);
}

View File

@ -10,10 +10,8 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lutron.action;
package org.openhab.binding.lutron.internal.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.math.BigDecimal;
import java.math.RoundingMode;
@ -36,7 +34,7 @@ import org.slf4j.LoggerFactory;
*/
@ThingActionsScope(name = "lutron")
@NonNullByDefault
public class DimmerActions implements ThingActions, IDimmerActions {
public class DimmerActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(DimmerActions.class);
private @Nullable DimmerHandler handler;
@ -60,8 +58,7 @@ public class DimmerActions implements ThingActions, IDimmerActions {
/**
* The setLevel dimmer thing action
*/
@Override
@RuleAction(label = "setLevel", description = "Send set level command with fade and delay times")
@RuleAction(label = "send a set level command", description = "Send set level command with fade and delay times.")
public void setLevel(
@ActionInput(name = "level", label = "Dimmer Level", description = "New dimmer level (0-100)") @Nullable Double level,
@ActionInput(name = "fadeTime", label = "Fade Time", description = "Time to fade to new level (seconds)") @Nullable Double fadeTime,
@ -103,29 +100,10 @@ public class DimmerActions implements ThingActions, IDimmerActions {
*/
public static void setLevel(@Nullable ThingActions actions, @Nullable Double level, @Nullable Double fadeTime,
@Nullable Double delayTime) {
invokeMethodOf(actions).setLevel(level, fadeTime, delayTime); // Replace when core issue #1536 is fixed
}
/**
* This is only necessary to work around a bug in openhab-core (issue #1536). It should be removed once that is
* resolved.
*/
private static IDimmerActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(DimmerActions.class.getName())) {
if (actions instanceof IDimmerActions) {
return (IDimmerActions) actions;
if (actions instanceof DimmerActions) {
((DimmerActions) actions).setLevel(level, fadeTime, delayTime);
} else {
return (IDimmerActions) Proxy.newProxyInstance(IDimmerActions.class.getClassLoader(),
new Class[] { IDimmerActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of DimmerActions");
}
}
}

View File

@ -19,7 +19,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicReference;
import org.openhab.binding.lutron.action.DimmerActions;
import org.openhab.binding.lutron.internal.action.DimmerActions;
import org.openhab.binding.lutron.internal.config.DimmerConfig;
import org.openhab.binding.lutron.internal.protocol.LutronCommandType;
import org.openhab.binding.lutron.internal.protocol.LutronDuration;

View File

@ -1,32 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.mail.action;
import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link ISendMailActions} interface defines rule actions for sending mail
*
* @author Jan N. Klug - Initial contribution
*/
@NonNullByDefault
public interface ISendMailActions {
Boolean sendMail(@Nullable String recipient, @Nullable String subject, @Nullable String text,
@Nullable List<String> urlStringList);
Boolean sendHtmlMail(@Nullable String recipient, @Nullable String subject, @Nullable String html,
@Nullable List<String> urlStringList);
}

View File

@ -19,7 +19,7 @@ import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.mail.action.SendMailActions;
import org.openhab.binding.mail.internal.action.SendMailActions;
import org.openhab.binding.mail.internal.config.SMTPConfig;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;

View File

@ -10,10 +10,8 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.mail.action;
package org.openhab.binding.mail.internal.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
@ -41,13 +39,13 @@ import org.slf4j.LoggerFactory;
*/
@ThingActionsScope(name = "mail")
@NonNullByDefault
public class SendMailActions implements ThingActions, ISendMailActions {
public class SendMailActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(SendMailActions.class);
private @Nullable SMTPHandler handler;
@RuleAction(label = "Send Text Mail", description = "sends a text mail")
@RuleAction(label = "send a text mail", description = "Sends a text mail.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendMail(
@ActionInput(name = "recipient") @Nullable String recipient,
@ActionInput(name = "subject") @Nullable String subject,
@ -55,7 +53,7 @@ public class SendMailActions implements ThingActions, ISendMailActions {
return sendMail(recipient, subject, text, new ArrayList<>());
}
@RuleAction(label = "Send Text Mail", description = "sends a text mail with URL attachment")
@RuleAction(label = "send a text mail", description = "Sends a text mail with URL attachment.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendMail(
@ActionInput(name = "recipient") @Nullable String recipient,
@ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "text") @Nullable String text,
@ -67,8 +65,7 @@ public class SendMailActions implements ThingActions, ISendMailActions {
return sendMail(recipient, subject, text, urlList);
}
@Override
@RuleAction(label = "Send Text Mail", description = "sends a text mail with several URL attachments")
@RuleAction(label = "send a text mail", description = "Sends a text mail with several URL attachments.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendMail(
@ActionInput(name = "recipient") @Nullable String recipient,
@ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "text") @Nullable String text,
@ -122,10 +119,14 @@ public class SendMailActions implements ThingActions, ISendMailActions {
public static boolean sendMail(@Nullable ThingActions actions, @Nullable String recipient, @Nullable String subject,
@Nullable String text, @Nullable List<String> urlStringList) {
return invokeMethodOf(actions).sendMail(recipient, subject, text, urlStringList);
if (actions instanceof SendMailActions) {
return ((SendMailActions) actions).sendMail(recipient, subject, text, urlStringList);
} else {
throw new IllegalArgumentException("Actions is not an instance of SendMailActions");
}
}
@RuleAction(label = "Send HTML Mail", description = "sends a HTML mail")
@RuleAction(label = "send a HTML mail", description = "Sends a HTML mail.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendHtmlMail(
@ActionInput(name = "recipient") @Nullable String recipient,
@ActionInput(name = "subject") @Nullable String subject,
@ -133,7 +134,7 @@ public class SendMailActions implements ThingActions, ISendMailActions {
return sendHtmlMail(recipient, subject, html, new ArrayList<>());
}
@RuleAction(label = "Send HTML Mail", description = "sends a HTML mail with URL attachment")
@RuleAction(label = "send a HTML mail", description = "Sends a HTML mail with URL attachment.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendHtmlMail(
@ActionInput(name = "recipient") @Nullable String recipient,
@ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "html") @Nullable String html,
@ -145,8 +146,7 @@ public class SendMailActions implements ThingActions, ISendMailActions {
return sendHtmlMail(recipient, subject, html, urlList);
}
@Override
@RuleAction(label = "Send HTML Mail", description = "sends a HTML mail with several URL attachments")
@RuleAction(label = "send a HTML mail", description = "Sends a HTML mail with several URL attachments.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendHtmlMail(
@ActionInput(name = "recipient") @Nullable String recipient,
@ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "html") @Nullable String html,
@ -200,7 +200,11 @@ public class SendMailActions implements ThingActions, ISendMailActions {
public static boolean sendHtmlMail(@Nullable ThingActions actions, @Nullable String recipient,
@Nullable String subject, @Nullable String html, @Nullable List<String> urlStringList) {
return invokeMethodOf(actions).sendHtmlMail(recipient, subject, html, urlStringList);
if (actions instanceof SendMailActions) {
return ((SendMailActions) actions).sendHtmlMail(recipient, subject, html, urlStringList);
} else {
throw new IllegalArgumentException("Actions is not an instance of SendMailActions");
}
}
@Override
@ -212,25 +216,6 @@ public class SendMailActions implements ThingActions, ISendMailActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
}
private static ISendMailActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(SendMailActions.class.getName())) {
if (actions instanceof ISendMailActions) {
return (ISendMailActions) actions;
} else {
return (ISendMailActions) Proxy.newProxyInstance(ISendMailActions.class.getClassLoader(),
new Class[] { ISendMailActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of SendMailActions");
return handler;
}
}

View File

@ -1,32 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.max.internal.actions;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.max.actions.MaxCubeActions;
/**
* The {@link IMaxCubeActions} defines the interface for all thing actions supported by the binding.
* These methods, parameters, and return types are explained in {@link MaxCubeActions}.
*
* @author Christoph Weitkamp - Initial contribution
*/
@NonNullByDefault
public interface IMaxCubeActions {
Boolean backup();
Boolean resetConfig();
Boolean reboot();
}

View File

@ -1,28 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.max.internal.actions;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.max.actions.MaxDevicesActions;
/**
* The {@link IMaxDevicesActions} defines the interface for all thing actions supported by the binding.
* These methods, parameters, and return types are explained in {@link MaxDevicesActions}.
*
* @author Christoph Weitkamp - Initial contribution
*/
@NonNullByDefault
public interface IMaxDevicesActions {
Boolean deleteFromCube();
}

View File

@ -10,14 +10,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.max.actions;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
package org.openhab.binding.max.internal.actions;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.max.internal.actions.IMaxCubeActions;
import org.openhab.binding.max.internal.handler.MaxCubeBridgeHandler;
import org.openhab.core.automation.annotation.ActionOutput;
import org.openhab.core.automation.annotation.RuleAction;
@ -34,7 +30,7 @@ import org.slf4j.LoggerFactory;
*/
@ThingActionsScope(name = "max-cube")
@NonNullByDefault
public class MaxCubeActions implements ThingActions, IMaxCubeActions {
public class MaxCubeActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(MaxCubeActions.class);
@ -49,11 +45,10 @@ public class MaxCubeActions implements ThingActions, IMaxCubeActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
return handler;
}
@Override
@RuleAction(label = "Backup Cube Data", description = "Creates a backup of the MAX! Cube data.")
@RuleAction(label = "backup the Cube data", description = "Creates a backup of the MAX! Cube data.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean backup() {
MaxCubeBridgeHandler actionsHandler = handler;
if (actionsHandler == null) {
@ -65,11 +60,14 @@ public class MaxCubeActions implements ThingActions, IMaxCubeActions {
}
public static boolean backup(@Nullable ThingActions actions) {
return invokeMethodOf(actions).backup();
if (actions instanceof MaxCubeActions) {
return ((MaxCubeActions) actions).backup();
} else {
throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions");
}
}
@Override
@RuleAction(label = "Reset Cube Configuration", description = "Resets the MAX! Cube room and device information. Devices will need to be included again!")
@RuleAction(label = "reset the Cube configuration", description = "Resets the MAX! Cube room and device information. Devices will need to be included again!")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean resetConfig() {
MaxCubeBridgeHandler actionsHandler = handler;
if (actionsHandler == null) {
@ -81,11 +79,14 @@ public class MaxCubeActions implements ThingActions, IMaxCubeActions {
}
public static boolean reset(@Nullable ThingActions actions) {
return invokeMethodOf(actions).resetConfig();
if (actions instanceof MaxCubeActions) {
return ((MaxCubeActions) actions).resetConfig();
} else {
throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions");
}
}
@Override
@RuleAction(label = "Restart Cube", description = "Restarts the MAX! Cube.")
@RuleAction(label = "restart the Cube", description = "Restarts the MAX! Cube.")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean reboot() {
MaxCubeBridgeHandler actionsHandler = handler;
if (actionsHandler == null) {
@ -97,25 +98,10 @@ public class MaxCubeActions implements ThingActions, IMaxCubeActions {
}
public static boolean reboot(@Nullable ThingActions actions) {
return invokeMethodOf(actions).reboot();
}
private static IMaxCubeActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(MaxCubeActions.class.getName())) {
if (actions instanceof IMaxCubeActions) {
return (IMaxCubeActions) actions;
if (actions instanceof MaxCubeActions) {
return ((MaxCubeActions) actions).reboot();
} else {
return (IMaxCubeActions) Proxy.newProxyInstance(IMaxCubeActions.class.getClassLoader(),
new Class[] { IMaxCubeActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions");
}
}
}

View File

@ -10,14 +10,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.max.actions;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
package org.openhab.binding.max.internal.actions;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.max.internal.actions.IMaxDevicesActions;
import org.openhab.binding.max.internal.handler.MaxDevicesHandler;
import org.openhab.core.automation.annotation.ActionOutput;
import org.openhab.core.automation.annotation.RuleAction;
@ -34,7 +30,7 @@ import org.slf4j.LoggerFactory;
*/
@ThingActionsScope(name = "max-devices")
@NonNullByDefault
public class MaxDevicesActions implements ThingActions, IMaxDevicesActions {
public class MaxDevicesActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(MaxDevicesActions.class);
@ -49,11 +45,10 @@ public class MaxDevicesActions implements ThingActions, IMaxDevicesActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
return handler;
}
@Override
@RuleAction(label = "Delete Device from Cube", description = "Deletes the device from the MAX! Cube. Device will need to be included again!")
@RuleAction(label = "delete the device from the Cube", description = "Deletes the device from the MAX! Cube. Device will need to be included again!")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean deleteFromCube() {
MaxDevicesHandler actionsHandler = handler;
if (actionsHandler == null) {
@ -65,25 +60,10 @@ public class MaxDevicesActions implements ThingActions, IMaxDevicesActions {
}
public static boolean deleteFromCube(@Nullable ThingActions actions) {
return invokeMethodOf(actions).deleteFromCube();
}
private static IMaxDevicesActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(MaxDevicesActions.class.getName())) {
if (actions instanceof IMaxDevicesActions) {
return (IMaxDevicesActions) actions;
if (actions instanceof MaxDevicesActions) {
return ((MaxDevicesActions) actions).deleteFromCube();
} else {
return (IMaxDevicesActions) Proxy.newProxyInstance(IMaxDevicesActions.class.getClassLoader(),
new Class[] { IMaxDevicesActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of MaxDevicesActions");
}
}
}

View File

@ -49,9 +49,9 @@ import java.util.stream.Stream;
import javax.measure.quantity.Temperature;
import org.openhab.binding.max.actions.MaxCubeActions;
import org.openhab.binding.max.internal.MaxBackupUtils;
import org.openhab.binding.max.internal.MaxBindingConstants;
import org.openhab.binding.max.internal.actions.MaxCubeActions;
import org.openhab.binding.max.internal.command.ACommand;
import org.openhab.binding.max.internal.command.CCommand;
import org.openhab.binding.max.internal.command.CubeCommand;

View File

@ -27,7 +27,7 @@ import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.openhab.binding.max.actions.MaxDevicesActions;
import org.openhab.binding.max.internal.actions.MaxDevicesActions;
import org.openhab.binding.max.internal.command.CCommand;
import org.openhab.binding.max.internal.command.QCommand;
import org.openhab.binding.max.internal.command.SConfigCommand;

View File

@ -1,29 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.mpd.internal.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link IMPDActions} interface defines rule actions for sending commands to a Music Player Daemon
*
* @author Stefan Röllin - Initial contribution
*/
@NonNullByDefault
public interface IMPDActions {
public void sendCommand(@Nullable String command, @Nullable String parameter);
public void sendCommand(@Nullable String command);
}

View File

@ -12,9 +12,6 @@
*/
package org.openhab.binding.mpd.internal.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.mpd.internal.handler.MPDHandler;
@ -33,7 +30,7 @@ import org.slf4j.LoggerFactory;
*/
@ThingActionsScope(name = "mpd")
@NonNullByDefault
public class MPDActions implements ThingActions, IMPDActions {
public class MPDActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(MPDActions.class);
@ -51,8 +48,7 @@ public class MPDActions implements ThingActions, IMPDActions {
return handler;
}
@Override
@RuleAction(label = "MPD : Send command", description = "Send a command to the Music Player Daemon.")
@RuleAction(label = "send a command with a parameter", description = "Send a command to the Music Player Daemon.")
public void sendCommand(@ActionInput(name = "command") @Nullable String command,
@ActionInput(name = "parameter") @Nullable String parameter) {
logger.debug("sendCommand called with {}", command);
@ -65,8 +61,7 @@ public class MPDActions implements ThingActions, IMPDActions {
}
}
@Override
@RuleAction(label = "MPD : Send command", description = "Send a command to the Music Player Daemon.")
@RuleAction(label = "send a command", description = "Send a command to the Music Player Daemon.")
public void sendCommand(@ActionInput(name = "command") @Nullable String command) {
logger.debug("sendCommand called with {}", command);
@ -78,31 +73,20 @@ public class MPDActions implements ThingActions, IMPDActions {
}
}
private static IMPDActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(MPDActions.class.getName())) {
if (actions instanceof IMPDActions) {
return (IMPDActions) actions;
} else {
return (IMPDActions) Proxy.newProxyInstance(IMPDActions.class.getClassLoader(),
new Class[] { IMPDActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of MPDActions");
}
public static void sendCommand(@Nullable ThingActions actions, @Nullable String command,
@Nullable String parameter) {
invokeMethodOf(actions).sendCommand(command, parameter);
if (actions instanceof MPDActions) {
((MPDActions) actions).sendCommand(command, parameter);
} else {
throw new IllegalArgumentException("Actions is not an instance of MPDActions");
}
}
public static void sendCommand(@Nullable ThingActions actions, @Nullable String command) {
invokeMethodOf(actions).sendCommand(command);
if (actions instanceof MPDActions) {
((MPDActions) actions).sendCommand(command);
} else {
throw new IllegalArgumentException("Actions is not an instance of MPDActions");
}
}
}

View File

@ -1,27 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.mqtt.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link IMQTTActions} defines the interface for all thing actions supported by the binding.
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public interface IMQTTActions {
public void publishMQTT(@Nullable String topic, @Nullable String value, @Nullable Boolean retain);
}

View File

@ -21,9 +21,9 @@ import java.util.concurrent.TimeoutException;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.mqtt.action.MQTTActions;
import org.openhab.binding.mqtt.discovery.MQTTTopicDiscoveryParticipant;
import org.openhab.binding.mqtt.discovery.TopicSubscribe;
import org.openhab.binding.mqtt.internal.action.MQTTActions;
import org.openhab.core.io.transport.mqtt.MqttBrokerConnection;
import org.openhab.core.io.transport.mqtt.MqttConnectionObserver;
import org.openhab.core.io.transport.mqtt.MqttConnectionState;

View File

@ -10,10 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.mqtt.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
package org.openhab.binding.mqtt.internal.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -29,17 +26,12 @@ import org.slf4j.LoggerFactory;
/**
* This is the automation engine action handler service for the publishMQTT action.
* <p>
* <b>Note:</b>The static method <b>invokeMethodOf</b> handles the case where
* the test <i>actions instanceof MQTTActions</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link MQTTActions} class
* can be loaded by a different classloader than the <i>actions</i> instance.
*
* @author David Graeff - Initial contribution
*/
@ThingActionsScope(name = "mqtt")
@NonNullByDefault
public class MQTTActions implements ThingActions, IMQTTActions {
public class MQTTActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(MQTTActions.class);
private @Nullable AbstractBrokerHandler handler;
@ -50,7 +42,7 @@ public class MQTTActions implements ThingActions, IMQTTActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
return handler;
}
@RuleAction(label = "@text/actionLabel", description = "@text/actionDesc")
@ -60,7 +52,6 @@ public class MQTTActions implements ThingActions, IMQTTActions {
publishMQTT(topic, value, null);
}
@Override
@RuleAction(label = "@text/actionLabel", description = "@text/actionDesc")
public void publishMQTT(
@ActionInput(name = "topic", label = "@text/actionInputTopicLabel", description = "@text/actionInputTopicDesc") @Nullable final String topic,
@ -100,25 +91,10 @@ public class MQTTActions implements ThingActions, IMQTTActions {
public static void publishMQTT(@Nullable ThingActions actions, @Nullable String topic, @Nullable String value,
@Nullable Boolean retain) {
invokeMethodOf(actions).publishMQTT(topic, value, retain);
}
private static IMQTTActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(MQTTActions.class.getName())) {
if (actions instanceof IMQTTActions) {
return (IMQTTActions) actions;
if (actions instanceof MQTTActions) {
((MQTTActions) actions).publishMQTT(topic, value, retain);
} else {
return (IMQTTActions) Proxy.newProxyInstance(IMQTTActions.class.getClassLoader(),
new Class[] { IMQTTActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of MQTTActions");
}
}
}

View File

@ -1,26 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.network.internal.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* The {@link INetworkActions} defines the interface for all thing actions supported by the binding.
*
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public interface INetworkActions {
void sendWakeOnLanPacket();
}

View File

@ -12,9 +12,6 @@
*/
package org.openhab.binding.network.internal.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.network.internal.handler.NetworkHandler;
@ -27,17 +24,12 @@ import org.slf4j.LoggerFactory;
/**
* The class is responsible to call corresponding actions on {@link NetworkHandler}.
* <p>
* <b>Note:</b>The static method <b>invokeMethodOf</b> handles the case where
* the test <i>actions instanceof NetworkActions</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link NetworkActions} class
* can be loaded by a different classloader than the <i>actions</i> instance.
*
* @author Wouter Born - Initial contribution
*/
@ThingActionsScope(name = "network")
@NonNullByDefault
public class NetworkActions implements ThingActions, INetworkActions {
public class NetworkActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(NetworkActions.class);
@ -55,8 +47,7 @@ public class NetworkActions implements ThingActions, INetworkActions {
return handler;
}
@Override
@RuleAction(label = "Send WoL Packet", description = "Send a Wake-on-LAN packet to wake the device")
@RuleAction(label = "send a WoL packet", description = "Send a Wake-on-LAN packet to wake the device.")
public void sendWakeOnLanPacket() {
NetworkHandler localHandler = handler;
if (localHandler != null) {
@ -67,25 +58,10 @@ public class NetworkActions implements ThingActions, INetworkActions {
}
public static void sendWakeOnLanPacket(@Nullable ThingActions actions) {
invokeMethodOf(actions).sendWakeOnLanPacket();
}
private static INetworkActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(NetworkActions.class.getName())) {
if (actions instanceof INetworkActions) {
return (INetworkActions) actions;
if (actions instanceof NetworkActions) {
((NetworkActions) actions).sendWakeOnLanPacket();
} else {
return (INetworkActions) Proxy.newProxyInstance(INetworkActions.class.getClassLoader(),
new Class[] { INetworkActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
throw new IllegalArgumentException("Actions is not an instance of NetworkActions");
}
}
throw new IllegalArgumentException("Actions is not an instance of " + NetworkActions.class.getName());
}
}

View File

@ -1,27 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.nuvo.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* The {@link INuvoThingActions} defines the interface for all thing actions supported by the binding.
* These methods, parameters, and return types are explained in {@link NuvoThingActions}.
*
* @author Michael Lobstein - Initial contribution
*/
@NonNullByDefault
public interface INuvoThingActions {
void sendNuvoCommand(String rawCommand);
}

View File

@ -12,9 +12,6 @@
*/
package org.openhab.binding.nuvo.internal;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.nuvo.internal.handler.NuvoHandler;
@ -30,17 +27,16 @@ import org.slf4j.LoggerFactory;
* Some automation actions to be used with a {@link NuvoThingActions}
*
* @author Michael Lobstein - initial contribution
*
*/
@ThingActionsScope(name = "nuvo")
@NonNullByDefault
public class NuvoThingActions implements ThingActions, INuvoThingActions {
public class NuvoThingActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(NuvoThingActions.class);
private @Nullable NuvoHandler handler;
@RuleAction(label = "sendNuvoCommand", description = "Action that sends raw command to the amplifer")
@RuleAction(label = "send a raw command", description = "Send a raw command to the amplifier.")
public void sendNuvoCommand(@ActionInput(name = "sendNuvoCommand") String rawCommand) {
NuvoHandler localHandler = handler;
if (localHandler != null) {
@ -52,9 +48,12 @@ public class NuvoThingActions implements ThingActions, INuvoThingActions {
}
/** Static alias to support the old DSL rules engine and make the action available there. */
public static void sendNuvoCommand(@Nullable ThingActions actions, String rawCommand)
throws IllegalArgumentException {
invokeMethodOf(actions).sendNuvoCommand(rawCommand);
public static void sendNuvoCommand(@Nullable ThingActions actions, String rawCommand) {
if (actions instanceof NuvoThingActions) {
((NuvoThingActions) actions).sendNuvoCommand(rawCommand);
} else {
throw new IllegalArgumentException("Actions is not an instance of NuvoThingActions");
}
}
@Override
@ -64,25 +63,6 @@ public class NuvoThingActions implements ThingActions, INuvoThingActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
}
private static INuvoThingActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(NuvoThingActions.class.getName())) {
if (actions instanceof NuvoThingActions) {
return (INuvoThingActions) actions;
} else {
return (INuvoThingActions) Proxy.newProxyInstance(INuvoThingActions.class.getClassLoader(),
new Class[] { INuvoThingActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of NuvoThingActions");
return handler;
}
}

View File

@ -14,14 +14,58 @@ package org.openhab.binding.onkyo.internal.automation.modules;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.onkyo.internal.handler.OnkyoHandler;
import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.RuleAction;
import org.openhab.core.thing.binding.ThingActions;
import org.openhab.core.thing.binding.ThingActionsScope;
import org.openhab.core.thing.binding.ThingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link OnkyoThingActions} defines the interface for all thing actions supported by the binding.
* Some automation actions to be used with a {@link OnkyoThingActions}
*
* @author Laurent Garnier - initial contribution
* @author David Masshardt - initial contribution
*/
@ThingActionsScope(name = "onkyo")
@NonNullByDefault
public interface OnkyoThingActions {
public class OnkyoThingActions implements ThingActions {
public void sendRawCommand(@Nullable String command, @Nullable String value);
private final Logger logger = LoggerFactory.getLogger(OnkyoThingActions.class);
private @Nullable OnkyoHandler handler;
@SuppressWarnings("null")
@RuleAction(label = "send a raw command", description = "Send a raw command to the receiver.")
public void sendRawCommand(@ActionInput(name = "command") @Nullable String command,
@ActionInput(name = "command") @Nullable String value) {
logger.debug("sendRawCommand called with raw command: {} value: {}", command, value);
if (handler == null) {
logger.warn("Onkyo Action service ThingHandler is null!");
return;
}
handler.sendRawCommand(command, value);
}
public static void sendRawCommand(@Nullable ThingActions actions, @Nullable String command,
@Nullable String value) {
if (actions instanceof OnkyoThingActions) {
((OnkyoThingActions) actions).sendRawCommand(command, value);
} else {
throw new IllegalArgumentException("Actions is not an instance of OnkyoThingActions");
}
}
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof OnkyoHandler) {
this.handler = (OnkyoHandler) handler;
}
}
@Override
public @Nullable ThingHandler getThingHandler() {
return handler;
}
}

View File

@ -1,96 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.onkyo.internal.automation.modules;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.onkyo.internal.handler.OnkyoHandler;
import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.RuleAction;
import org.openhab.core.thing.binding.ThingActions;
import org.openhab.core.thing.binding.ThingActionsScope;
import org.openhab.core.thing.binding.ThingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Some automation actions to be used with a {@link OnkyoThingActionsService}
* <p>
* <b>Note:</b>The static method <b>invokeMethodOf</b> handles the case where
* the test <i>actions instanceof OnkyoThingActionsService</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link OnkyoThingActionsService} class
* can be loaded by a different classloader than the <i>actions</i> instance.
*
* @author David Masshardt - initial contribution
*
*/
@ThingActionsScope(name = "onkyo")
@NonNullByDefault
public class OnkyoThingActionsService implements ThingActions, OnkyoThingActions {
private final Logger logger = LoggerFactory.getLogger(OnkyoThingActionsService.class);
private @Nullable OnkyoHandler handler;
@Override
@SuppressWarnings("null")
@RuleAction(label = "Onkyo sendRawCommand", description = "Action that sends raw command to the receiver")
public void sendRawCommand(@ActionInput(name = "command") @Nullable String command,
@ActionInput(name = "command") @Nullable String value) {
logger.debug("sendRawCommand called with raw command: {} value: {}", command, value);
if (handler == null) {
logger.warn("Onkyo Action service ThingHandler is null!");
return;
}
handler.sendRawCommand(command, value);
}
public static void sendRawCommand(@Nullable ThingActions actions, @Nullable String command,
@Nullable String value) {
invokeMethodOf(actions).sendRawCommand(command, value);
}
private static OnkyoThingActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(OnkyoThingActionsService.class.getName())) {
if (actions instanceof OnkyoThingActions) {
return (OnkyoThingActions) actions;
} else {
return (OnkyoThingActions) Proxy.newProxyInstance(OnkyoThingActions.class.getClassLoader(),
new Class[] { OnkyoThingActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of OnkyoThingActionsService");
}
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof OnkyoHandler) {
this.handler = (OnkyoHandler) handler;
}
}
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
}
}

View File

@ -32,7 +32,7 @@ import org.openhab.binding.onkyo.internal.OnkyoConnection;
import org.openhab.binding.onkyo.internal.OnkyoEventListener;
import org.openhab.binding.onkyo.internal.OnkyoStateDescriptionProvider;
import org.openhab.binding.onkyo.internal.ServiceType;
import org.openhab.binding.onkyo.internal.automation.modules.OnkyoThingActionsService;
import org.openhab.binding.onkyo.internal.automation.modules.OnkyoThingActions;
import org.openhab.binding.onkyo.internal.config.OnkyoDeviceConfiguration;
import org.openhab.binding.onkyo.internal.eiscp.EiscpCommand;
import org.openhab.binding.onkyo.internal.eiscp.EiscpMessage;
@ -910,6 +910,6 @@ public class OnkyoHandler extends UpnpAudioSinkHandler implements OnkyoEventList
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singletonList(OnkyoThingActionsService.class);
return Collections.singletonList(OnkyoThingActions.class);
}
}

View File

@ -1,29 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.pushbullet.internal.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link IPushbulletActions} interface defines rule actions for sending notifications
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public interface IPushbulletActions {
public Boolean sendPushbulletNote(@Nullable String recipient, @Nullable String title, @Nullable String message);
public Boolean sendPushbulletNote(@Nullable String recipient, @Nullable String message);
}

View File

@ -12,9 +12,6 @@
*/
package org.openhab.binding.pushbullet.internal.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.pushbullet.internal.handler.PushbulletHandler;
@ -29,17 +26,12 @@ import org.slf4j.LoggerFactory;
/**
* The {@link PushbulletActions} class defines rule actions for sending notifications
* <p>
* <b>Note:</b>The static method <b>invokeMethodOf</b> handles the case where
* the test <i>actions instanceof PushbulletActions</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link PushbulletActions} class
* can be loaded by a different classloader than the <i>actions</i> instance.
*
* @author Hakan Tandogan - Initial contribution
*/
@ThingActionsScope(name = "pushbullet")
@NonNullByDefault
public class PushbulletActions implements ThingActions, IPushbulletActions {
public class PushbulletActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(PushbulletActions.class);
@ -52,10 +44,9 @@ public class PushbulletActions implements ThingActions, IPushbulletActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
return handler;
}
@Override
@RuleAction(label = "@text/actionSendPushbulletNoteLabel", description = "@text/actionSendPushbulletNoteDesc")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendPushbulletNote(
@ActionInput(name = "recipient", label = "@text/actionSendPushbulletNoteInputRecipientLabel", description = "@text/actionSendPushbulletNoteInputRecipientDesc") @Nullable String recipient,
@ -63,9 +54,7 @@ public class PushbulletActions implements ThingActions, IPushbulletActions {
@ActionInput(name = "message", label = "@text/actionSendPushbulletNoteInputMessageLabel", description = "@text/actionSendPushbulletNoteInputMessageDesc") @Nullable String message) {
logger.trace("sendPushbulletNote '{}', '{}', '{}'", recipient, title, message);
// Use local variable so the SAT check can do proper flow analysis
PushbulletHandler localHandler = handler;
if (localHandler == null) {
logger.warn("Pushbullet service Handler is null!");
return false;
@ -76,19 +65,20 @@ public class PushbulletActions implements ThingActions, IPushbulletActions {
public static boolean sendPushbulletNote(@Nullable ThingActions actions, @Nullable String recipient,
@Nullable String title, @Nullable String message) {
return invokeMethodOf(actions).sendPushbulletNote(recipient, title, message);
if (actions instanceof PushbulletActions) {
return ((PushbulletActions) actions).sendPushbulletNote(recipient, title, message);
} else {
throw new IllegalArgumentException("Actions is not an instance of PushbulletActions");
}
}
@Override
@RuleAction(label = "@text/actionSendPushbulletNoteLabel", description = "@text/actionSendPushbulletNoteDesc")
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendPushbulletNote(
@ActionInput(name = "recipient", label = "@text/actionSendPushbulletNoteInputRecipientLabel", description = "@text/actionSendPushbulletNoteInputRecipientDesc") @Nullable String recipient,
@ActionInput(name = "message", label = "@text/actionSendPushbulletNoteInputMessageLabel", description = "@text/actionSendPushbulletNoteInputMessageDesc") @Nullable String message) {
logger.trace("sendPushbulletNote '{}', '{}'", recipient, message);
// Use local variable so the SAT check can do proper flow analysis
PushbulletHandler localHandler = handler;
if (localHandler == null) {
logger.warn("Pushbullet service Handler is null!");
return false;
@ -99,25 +89,10 @@ public class PushbulletActions implements ThingActions, IPushbulletActions {
public static boolean sendPushbulletNote(@Nullable ThingActions actions, @Nullable String recipient,
@Nullable String message) {
return invokeMethodOf(actions).sendPushbulletNote(recipient, message);
}
private static IPushbulletActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(PushbulletActions.class.getName())) {
if (actions instanceof IPushbulletActions) {
return (IPushbulletActions) actions;
if (actions instanceof PushbulletActions) {
return ((PushbulletActions) actions).sendPushbulletNote(recipient, message);
} else {
return (IPushbulletActions) Proxy.newProxyInstance(IPushbulletActions.class.getClassLoader(),
new Class[] { IPushbulletActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of PushbulletActions");
}
}
}

View File

@ -1,28 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.radiothermostat.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link IRadioThermostatThingActions} defines the interface for all thing actions supported by the binding.
* These methods, parameters, and return types are explained in {@link RadioThermostatThingActions}.
*
* @author Michael Lobstein - Initial contribution
*/
@NonNullByDefault
public interface IRadioThermostatThingActions {
void sendRawCommand(@Nullable String rawCommand);
}

View File

@ -12,9 +12,6 @@
*/
package org.openhab.binding.radiothermostat.internal;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.radiothermostat.internal.handler.RadioThermostatHandler;
@ -30,24 +27,22 @@ import org.slf4j.LoggerFactory;
* Some automation actions to be used with a {@link RadioThermostatThingActions}
*
* @author Michael Lobstein - initial contribution
*
*/
@ThingActionsScope(name = "radiothermostat")
@NonNullByDefault
public class RadioThermostatThingActions implements ThingActions, IRadioThermostatThingActions {
public class RadioThermostatThingActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(RadioThermostatThingActions.class);
private @Nullable RadioThermostatHandler handler;
@Override
@RuleAction(label = "sendRawCommand", description = "Action that sends raw command to the thermostat")
@RuleAction(label = "send a raw command", description = "Send a raw command to the thermostat.")
public void sendRawCommand(@ActionInput(name = "sendRawCommand") @Nullable String rawCommand) {
RadioThermostatHandler localHandler = handler;
if (rawCommand == null) {
logger.warn("sendRawCommand called with null command, ignoring");
return;
}
RadioThermostatHandler localHandler = handler;
if (localHandler != null) {
localHandler.handleRawCommand(rawCommand);
logger.debug("sendRawCommand called with raw command: {}", rawCommand);
@ -55,9 +50,12 @@ public class RadioThermostatThingActions implements ThingActions, IRadioThermost
}
/** Static alias to support the old DSL rules engine and make the action available there. */
public static void sendRawCommand(@Nullable ThingActions actions, @Nullable String rawCommand)
throws IllegalArgumentException {
invokeMethodOf(actions).sendRawCommand(rawCommand);
public static void sendRawCommand(@Nullable ThingActions actions, @Nullable String rawCommand) {
if (actions instanceof RadioThermostatThingActions) {
((RadioThermostatThingActions) actions).sendRawCommand(rawCommand);
} else {
throw new IllegalArgumentException("Actions is not an instance of RadioThermostatThingActions");
}
}
@Override
@ -67,27 +65,6 @@ public class RadioThermostatThingActions implements ThingActions, IRadioThermost
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
}
private static IRadioThermostatThingActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(RadioThermostatThingActions.class.getName())) {
if (actions instanceof RadioThermostatThingActions) {
return (IRadioThermostatThingActions) actions;
} else {
return (IRadioThermostatThingActions) Proxy.newProxyInstance(
IRadioThermostatThingActions.class.getClassLoader(),
new Class[] { IRadioThermostatThingActions.class },
(Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of RadioThermostatThingActions");
return handler;
}
}

View File

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

View File

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

View File

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

View File

@ -1,48 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.telegram.bot;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* Provides the actions for the Telegram API.
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public interface ITelegramActions {
public boolean sendTelegramAnswer(@Nullable Long chatId, @Nullable String replyId, @Nullable String message);
public boolean sendTelegramAnswer(@Nullable String replyId, @Nullable String message);
public boolean sendTelegram(@Nullable Long chatId, @Nullable String message);
public boolean sendTelegram(@Nullable String message);
public boolean sendTelegramQuery(@Nullable Long chatId, @Nullable String message, @Nullable String replyId,
@Nullable String... buttons);
public boolean sendTelegramQuery(@Nullable String message, @Nullable String replyId, @Nullable String... buttons);
public boolean sendTelegram(@Nullable Long chatId, @Nullable String message, @Nullable Object... args);
public boolean sendTelegram(@Nullable String message, @Nullable Object... args);
public boolean sendTelegramPhoto(@Nullable Long chatId, @Nullable String photoURL, @Nullable String caption,
@Nullable String username, @Nullable String password);
public boolean sendTelegramPhoto(@Nullable String photoURL, @Nullable String caption, @Nullable String username,
@Nullable String password);
}

View File

@ -34,7 +34,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.openhab.binding.telegram.bot.TelegramActions;
import org.openhab.binding.telegram.internal.action.TelegramActions;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.thing.ChannelUID;

View File

@ -10,13 +10,11 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.telegram.bot;
package org.openhab.binding.telegram.internal.action;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@ -58,18 +56,12 @@ import com.pengrad.telegrambot.response.SendResponse;
/**
* Provides the actions for the Telegram API.
* <p>
* <b>Note:</b>The static method <b>invokeMethodOf</b> handles the case where
* the test <i>actions instanceof TelegramActions</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link TelegramActions} class
* can be loaded by a different classloader than the <i>actions</i> instance.
*
* @author Alexander Krasnogolowy - Initial contribution
*
*/
@ThingActionsScope(name = "telegram")
@NonNullByDefault
public class TelegramActions implements ThingActions, ITelegramActions {
public class TelegramActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(TelegramActions.class);
private @Nullable TelegramHandler handler;
@ -81,7 +73,6 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return true;
}
@NonNullByDefault
private static class BasicResult implements Authentication.Result {
private final HttpHeader header;
@ -112,8 +103,7 @@ public class TelegramActions implements ThingActions, ITelegramActions {
}
}
@Override
@RuleAction(label = "Telegram answer", description = "Sends a Telegram answer via Telegram API")
@RuleAction(label = "send an answer", description = "Send a Telegram answer using the Telegram API.")
public boolean sendTelegramAnswer(@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "replyId") @Nullable String replyId,
@ActionInput(name = "message") @Nullable String message) {
@ -155,8 +145,7 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return false;
}
@Override
@RuleAction(label = "Telegram answer", description = "Sends a Telegram answer via Telegram API")
@RuleAction(label = "send an answer", description = "Send a Telegram answer using the Telegram API.")
public boolean sendTelegramAnswer(@ActionInput(name = "replyId") @Nullable String replyId,
@ActionInput(name = "message") @Nullable String message) {
TelegramHandler localHandler = handler;
@ -170,15 +159,13 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return true;
}
@Override
@RuleAction(label = "Telegram message", description = "Sends a Telegram via Telegram API")
@RuleAction(label = "send a message", description = "Send a Telegram message using the Telegram API.")
public boolean sendTelegram(@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "message") @Nullable String message) {
return sendTelegramGeneral(chatId, message, (String) null);
}
@Override
@RuleAction(label = "Telegram message", description = "Sends a Telegram via Telegram API")
@RuleAction(label = "send a message", description = "Send a Telegram message using the Telegram API.")
public boolean sendTelegram(@ActionInput(name = "message") @Nullable String message) {
TelegramHandler localHandler = handler;
if (localHandler != null) {
@ -191,8 +178,7 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return true;
}
@Override
@RuleAction(label = "Telegram message", description = "Sends a Telegram via Telegram API")
@RuleAction(label = "send a message", description = "Send a Telegram using the Telegram API.")
public boolean sendTelegramQuery(@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "message") @Nullable String message,
@ActionInput(name = "replyId") @Nullable String replyId,
@ -200,8 +186,7 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return sendTelegramGeneral(chatId, message, replyId, buttons);
}
@Override
@RuleAction(label = "Telegram message", description = "Sends a Telegram via Telegram API")
@RuleAction(label = "send a message", description = "Send a Telegram using the Telegram API.")
public boolean sendTelegramQuery(@ActionInput(name = "message") @Nullable String message,
@ActionInput(name = "replyId") @Nullable String replyId,
@ActionInput(name = "buttons") @Nullable String... buttons) {
@ -266,16 +251,14 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return false;
}
@Override
@RuleAction(label = "Telegram message", description = "Sends a Telegram via Telegram API")
@RuleAction(label = "send a message", description = "Send a Telegram using the Telegram API.")
public boolean sendTelegram(@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "message") @Nullable String message,
@ActionInput(name = "args") @Nullable Object... args) {
return sendTelegram(chatId, String.format(message, args));
}
@Override
@RuleAction(label = "Telegram message", description = "Sends a Telegram via Telegram API")
@RuleAction(label = "send a message", description = "Send a Telegram using the Telegram API.")
public boolean sendTelegram(@ActionInput(name = "message") @Nullable String message,
@ActionInput(name = "args") @Nullable Object... args) {
TelegramHandler localHandler = handler;
@ -289,15 +272,14 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return true;
}
@RuleAction(label = "Telegram photo", description = "Sends a Picture via Telegram API")
@RuleAction(label = "send a photo", description = "Send a picture using the Telegram API.")
public boolean sendTelegramPhoto(@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "photoURL") @Nullable String photoURL,
@ActionInput(name = "caption") @Nullable String caption) {
return sendTelegramPhoto(chatId, photoURL, caption, null, null);
}
@Override
@RuleAction(label = "Telegram photo", description = "Sends a Picture via Telegram API")
@RuleAction(label = "send a photo", description = "Send a picture using the Telegram API.")
public boolean sendTelegramPhoto(@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "photoURL") @Nullable String photoURL,
@ActionInput(name = "caption") @Nullable String caption,
@ -387,8 +369,7 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return false;
}
@Override
@RuleAction(label = "Telegram photo", description = "Sends a Picture via Telegram API")
@RuleAction(label = "send a photo", description = "Send a Picture using the Telegram API.")
public boolean sendTelegramPhoto(@ActionInput(name = "photoURL") @Nullable String photoURL,
@ActionInput(name = "caption") @Nullable String caption,
@ActionInput(name = "username") @Nullable String username,
@ -404,7 +385,7 @@ public class TelegramActions implements ThingActions, ITelegramActions {
return true;
}
@RuleAction(label = "Telegram photo", description = "Sends a Picture via Telegram API")
@RuleAction(label = "send a photo", description = "Send a Picture using the Telegram API.")
public boolean sendTelegramPhoto(@ActionInput(name = "photoURL") @Nullable String photoURL,
@ActionInput(name = "caption") @Nullable String caption) {
return sendTelegramPhoto(photoURL, caption, null, null);
@ -414,79 +395,104 @@ public class TelegramActions implements ThingActions, ITelegramActions {
/* APIs without chatId parameter */
public static boolean sendTelegram(@Nullable ThingActions actions, @Nullable String format,
@Nullable Object... args) {
return invokeMethodOf(actions).sendTelegram(format, args);
if (actions instanceof TelegramActions) {
return ((TelegramActions) actions).sendTelegram(format, args);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
}
public static boolean sendTelegramQuery(@Nullable ThingActions actions, @Nullable String message,
@Nullable String replyId, @Nullable String... buttons) {
return invokeMethodOf(actions).sendTelegramQuery(message, replyId, buttons);
if (actions instanceof TelegramActions) {
return ((TelegramActions) actions).sendTelegramQuery(message, replyId, buttons);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
}
public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable String photoURL,
@Nullable String caption) {
return invokeMethodOf(actions).sendTelegramPhoto(photoURL, caption, null, null);
if (actions instanceof TelegramActions) {
return ((TelegramActions) actions).sendTelegramPhoto(photoURL, caption, null, null);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
}
public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable String photoURL,
@Nullable String caption, @Nullable String username, @Nullable String password) {
return invokeMethodOf(actions).sendTelegramPhoto(photoURL, caption, username, password);
if (actions instanceof TelegramActions) {
return ((TelegramActions) actions).sendTelegramPhoto(photoURL, caption, username, password);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
}
public static boolean sendTelegramAnswer(@Nullable ThingActions actions, @Nullable String replyId,
@Nullable String message) {
return invokeMethodOf(actions).sendTelegramAnswer(replyId, message);
if (actions instanceof TelegramActions) {
return ((TelegramActions) actions).sendTelegramAnswer(replyId, message);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
}
/* APIs with chatId parameter */
public static boolean sendTelegram(@Nullable ThingActions actions, @Nullable Long chatId, @Nullable String format,
@Nullable Object... args) {
return invokeMethodOf(actions).sendTelegram(chatId, format, args);
if (actions instanceof TelegramActions) {
return ((TelegramActions) actions).sendTelegram(chatId, format, args);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
}
public static boolean sendTelegramQuery(@Nullable ThingActions actions, @Nullable Long chatId,
@Nullable String message, @Nullable String replyId, @Nullable String... buttons) {
return invokeMethodOf(actions).sendTelegramQuery(chatId, message, replyId, buttons);
if (actions instanceof TelegramActions) {
return ((TelegramActions) actions).sendTelegramQuery(chatId, message, replyId, buttons);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
}
public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable Long chatId,
@Nullable String photoURL, @Nullable String caption) {
return invokeMethodOf(actions).sendTelegramPhoto(chatId, photoURL, caption, null, null);
if (actions instanceof TelegramActions) {
return ((TelegramActions) actions).sendTelegramPhoto(chatId, photoURL, caption, null, null);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
}
public static boolean sendTelegramPhoto(@Nullable ThingActions actions, @Nullable Long chatId,
@Nullable String photoURL, @Nullable String caption, @Nullable String username, @Nullable String password) {
return invokeMethodOf(actions).sendTelegramPhoto(chatId, photoURL, caption, username, password);
if (actions instanceof TelegramActions) {
return ((TelegramActions) actions).sendTelegramPhoto(chatId, photoURL, caption, username, password);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
}
public static boolean sendTelegramAnswer(@Nullable ThingActions actions, @Nullable Long chatId,
@Nullable String replyId, @Nullable String message) {
return invokeMethodOf(actions).sendTelegramAnswer(chatId, replyId, message);
if (actions instanceof TelegramActions) {
return ((TelegramActions) actions).sendTelegramAnswer(chatId, replyId, message);
} else {
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
}
public static boolean sendTelegramAnswer(@Nullable ThingActions actions, @Nullable String chatId,
@Nullable String replyId, @Nullable String message) {
return invokeMethodOf(actions).sendTelegramAnswer(Long.valueOf(chatId), replyId, message);
}
private static ITelegramActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(TelegramActions.class.getName())) {
if (actions instanceof ITelegramActions) {
return (ITelegramActions) actions;
if (actions instanceof TelegramActions) {
return ((TelegramActions) actions).sendTelegramAnswer(Long.valueOf(chatId), replyId, message);
} else {
return (ITelegramActions) Proxy.newProxyInstance(ITelegramActions.class.getClassLoader(),
new Class[] { ITelegramActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
}
}
@Override
public void setThingHandler(@Nullable ThingHandler handler) {

View File

@ -41,7 +41,7 @@ public class VolvoOnCallActions implements ThingActions {
private @Nullable VehicleHandler handler;
public VolvoOnCallActions() {
logger.info("Volvo On Call actions service instanciated");
logger.debug("Volvo On Call actions service instantiated");
}
@Override
@ -53,7 +53,7 @@ public class VolvoOnCallActions implements ThingActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
return handler;
}
@RuleAction(label = "close the car", description = "Closes the car")

View File

@ -1,32 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.xmppclient.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* This is the automation engine action handler service for the publishXMPP action.
* <p>
* <b>Note:</b>The static method <b>invokeMethodOf</b> handles the case where
* the test <i>actions instanceof XMPPActions</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link IXMPPActions} class
* can be loaded by a different classloader than the <i>actions</i> instance.
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public interface IXMPPActions {
public void publishXMPP(@Nullable String to, @Nullable String text);
}

View File

@ -16,7 +16,12 @@ import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.ReconnectionManager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.chat2.Chat;
import org.jivesoftware.smack.chat2.ChatManager;
import org.jivesoftware.smack.chat2.IncomingChatMessageListener;
@ -28,7 +33,7 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
import org.openhab.binding.xmppclient.handler.XMPPClientMessageSubscriber;
import org.openhab.binding.xmppclient.internal.handler.XMPPClientMessageSubscriber;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.xmppclient;
package org.openhab.binding.xmppclient.internal;
import org.openhab.core.thing.ThingTypeUID;

View File

@ -15,8 +15,7 @@ package org.openhab.binding.xmppclient.internal;
import java.util.Collections;
import java.util.Set;
import org.openhab.binding.xmppclient.XMPPClientBindingConstants;
import org.openhab.binding.xmppclient.handler.XMPPClientHandler;
import org.openhab.binding.xmppclient.internal.handler.XMPPClientHandler;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;

View File

@ -10,15 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.xmppclient.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
package org.openhab.binding.xmppclient.internal.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.xmppclient.handler.XMPPClientHandler;
import org.openhab.binding.xmppclient.internal.XMPPClient;
import org.openhab.binding.xmppclient.internal.handler.XMPPClientHandler;
import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.RuleAction;
import org.openhab.core.thing.binding.ThingActions;
@ -29,17 +26,12 @@ import org.slf4j.LoggerFactory;
/**
* This is the automation engine action handler service for the publishXMPP action.
* <p>
* <b>Note:</b>The static method <b>invokeMethodOf</b> handles the case where
* the test <i>actions instanceof XMPPActions</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link XMPPActions} class
* can be loaded by a different classloader than the <i>actions</i> instance.
*
* @author Pavel Gololobov - Initial contribution
*/
@ThingActionsScope(name = "xmpp")
@NonNullByDefault
public class XMPPActions implements ThingActions, IXMPPActions {
public class XMPPActions implements ThingActions {
private static final Logger logger = LoggerFactory.getLogger(XMPPActions.class);
private @Nullable XMPPClientHandler handler;
@ -50,11 +42,10 @@ public class XMPPActions implements ThingActions, IXMPPActions {
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
return handler;
}
@Override
@RuleAction(label = "publishXMPP", description = "Publish to XMPP")
@RuleAction(label = "publish a message", description = "Publish a message using XMPP.")
public void publishXMPP(@ActionInput(name = "to", label = "To", description = "Send to") @Nullable String to,
@ActionInput(name = "text", label = "Text", description = "Message text") @Nullable String text) {
XMPPClientHandler clientHandler = handler;
@ -76,25 +67,10 @@ public class XMPPActions implements ThingActions, IXMPPActions {
}
public static void publishXMPP(@Nullable ThingActions actions, @Nullable String to, @Nullable String text) {
invokeMethodOf(actions).publishXMPP(to, text);
}
private static IXMPPActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(XMPPActions.class.getName())) {
if (actions instanceof IXMPPActions) {
return (IXMPPActions) actions;
if (actions instanceof XMPPActions) {
((XMPPActions) actions).publishXMPP(to, text);
} else {
return (IXMPPActions) Proxy.newProxyInstance(IXMPPActions.class.getClassLoader(),
new Class[] { IXMPPActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of XMPPActions");
}
}
}

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.xmppclient.handler;
package org.openhab.binding.xmppclient.internal.handler;
import org.openhab.binding.xmppclient.internal.XMPPClient;
import org.openhab.core.thing.ChannelUID;

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.xmppclient.handler;
package org.openhab.binding.xmppclient.internal.handler;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.xmppclient.handler;
package org.openhab.binding.xmppclient.internal.handler;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.xmppclient.handler;
package org.openhab.binding.xmppclient.internal.handler;
import java.io.IOException;
import java.util.Collection;
@ -20,8 +20,8 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.jivesoftware.smack.*;
import org.openhab.binding.xmppclient.action.XMPPActions;
import org.openhab.binding.xmppclient.internal.XMPPClient;
import org.openhab.binding.xmppclient.internal.action.XMPPActions;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.xmppclient.handler;
package org.openhab.binding.xmppclient.internal.handler;
/**
* Subscriber interface

View File

@ -1,32 +0,0 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.zoneminder.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link IZmActions} defines the interface for all thing actions supported by the binding.
* These methods, parameters, and return types are explained in {@link ZmActions}.
*
* @author Mark Hilbush - Initial contribution
*/
@NonNullByDefault
public interface IZmActions {
public void triggerAlarm(@Nullable Number alarmDuration);
public void triggerAlarm();
public void cancelAlarm();
}

View File

@ -10,10 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.zoneminder.action;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
package org.openhab.binding.zoneminder.internal.action;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -29,23 +26,18 @@ import org.slf4j.LoggerFactory;
/**
* The {@link ZmActions} defines the thing actions provided by this binding.
*
* <b>Note:</b>The static method <b>invokeMethodOf</b> handles the case where
* the test <i>actions instanceof ZmActions</i> fails. This test can fail
* due to an issue in openHAB core v2.5.0 where the {@link ZmActions} class
* can be loaded by a different classloader than the <i>actions</i> instance.
*
* @author Mark Hilbush - Initial contribution
*/
@ThingActionsScope(name = "zm")
@NonNullByDefault
public class ZmActions implements ThingActions, IZmActions {
public class ZmActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(ZmActions.class);
private @Nullable ZmMonitorHandler handler;
@Override
public @Nullable ThingHandler getThingHandler() {
return this.handler;
return handler;
}
@Override
@ -55,31 +47,11 @@ public class ZmActions implements ThingActions, IZmActions {
}
}
private static IZmActions invokeMethodOf(@Nullable ThingActions actions) {
if (actions == null) {
throw new IllegalArgumentException("actions cannot be null");
}
if (actions.getClass().getName().equals(ZmActions.class.getName())) {
if (actions instanceof IZmActions) {
return (IZmActions) actions;
} else {
return (IZmActions) Proxy.newProxyInstance(IZmActions.class.getClassLoader(),
new Class[] { IZmActions.class }, (Object proxy, Method method, Object[] args) -> {
Method m = actions.getClass().getDeclaredMethod(method.getName(),
method.getParameterTypes());
return m.invoke(actions, args);
});
}
}
throw new IllegalArgumentException("Actions is not an instance of ZmActions");
}
/**
* The Trigger Alarm function triggers an alarm that will run for the number of seconds
* specified by the supplied parameter duration.
*/
@Override
@RuleAction(label = "TriggerAlarm", description = "Trigger an alarm on the monitor.")
@RuleAction(label = "trigger an alarm", description = "Trigger an alarm on the monitor.")
public void triggerAlarm(
@ActionInput(name = "duration", description = "The duration of the alarm in seconds.") @Nullable Number duration) {
logger.debug("ZmActions: Action 'TriggerAlarm' called");
@ -92,15 +64,18 @@ public class ZmActions implements ThingActions, IZmActions {
}
public static void triggerAlarm(@Nullable ThingActions actions, @Nullable Number alarmDuration) {
invokeMethodOf(actions).triggerAlarm(alarmDuration);
if (actions instanceof ZmActions) {
((ZmActions) actions).triggerAlarm(alarmDuration);
} else {
throw new IllegalArgumentException("Actions is not an instance of ZmActions");
}
}
/**
* The Trigger Alarm function triggers an alarm that will run for the number of seconds
* specified in the thing configuration.
*/
@Override
@RuleAction(label = "TriggerAlarm", description = "Trigger an alarm on the monitor.")
@RuleAction(label = "trigger an alarm", description = "Trigger an alarm on the monitor.")
public void triggerAlarm() {
logger.debug("ZmActions: Action 'TriggerAlarm' called");
ZmMonitorHandler localHandler = handler;
@ -112,14 +87,17 @@ public class ZmActions implements ThingActions, IZmActions {
}
public static void triggerAlarm(@Nullable ThingActions actions) {
invokeMethodOf(actions).triggerAlarm();
if (actions instanceof ZmActions) {
((ZmActions) actions).triggerAlarm();
} else {
throw new IllegalArgumentException("Actions is not an instance of ZmActions");
}
}
/**
* The Cancel Alarm function cancels a running alarm.
*/
@Override
@RuleAction(label = "CancelAlarm", description = "Cancel a running alarm.")
@RuleAction(label = "cancel a running alarm", description = "Cancel a running alarm.")
public void cancelAlarm() {
logger.debug("ZmActions: Action 'CancelAlarm' called");
ZmMonitorHandler localHandler = handler;
@ -131,6 +109,10 @@ public class ZmActions implements ThingActions, IZmActions {
}
public static void cancelAlarm(@Nullable ThingActions actions) {
invokeMethodOf(actions).cancelAlarm();
if (actions instanceof ZmActions) {
((ZmActions) actions).cancelAlarm();
} else {
throw new IllegalArgumentException("Actions is not an instance of ZmActions");
}
}
}

View File

@ -26,7 +26,7 @@ import javax.measure.quantity.Time;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.zoneminder.action.ZmActions;
import org.openhab.binding.zoneminder.internal.action.ZmActions;
import org.openhab.binding.zoneminder.internal.config.ZmMonitorConfig;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.library.types.DateTimeType;