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.fronius.internal.action;
15 import java.time.LocalTime;
16 import java.time.ZonedDateTime;
18 import javax.measure.quantity.Power;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.fronius.internal.handler.FroniusSymoInverterHandler;
23 import org.openhab.core.automation.annotation.ActionInput;
24 import org.openhab.core.automation.annotation.RuleAction;
25 import org.openhab.core.library.types.QuantityType;
26 import org.openhab.core.thing.binding.ThingActions;
27 import org.openhab.core.thing.binding.ThingActionsScope;
28 import org.openhab.core.thing.binding.ThingHandler;
29 import org.osgi.service.component.annotations.Component;
30 import org.osgi.service.component.annotations.ServiceScope;
33 * Implementation of the {@link ThingActions} interface used for controlling battery charging and discharging for
34 * Fronius hybrid inverters.
36 * @author Florian Hotze - Initial contribution
38 @Component(scope = ServiceScope.PROTOTYPE, service = FroniusSymoInverterActions.class)
39 @ThingActionsScope(name = "fronius")
41 public class FroniusSymoInverterActions implements ThingActions {
42 private @Nullable FroniusSymoInverterHandler handler;
44 public static void resetBatteryControl(ThingActions actions) {
45 if (actions instanceof FroniusSymoInverterActions froniusSymoInverterActions) {
46 froniusSymoInverterActions.resetBatteryControl();
48 throw new IllegalArgumentException(
49 "The 'actions' argument is not an instance of FroniusSymoInverterActions");
53 public static void holdBatteryCharge(ThingActions actions) {
54 if (actions instanceof FroniusSymoInverterActions froniusSymoInverterActions) {
55 froniusSymoInverterActions.holdBatteryCharge();
57 throw new IllegalArgumentException(
58 "The 'actions' argument is not an instance of FroniusSymoInverterActions");
62 public static void addHoldBatteryChargeSchedule(ThingActions actions, LocalTime from, LocalTime until) {
63 if (actions instanceof FroniusSymoInverterActions froniusSymoInverterActions) {
64 froniusSymoInverterActions.addHoldBatteryChargeSchedule(from, until);
66 throw new IllegalArgumentException(
67 "The 'actions' argument is not an instance of FroniusSymoInverterActions");
71 public static void addHoldBatteryChargeSchedule(ThingActions actions, ZonedDateTime from, ZonedDateTime until) {
72 addHoldBatteryChargeSchedule(actions, from.toLocalTime(), until.toLocalTime());
75 public static void forceBatteryCharging(ThingActions actions, QuantityType<Power> power) {
76 if (actions instanceof FroniusSymoInverterActions froniusSymoInverterActions) {
77 froniusSymoInverterActions.forceBatteryCharging(power);
79 throw new IllegalArgumentException(
80 "The 'actions' argument is not an instance of FroniusSymoInverterActions");
84 public static void addForcedBatteryChargingSchedule(ThingActions actions, LocalTime from, LocalTime until,
85 QuantityType<Power> power) {
86 if (actions instanceof FroniusSymoInverterActions froniusSymoInverterActions) {
87 froniusSymoInverterActions.addForcedBatteryChargingSchedule(from, until, power);
89 throw new IllegalArgumentException(
90 "The 'actions' argument is not an instance of FroniusSymoInverterActions");
94 public static void addForcedBatteryChargingSchedule(ThingActions actions, ZonedDateTime from, ZonedDateTime until,
95 QuantityType<Power> power) {
96 addForcedBatteryChargingSchedule(actions, from.toLocalTime(), until.toLocalTime(), power);
100 public void setThingHandler(@Nullable ThingHandler handler) {
101 this.handler = (FroniusSymoInverterHandler) handler;
105 public @Nullable ThingHandler getThingHandler() {
109 @RuleAction(label = "@text/actions.reset-battery-control.label", description = "@text/actions.reset-battery-control.description")
110 public void resetBatteryControl() {
111 FroniusSymoInverterHandler handler = this.handler;
112 if (handler != null) {
113 handler.resetBatteryControl();
117 @RuleAction(label = "@text/actions.hold-battery-charge.label", description = "@text/actions.hold-battery-charge.description")
118 public void holdBatteryCharge() {
119 FroniusSymoInverterHandler handler = this.handler;
120 if (handler != null) {
121 handler.holdBatteryCharge();
125 @RuleAction(label = "@text/actions.add-hold-battery-charge-schedule.label", description = "@text/actions.add-hold-battery-charge-schedule.description")
126 public void addHoldBatteryChargeSchedule(
127 @ActionInput(name = "from", label = "@text/actions.from.label", description = "@text/actions.from.description") LocalTime from,
128 @ActionInput(name = "until", label = "@text/actions.until.label", description = "@text/actions.until.description") LocalTime until) {
129 FroniusSymoInverterHandler handler = this.handler;
130 if (handler != null) {
131 handler.addHoldBatteryChargeSchedule(from, until);
135 public void addHoldBatteryChargeSchedule(ZonedDateTime from, ZonedDateTime until) {
136 addHoldBatteryChargeSchedule(from.toLocalTime(), until.toLocalTime());
139 @RuleAction(label = "@text/actions.force-battery-charging.label", description = "@text/actions.force-battery-charging.description")
140 public void forceBatteryCharging(
141 @ActionInput(name = "power", label = "@text/actions.power.label", description = "@text/actions.power.label") QuantityType<Power> power) {
142 FroniusSymoInverterHandler handler = this.handler;
143 if (handler != null) {
144 handler.forceBatteryCharging(power);
148 @RuleAction(label = "@text/actions.add-forced-battery-charging-schedule.label", description = "@text/actions.add-forced-battery-charging-schedule.description")
149 public void addForcedBatteryChargingSchedule(
150 @ActionInput(name = "from", label = "@text/actions.from.label", description = "@text/actions.from.description") LocalTime from,
151 @ActionInput(name = "until", label = "@text/actions.until.label", description = "@text/actions.until.description") LocalTime until,
152 @ActionInput(name = "power", label = "@text/actions.power.label", description = "@text/actions.power.label") QuantityType<Power> power) {
153 FroniusSymoInverterHandler handler = this.handler;
154 if (handler != null) {
155 handler.addForcedBatteryChargingSchedule(from, until, power);
159 public void addForcedBatteryChargingSchedule(ZonedDateTime from, ZonedDateTime until, QuantityType<Power> power) {
160 addForcedBatteryChargingSchedule(from.toLocalTime(), until.toLocalTime(), power);