-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[avmfritz] Added ThingActions to handle Boost and Window-Open modes f…
…or heating devices / groups (#8222) * Added ThingActions to handle Boost and Window-Open modes Signed-off-by: Christoph Weitkamp <[email protected]>
- Loading branch information
Showing
23 changed files
with
705 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...g.avmfritz/src/main/java/org/openhab/binding/avmfritz/actions/AVMFritzHeatingActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* 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.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.eclipse.smarthome.core.thing.binding.ThingActions; | ||
import org.eclipse.smarthome.core.thing.binding.ThingActionsScope; | ||
import org.eclipse.smarthome.core.thing.binding.ThingHandler; | ||
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.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The {@link AVMFritzHeatingActions} defines thing actions for heating devices / groups of the avmfritz binding. | ||
* | ||
* @author Christoph Weitkamp - Initial contribution | ||
*/ | ||
@ThingActionsScope(name = "avmfritz") | ||
@NonNullByDefault | ||
public class AVMFritzHeatingActions implements ThingActions, IAVMFritzHeatingActions { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(AVMFritzHeatingActions.class); | ||
|
||
private @Nullable AVMFritzHeatingActionsHandler handler; | ||
|
||
@Override | ||
public void setThingHandler(@Nullable ThingHandler handler) { | ||
this.handler = (AVMFritzHeatingActionsHandler) handler; | ||
} | ||
|
||
@Override | ||
public @Nullable ThingHandler getThingHandler() { | ||
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) { | ||
AVMFritzHeatingActionsHandler actionsHandler = handler; | ||
if (actionsHandler == null) { | ||
throw new IllegalArgumentException("AVMFritzHeatingActions ThingHandler is null!"); | ||
} | ||
if (duration == null) { | ||
throw new IllegalArgumentException("Cannot set Boost mode as 'duration' is null!"); | ||
} | ||
actionsHandler.setBoostMode(duration.longValue()); | ||
} | ||
|
||
public static void setBoostMode(@Nullable ThingActions actions, @Nullable Long duration) { | ||
invokeMethodOf(actions).setBoostMode(duration); | ||
} | ||
|
||
@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) { | ||
AVMFritzHeatingActionsHandler actionsHandler = handler; | ||
if (actionsHandler == null) { | ||
throw new IllegalArgumentException("AVMFritzHeatingActions ThingHandler is null!"); | ||
} | ||
if (duration == null) { | ||
throw new IllegalArgumentException("Cannot set Window Open mode as 'duration' is null!"); | ||
} | ||
actionsHandler.setWindowOpenMode(duration.longValue()); | ||
} | ||
|
||
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; | ||
} 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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
.../src/main/java/org/openhab/binding/avmfritz/internal/actions/IAVMFritzHeatingActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* 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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.