2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.max.internal.actions;
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;
27 * The {@link MaxCubeActions} class defines rule actions for MAX! Cube
29 * @author Christoph Weitkamp - Initial contribution
31 @ThingActionsScope(name = "max-cube")
33 public class MaxCubeActions implements ThingActions {
35 private final Logger logger = LoggerFactory.getLogger(MaxCubeActions.class);
37 private @Nullable MaxCubeBridgeHandler handler;
40 public void setThingHandler(@Nullable ThingHandler handler) {
41 if (handler instanceof MaxCubeBridgeHandler bridgeHandler) {
42 this.handler = bridgeHandler;
47 public @Nullable ThingHandler getThingHandler() {
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!");
58 actionsHandler.backup();
62 public static boolean backup(ThingActions actions) {
63 return ((MaxCubeActions) actions).backup();
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!");
73 actionsHandler.cubeConfigReset();
77 public static boolean reset(ThingActions actions) {
78 return ((MaxCubeActions) actions).resetConfig();
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!");
88 actionsHandler.cubeReboot();
92 public static boolean reboot(ThingActions actions) {
93 return ((MaxCubeActions) actions).reboot();