]> git.basschouten.com Git - openhab-addons.git/blob
fb2e67ecb847d0d43aa012b9182f5ffb84de4ff8
[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.fronius.internal.action;
14
15 import java.time.LocalTime;
16 import java.time.ZonedDateTime;
17
18 import javax.measure.quantity.Power;
19
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;
31
32 /**
33  * Implementation of the {@link ThingActions} interface used for controlling battery charging and discharging for
34  * Fronius hybrid inverters.
35  *
36  * @author Florian Hotze - Initial contribution
37  */
38 @Component(scope = ServiceScope.PROTOTYPE, service = FroniusSymoInverterActions.class)
39 @ThingActionsScope(name = "fronius")
40 @NonNullByDefault
41 public class FroniusSymoInverterActions implements ThingActions {
42     private @Nullable FroniusSymoInverterHandler handler;
43
44     public static void resetBatteryControl(ThingActions actions) {
45         if (actions instanceof FroniusSymoInverterActions froniusSymoInverterActions) {
46             froniusSymoInverterActions.resetBatteryControl();
47         } else {
48             throw new IllegalArgumentException(
49                     "The 'actions' argument is not an instance of FroniusSymoInverterActions");
50         }
51     }
52
53     public static void holdBatteryCharge(ThingActions actions) {
54         if (actions instanceof FroniusSymoInverterActions froniusSymoInverterActions) {
55             froniusSymoInverterActions.holdBatteryCharge();
56         } else {
57             throw new IllegalArgumentException(
58                     "The 'actions' argument is not an instance of FroniusSymoInverterActions");
59         }
60     }
61
62     public static void addHoldBatteryChargeSchedule(ThingActions actions, LocalTime from, LocalTime until) {
63         if (actions instanceof FroniusSymoInverterActions froniusSymoInverterActions) {
64             froniusSymoInverterActions.addHoldBatteryChargeSchedule(from, until);
65         } else {
66             throw new IllegalArgumentException(
67                     "The 'actions' argument is not an instance of FroniusSymoInverterActions");
68         }
69     }
70
71     public static void addHoldBatteryChargeSchedule(ThingActions actions, ZonedDateTime from, ZonedDateTime until) {
72         addHoldBatteryChargeSchedule(actions, from.toLocalTime(), until.toLocalTime());
73     }
74
75     public static void forceBatteryCharging(ThingActions actions, QuantityType<Power> power) {
76         if (actions instanceof FroniusSymoInverterActions froniusSymoInverterActions) {
77             froniusSymoInverterActions.forceBatteryCharging(power);
78         } else {
79             throw new IllegalArgumentException(
80                     "The 'actions' argument is not an instance of FroniusSymoInverterActions");
81         }
82     }
83
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);
88         } else {
89             throw new IllegalArgumentException(
90                     "The 'actions' argument is not an instance of FroniusSymoInverterActions");
91         }
92     }
93
94     public static void addForcedBatteryChargingSchedule(ThingActions actions, ZonedDateTime from, ZonedDateTime until,
95             QuantityType<Power> power) {
96         addForcedBatteryChargingSchedule(actions, from.toLocalTime(), until.toLocalTime(), power);
97     }
98
99     @Override
100     public void setThingHandler(@Nullable ThingHandler handler) {
101         this.handler = (FroniusSymoInverterHandler) handler;
102     }
103
104     @Override
105     public @Nullable ThingHandler getThingHandler() {
106         return handler;
107     }
108
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();
114         }
115     }
116
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();
122         }
123     }
124
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);
132         }
133     }
134
135     public void addHoldBatteryChargeSchedule(ZonedDateTime from, ZonedDateTime until) {
136         addHoldBatteryChargeSchedule(from.toLocalTime(), until.toLocalTime());
137     }
138
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);
145         }
146     }
147
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);
156         }
157     }
158
159     public void addForcedBatteryChargingSchedule(ZonedDateTime from, ZonedDateTime until, QuantityType<Power> power) {
160         addForcedBatteryChargingSchedule(from.toLocalTime(), until.toLocalTime(), power);
161     }
162 }