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.alarmdecoder.internal.actions;
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;
27 * The {@link BridgeActions} class defines thing actions for alarmdecoder bridges.
29 * @author Bob Adair - Initial contribution
31 @ThingActionsScope(name = "alarmdecoder")
33 public class BridgeActions implements ThingActions {
35 private final Logger logger = LoggerFactory.getLogger(BridgeActions.class);
37 private @Nullable ADBridgeHandler bridge;
39 public BridgeActions() {
40 logger.trace("Alarm Decoder bridge actions service created");
44 public void setThingHandler(@Nullable ThingHandler handler) {
45 if (handler instanceof ADBridgeHandler bridgeHandler) {
46 this.bridge = bridgeHandler;
51 public @Nullable ThingHandler getThingHandler() {
58 @RuleAction(label = "reboot the device", description = "Reboot the Alarm Decoder device.")
59 public void reboot() {
60 ADBridgeHandler bridge = this.bridge;
62 bridge.sendADCommand(ADCommand.reboot());
63 logger.debug("Sending reboot command.");
65 logger.debug("Request for reboot action, but bridge is undefined.");
69 // Static method for Rules DSL backward compatibility
70 public static void reboot(ThingActions actions) {
71 ((BridgeActions) actions).reboot();