]> git.basschouten.com Git - openhab-addons.git/blob
0814fe1e77438e1832731f00f9453a4b1750d0f9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.max.internal.actions;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.max.internal.handler.MaxCubeBridgeHandler;
18 import org.openhab.core.automation.annotation.ActionOutput;
19 import org.openhab.core.automation.annotation.RuleAction;
20 import org.openhab.core.thing.binding.ThingActions;
21 import org.openhab.core.thing.binding.ThingActionsScope;
22 import org.openhab.core.thing.binding.ThingHandler;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * The {@link MaxCubeActions} class defines rule actions for MAX! Cube
28  *
29  * @author Christoph Weitkamp - Initial contribution
30  */
31 @ThingActionsScope(name = "max-cube")
32 @NonNullByDefault
33 public class MaxCubeActions implements ThingActions {
34
35     private final Logger logger = LoggerFactory.getLogger(MaxCubeActions.class);
36
37     private @Nullable MaxCubeBridgeHandler handler;
38
39     @Override
40     public void setThingHandler(@Nullable ThingHandler handler) {
41         if (handler instanceof MaxCubeBridgeHandler) {
42             this.handler = (MaxCubeBridgeHandler) handler;
43         }
44     }
45
46     @Override
47     public @Nullable ThingHandler getThingHandler() {
48         return handler;
49     }
50
51     @RuleAction(label = "backup the Cube data", description = "Creates a backup of the MAX! Cube data.")
52     public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean backup() {
53         MaxCubeBridgeHandler actionsHandler = handler;
54         if (actionsHandler == null) {
55             logger.info("MaxCubeActions: Action service ThingHandler is null!");
56             return false;
57         }
58         actionsHandler.backup();
59         return true;
60     }
61
62     public static boolean backup(@Nullable ThingActions actions) {
63         if (actions instanceof MaxCubeActions) {
64             return ((MaxCubeActions) actions).backup();
65         } else {
66             throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions");
67         }
68     }
69
70     @RuleAction(label = "reset the Cube configuration", description = "Resets the MAX! Cube room and device information. Devices will need to be included again!")
71     public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean resetConfig() {
72         MaxCubeBridgeHandler actionsHandler = handler;
73         if (actionsHandler == null) {
74             logger.info("MaxCubeActions: Action service ThingHandler is null!");
75             return false;
76         }
77         actionsHandler.cubeConfigReset();
78         return true;
79     }
80
81     public static boolean reset(@Nullable ThingActions actions) {
82         if (actions instanceof MaxCubeActions) {
83             return ((MaxCubeActions) actions).resetConfig();
84         } else {
85             throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions");
86         }
87     }
88
89     @RuleAction(label = "restart the Cube", description = "Restarts the MAX! Cube.")
90     public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean reboot() {
91         MaxCubeBridgeHandler actionsHandler = handler;
92         if (actionsHandler == null) {
93             logger.info("MaxCubeActions: Action service ThingHandler is null!");
94             return false;
95         }
96         actionsHandler.cubeReboot();
97         return true;
98     }
99
100     public static boolean reboot(@Nullable ThingActions actions) {
101         if (actions instanceof MaxCubeActions) {
102             return ((MaxCubeActions) actions).reboot();
103         } else {
104             throw new IllegalArgumentException("Actions is not an instance of MaxCubeActions");
105         }
106     }
107 }