]> git.basschouten.com Git - openhab-addons.git/blob
e727f58283e51c6470cc91a57ea1925eddde5fcb
[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.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.MaxDevicesHandler;
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 MaxDevicesActions} class defines rule actions for MAX! devices
28  *
29  * @author Christoph Weitkamp - Initial contribution
30  */
31 @ThingActionsScope(name = "max-devices")
32 @NonNullByDefault
33 public class MaxDevicesActions implements ThingActions {
34
35     private final Logger logger = LoggerFactory.getLogger(MaxDevicesActions.class);
36
37     private @Nullable MaxDevicesHandler handler;
38
39     @Override
40     public void setThingHandler(@Nullable ThingHandler handler) {
41         if (handler instanceof MaxDevicesHandler devicesHandler) {
42             this.handler = devicesHandler;
43         }
44     }
45
46     @Override
47     public @Nullable ThingHandler getThingHandler() {
48         return handler;
49     }
50
51     @RuleAction(label = "delete the device from the Cube", description = "Deletes the device from the MAX! Cube. Device will need to be included again!")
52     public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean deleteFromCube() {
53         MaxDevicesHandler actionsHandler = handler;
54         if (actionsHandler == null) {
55             logger.info("MaxDevicesActions: Action service ThingHandler is null!");
56             return false;
57         }
58         actionsHandler.deviceDelete();
59         return true;
60     }
61
62     public static boolean deleteFromCube(ThingActions actions) {
63         return ((MaxDevicesActions) actions).deleteFromCube();
64     }
65 }