]> git.basschouten.com Git - openhab-addons.git/blob
b719cfb1b77736fb6aa98cb7b7c86c505ca4716d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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 bridgeHandler) {
42             this.handler = bridgeHandler;
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(ThingActions actions) {
63         return ((MaxCubeActions) actions).backup();
64     }
65
66     @RuleAction(label = "reset the Cube configuration", description = "Resets the MAX! Cube room and device information. Devices will need to be included again!")
67     public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean resetConfig() {
68         MaxCubeBridgeHandler actionsHandler = handler;
69         if (actionsHandler == null) {
70             logger.info("MaxCubeActions: Action service ThingHandler is null!");
71             return false;
72         }
73         actionsHandler.cubeConfigReset();
74         return true;
75     }
76
77     public static boolean reset(ThingActions actions) {
78         return ((MaxCubeActions) actions).resetConfig();
79     }
80
81     @RuleAction(label = "restart the Cube", description = "Restarts the MAX! Cube.")
82     public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean reboot() {
83         MaxCubeBridgeHandler actionsHandler = handler;
84         if (actionsHandler == null) {
85             logger.info("MaxCubeActions: Action service ThingHandler is null!");
86             return false;
87         }
88         actionsHandler.cubeReboot();
89         return true;
90     }
91
92     public static boolean reboot(ThingActions actions) {
93         return ((MaxCubeActions) actions).reboot();
94     }
95 }