2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.growatt.internal.action;
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;
27 * Implementation of the {@link ThingActions} interface used for setting up battery charging and discharging programs.
29 * @author Andrew Fiddian-Green - Initial contribution
31 @ThingActionsScope(name = "growatt")
33 public class GrowattActions implements ThingActions {
35 private final Logger logger = LoggerFactory.getLogger(GrowattActions.class);
36 private @Nullable GrowattInverterHandler handler;
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,
45 throw new IllegalArgumentException("The 'actions' argument is not an instance of GrowattActions");
50 public @Nullable ThingHandler getThingHandler() {
55 public void setThingHandler(@Nullable ThingHandler handler) {
56 this.handler = (handler instanceof GrowattInverterHandler growattHandler) ? growattHandler : null;
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,
73 logger.warn("ThingHandler is null.");