]> git.basschouten.com Git - openhab-addons.git/blob
e95bcca8fb624e3392088434e7b3628a19407838
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.mielecloud.internal.webservice.api.json;
14
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Objects;
18 import java.util.Optional;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22
23 /**
24  * Immutable POJO representing the state of a device. Queried from the Miele REST API.
25  *
26  * @author Björn Lange - Initial contribution
27  * @author Benjamin Bolte - Add plate step
28  * @author Björn Lange - Add elapsed time channel, add eco feedback
29  */
30 @NonNullByDefault
31 public class State {
32     @Nullable
33     private Status status;
34     /**
35      * Currently used by Miele webservice.
36      */
37     @Nullable
38     private ProgramId ProgramID;
39     /**
40      * Planned to be used in the future.
41      */
42     @Nullable
43     private ProgramId programId;
44     @Nullable
45     private ProgramType programType;
46     @Nullable
47     private ProgramPhase programPhase;
48     @Nullable
49     private final List<Integer> remainingTime = null;
50     @Nullable
51     private final List<Integer> startTime = null;
52     @Nullable
53     private final List<Temperature> targetTemperature = null;
54     @Nullable
55     private final List<Temperature> temperature = null;
56     @Nullable
57     private Boolean signalInfo;
58     @Nullable
59     private Boolean signalFailure;
60     @Nullable
61     private Boolean signalDoor;
62     @Nullable
63     private RemoteEnable remoteEnable;
64     @Nullable
65     private Integer light;
66     @Nullable
67     private final List<Integer> elapsedTime = null;
68     @Nullable
69     private SpinningSpeed spinningSpeed;
70     @Nullable
71     private DryingStep dryingStep;
72     @Nullable
73     private VentilationStep ventilationStep;
74     @Nullable
75     private final List<PlateStep> plateStep = null;
76     @Nullable
77     private EcoFeedback ecoFeedback;
78     @Nullable
79     private Integer batteryLevel;
80
81     public Optional<Status> getStatus() {
82         return Optional.ofNullable(status);
83     }
84
85     public Optional<ProgramId> getProgramId() {
86         // There is a typo for the program ID in the Miele Cloud API, which will be corrected in the future.
87         // For the sake of robustness, we currently support both upper and lower case.
88         return Optional.ofNullable(programId != null ? programId : ProgramID);
89     }
90
91     public Optional<ProgramType> getProgramType() {
92         return Optional.ofNullable(programType);
93     }
94
95     public Optional<ProgramPhase> getProgramPhase() {
96         return Optional.ofNullable(programPhase);
97     }
98
99     /**
100      * Gets the remaining time encoded as {@link List} of {@link Integer} values.
101      *
102      * @return The remaining time encoded as {@link List} of {@link Integer} values.
103      */
104     public Optional<List<Integer>> getRemainingTime() {
105         if (remainingTime == null) {
106             return Optional.empty();
107         }
108
109         return Optional.ofNullable(Collections.unmodifiableList(remainingTime));
110     }
111
112     /**
113      * Gets the start time encoded as {@link List} of {@link Integer} values.
114      *
115      * @return The start time encoded as {@link List} of {@link Integer} values.
116      */
117     public Optional<List<Integer>> getStartTime() {
118         if (startTime == null) {
119             return Optional.empty();
120         }
121
122         return Optional.ofNullable(Collections.unmodifiableList(startTime));
123     }
124
125     public List<Temperature> getTargetTemperature() {
126         if (targetTemperature == null) {
127             return Collections.emptyList();
128         }
129
130         return Collections.unmodifiableList(targetTemperature);
131     }
132
133     public List<Temperature> getTemperature() {
134         if (temperature == null) {
135             return Collections.emptyList();
136         }
137
138         return Collections.unmodifiableList(temperature);
139     }
140
141     public Optional<Boolean> getSignalInfo() {
142         return Optional.ofNullable(signalInfo);
143     }
144
145     public Optional<Boolean> getSignalFailure() {
146         return Optional.ofNullable(signalFailure);
147     }
148
149     public Optional<Boolean> getSignalDoor() {
150         return Optional.ofNullable(signalDoor);
151     }
152
153     public Optional<RemoteEnable> getRemoteEnable() {
154         return Optional.ofNullable(remoteEnable);
155     }
156
157     public Light getLight() {
158         return Light.fromId(light);
159     }
160
161     /**
162      * Gets the elapsed time encoded as {@link List} of {@link Integer} values.
163      *
164      * @return The elapsed time encoded as {@link List} of {@link Integer} values.
165      */
166     public Optional<List<Integer>> getElapsedTime() {
167         if (elapsedTime == null) {
168             return Optional.empty();
169         }
170
171         return Optional.ofNullable(Collections.unmodifiableList(elapsedTime));
172     }
173
174     public Optional<SpinningSpeed> getSpinningSpeed() {
175         return Optional.ofNullable(spinningSpeed);
176     }
177
178     public Optional<DryingStep> getDryingStep() {
179         return Optional.ofNullable(dryingStep);
180     }
181
182     public Optional<VentilationStep> getVentilationStep() {
183         return Optional.ofNullable(ventilationStep);
184     }
185
186     public List<PlateStep> getPlateStep() {
187         if (plateStep == null) {
188             return Collections.emptyList();
189         }
190
191         return Collections.unmodifiableList(plateStep);
192     }
193
194     public Optional<EcoFeedback> getEcoFeedback() {
195         return Optional.ofNullable(ecoFeedback);
196     }
197
198     public Optional<Integer> getBatteryLevel() {
199         return Optional.ofNullable(batteryLevel);
200     }
201
202     @Override
203     public int hashCode() {
204         return Objects.hash(dryingStep, elapsedTime, light, programPhase, ProgramID, programId, programType,
205                 remainingTime, remoteEnable, signalDoor, signalFailure, signalInfo, startTime, status,
206                 targetTemperature, temperature, ventilationStep, plateStep, ecoFeedback, batteryLevel);
207     }
208
209     @Override
210     public boolean equals(@Nullable Object obj) {
211         if (this == obj) {
212             return true;
213         }
214         if (obj == null) {
215             return false;
216         }
217         if (getClass() != obj.getClass()) {
218             return false;
219         }
220         State other = (State) obj;
221         return Objects.equals(dryingStep, other.dryingStep) && Objects.equals(elapsedTime, other.elapsedTime)
222                 && Objects.equals(light, other.light) && Objects.equals(programPhase, other.programPhase)
223                 && Objects.equals(ProgramID, other.ProgramID) && Objects.equals(programId, other.programId)
224                 && Objects.equals(programType, other.programType) && Objects.equals(remainingTime, other.remainingTime)
225                 && Objects.equals(remoteEnable, other.remoteEnable) && Objects.equals(signalDoor, other.signalDoor)
226                 && Objects.equals(signalFailure, other.signalFailure) && Objects.equals(signalInfo, other.signalInfo)
227                 && Objects.equals(startTime, other.startTime) && Objects.equals(status, other.status)
228                 && Objects.equals(targetTemperature, other.targetTemperature)
229                 && Objects.equals(temperature, other.temperature)
230                 && Objects.equals(ventilationStep, other.ventilationStep) && Objects.equals(plateStep, other.plateStep)
231                 && Objects.equals(ecoFeedback, other.ecoFeedback) && Objects.equals(batteryLevel, other.batteryLevel);
232     }
233
234     @Override
235     public String toString() {
236         return "State [status=" + status + ", programId=" + getProgramId() + ", programType=" + programType
237                 + ", programPhase=" + programPhase + ", remainingTime=" + remainingTime + ", startTime=" + startTime
238                 + ", targetTemperature=" + targetTemperature + ", temperature=" + temperature + ", signalInfo="
239                 + signalInfo + ", signalFailure=" + signalFailure + ", signalDoor=" + signalDoor + ", remoteEnable="
240                 + remoteEnable + ", light=" + light + ", elapsedTime=" + elapsedTime + ", dryingStep=" + dryingStep
241                 + ", ventilationStep=" + ventilationStep + ", plateStep=" + plateStep + ", ecoFeedback=" + ecoFeedback
242                 + ", batteryLevel=" + batteryLevel + "]";
243     }
244 }