]> git.basschouten.com Git - openhab-addons.git/blob
d111c807a030033a9cfd12daa8855d50e5155297
[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.freeboxos.internal.action;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.freeboxos.internal.handler.ServerHandler;
18 import org.openhab.core.automation.annotation.RuleAction;
19 import org.openhab.core.thing.binding.ThingActions;
20 import org.openhab.core.thing.binding.ThingActionsScope;
21 import org.openhab.core.thing.binding.ThingHandler;
22 import org.osgi.service.component.annotations.Component;
23 import org.osgi.service.component.annotations.ServiceScope;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * The {ServerActions} class is responsible to call corresponding actions on Freebox Server
29  *
30  * @author GaĆ«l L'hopital - Initial contribution
31  */
32 @Component(scope = ServiceScope.PROTOTYPE, service = ServerActions.class)
33 @ThingActionsScope(name = "freeboxos")
34 @NonNullByDefault
35 public class ServerActions implements ThingActions {
36     private final Logger logger = LoggerFactory.getLogger(ServerActions.class);
37     private @Nullable ServerHandler handler;
38
39     @Override
40     public void setThingHandler(@Nullable ThingHandler handler) {
41         if (handler instanceof ServerHandler serverHandler) {
42             this.handler = serverHandler;
43         }
44     }
45
46     @Override
47     public @Nullable ThingHandler getThingHandler() {
48         return this.handler;
49     }
50
51     @RuleAction(label = "reboot freebox server", description = "Reboots the Freebox Server")
52     public void reboot() {
53         logger.debug("Server reboot called");
54         ServerHandler serverHandler = this.handler;
55         if (serverHandler != null) {
56             serverHandler.reboot();
57         } else {
58             logger.warn("Freebox Action service ThingHandler is null");
59         }
60     }
61 }