]> git.basschouten.com Git - openhab-addons.git/blob
bd55c04a079856fa337f9d36e172854f6228feef
[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.growatt.internal.action;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.growatt.internal.handler.GrowattInverterHandler;
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  * Implementation of the {@link ThingActions} interface used for setting up battery charging and discharging programs.
28  *
29  * @author Andrew Fiddian-Green - Initial contribution
30  */
31 @ThingActionsScope(name = "growatt")
32 @NonNullByDefault
33 public class GrowattActions implements ThingActions {
34
35     private final Logger logger = LoggerFactory.getLogger(GrowattActions.class);
36     private @Nullable GrowattInverterHandler handler;
37
38     public static void setupBatteryProgram(ThingActions actions, Integer programMode, @Nullable Integer powerLevel,
39             @Nullable Integer stopSOC, @Nullable Boolean enableAcCharging, @Nullable String startTime,
40             @Nullable String stopTime, @Nullable Boolean enableProgram) {
41         if (actions instanceof GrowattActions growattActions) {
42             growattActions.setupBatteryProgram(programMode, powerLevel, stopSOC, enableAcCharging, startTime, stopTime,
43                     enableProgram);
44         } else {
45             throw new IllegalArgumentException("The 'actions' argument is not an instance of GrowattActions");
46         }
47     }
48
49     @Override
50     public @Nullable ThingHandler getThingHandler() {
51         return handler;
52     }
53
54     @Override
55     public void setThingHandler(@Nullable ThingHandler handler) {
56         this.handler = (handler instanceof GrowattInverterHandler growattHandler) ? growattHandler : null;
57     }
58
59     @RuleAction(label = "@text/actions.battery-program.label", description = "@text/actions.battery-program.description")
60     public void setupBatteryProgram(
61             @ActionInput(name = "program-mode", label = "@text/actions.program-mode.label", description = "@text/actions.program-mode.description") Integer programMode,
62             @ActionInput(name = "power-level", label = "@text/actions.power-level.label", description = "@text/actions.power-level.description") @Nullable Integer powerLevel,
63             @ActionInput(name = "stop-soc", label = "@text/actions.stop-soc.label", description = "@text/actions.stop-soc.description") @Nullable Integer stopSOC,
64             @ActionInput(name = "enable-ac-charging", label = "@text/actions.enable-ac-charging.label", description = "@text/actions.enable-ac-charging.description") @Nullable Boolean enableAcCharging,
65             @ActionInput(name = "start-time", label = "@text/actions.start-time.label", description = "@text/actions.start-time.description") @Nullable String startTime,
66             @ActionInput(name = "stop-time", label = "@text/actions.stop-time.label", description = "@text/actions.stop-time.description") @Nullable String stopTime,
67             @ActionInput(name = "enable-program", label = "@text/actions.enable-program.label", description = "@text/actions.enable-program.description") @Nullable Boolean enableProgram) {
68         GrowattInverterHandler handler = this.handler;
69         if (handler != null) {
70             handler.setupBatteryProgram(programMode, powerLevel, stopSOC, enableAcCharging, startTime, stopTime,
71                     enableProgram);
72         } else {
73             logger.warn("ThingHandler is null.");
74         }
75     }
76 }