]> git.basschouten.com Git - openhab-addons.git/blob
a126b325890c7d6f53b3646a33c66f6c8f09ab6d
[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.gce.internal.action;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.gce.internal.handler.Ipx800v3Handler;
18 import org.openhab.core.automation.annotation.ActionInput;
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  * Defines rule actions for the GCE binding.
28  *
29  * @author GaĆ«l L'hopital - Initial contribution
30  */
31 @ThingActionsScope(name = "gce")
32 @NonNullByDefault
33 public class Ipx800Actions implements ThingActions {
34     private final Logger logger = LoggerFactory.getLogger(Ipx800Actions.class);
35
36     protected @Nullable Ipx800v3Handler handler;
37
38     public Ipx800Actions() {
39         logger.debug("IPX800 actions service instanciated");
40     }
41
42     @Override
43     public void setThingHandler(@Nullable ThingHandler handler) {
44         if (handler instanceof Ipx800v3Handler ipx800v3Handler) {
45             this.handler = ipx800v3Handler;
46         }
47     }
48
49     @Override
50     public @Nullable ThingHandler getThingHandler() {
51         return handler;
52     }
53
54     @RuleAction(label = "reset a counter", description = "Resets to 0 value of a given counter.")
55     public void resetCounter(
56             @ActionInput(name = "counter", label = "Counter", required = true, description = "Id of the counter", type = "java.lang.Integer") Integer counter) {
57         logger.debug("IPX800 action 'resetCounter' called");
58         Ipx800v3Handler theHandler = this.handler;
59         if (theHandler != null) {
60             theHandler.resetCounter(counter);
61         } else {
62             logger.warn("Method call resetCounter failed because IPX800 action service ThingHandler is null!");
63         }
64     }
65
66     @RuleAction(label = "reset the PLC", description = "Restarts the IPX800.")
67     public void reset(
68             @ActionInput(name = "placeholder", label = "Placeholder", required = false, description = "This parameter is not used", type = "java.lang.Integer") @Nullable Integer placeholder) {
69         logger.debug("IPX800 action 'reset' called");
70         Ipx800v3Handler theHandler = this.handler;
71         if (theHandler != null) {
72             theHandler.reset();
73         } else {
74             logger.warn("Method call reset failed because IPX800 action service ThingHandler is null!");
75         }
76     }
77
78     public static void resetCounter(ThingActions actions, Integer counter) {
79         ((Ipx800Actions) actions).resetCounter(counter);
80     }
81
82     public static void reset(ThingActions actions, @Nullable Integer placeholder) {
83         ((Ipx800Actions) actions).reset(placeholder);
84     }
85 }