]> git.basschouten.com Git - openhab-addons.git/blob
33114c893d5bac15a3f034a1be1a91f7341ddfe3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.alarmdecoder.internal.actions;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.alarmdecoder.internal.handler.ADBridgeHandler;
18 import org.openhab.binding.alarmdecoder.internal.protocol.ADCommand;
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 BridgeActions} class defines thing actions for alarmdecoder bridges.
28  *
29  * @author Bob Adair - Initial contribution
30  */
31 @ThingActionsScope(name = "alarmdecoder")
32 @NonNullByDefault
33 public class BridgeActions implements ThingActions {
34
35     private final Logger logger = LoggerFactory.getLogger(BridgeActions.class);
36
37     private @Nullable ADBridgeHandler bridge;
38
39     public BridgeActions() {
40         logger.trace("Alarm Decoder bridge actions service created");
41     }
42
43     @Override
44     public void setThingHandler(@Nullable ThingHandler handler) {
45         if (handler instanceof ADBridgeHandler bridgeHandler) {
46             this.bridge = bridgeHandler;
47         }
48     }
49
50     @Override
51     public @Nullable ThingHandler getThingHandler() {
52         return bridge;
53     }
54
55     /**
56      * Reboot thing action
57      */
58     @RuleAction(label = "reboot the device", description = "Reboot the Alarm Decoder device.")
59     public void reboot() {
60         ADBridgeHandler bridge = this.bridge;
61         if (bridge != null) {
62             bridge.sendADCommand(ADCommand.reboot());
63             logger.debug("Sending reboot command.");
64         } else {
65             logger.debug("Request for reboot action, but bridge is undefined.");
66         }
67     }
68
69     // Static method for Rules DSL backward compatibility
70     public static void reboot(ThingActions actions) {
71         ((BridgeActions) actions).reboot();
72     }
73 }