]> git.basschouten.com Git - openhab-addons.git/blob
cae2d06cb65deadf4030c6241a69740a2f3a61da
[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.caddx.internal.action;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.caddx.internal.handler.ThingHandlerZone;
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.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * This is the automation engine action handler service for the
27  * caddx bridge actions.
28  *
29  * @author Georgios Moutsos - Initial contribution
30  */
31 @ThingActionsScope(name = "caddx")
32 @NonNullByDefault
33 public class CaddxZoneActions implements ThingActions {
34     private final Logger logger = LoggerFactory.getLogger(CaddxZoneActions.class);
35
36     private static final String HANDLER_IS_NULL = "ThingHandlerZone is null!";
37
38     private @Nullable ThingHandlerZone handler;
39
40     @Override
41     public void setThingHandler(@Nullable ThingHandler handler) {
42         if (handler instanceof ThingHandlerZone) {
43             this.handler = (ThingHandlerZone) handler;
44         }
45     }
46
47     @Override
48     public @Nullable ThingHandler getThingHandler() {
49         return this.handler;
50     }
51
52     @RuleAction(label = "bypass", description = "Bypass the zone")
53     public void bypass() {
54         // Check of parameters
55         ThingHandlerZone thingHandler = this.handler;
56         if (thingHandler == null) {
57             logger.debug(HANDLER_IS_NULL);
58             return;
59         }
60
61         thingHandler.bypass();
62     }
63
64     public static void bypass(ThingActions actions) {
65         ((CaddxZoneActions) actions).bypass();
66     }
67 }