]> git.basschouten.com Git - openhab-addons.git/blob
6b813e7a089346d5d5c2b396f53b2514898da0f6
[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
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 Integer batteryLevel;
78
79     public Optional<Status> getStatus() {
80         return Optional.ofNullable(status);
81     }
82
83     public Optional<ProgramId> getProgramId() {
84         // There is a typo for the program ID in the Miele Cloud API, which will be corrected in the future.
85         // For the sake of robustness, we currently support both upper and lower case.
86         return Optional.ofNullable(programId != null ? programId : ProgramID);
87     }
88
89     public Optional<ProgramType> getProgramType() {
90         return Optional.ofNullable(programType);
91     }
92
93     public Optional<ProgramPhase> getProgramPhase() {
94         return Optional.ofNullable(programPhase);
95     }
96
97     /**
98      * Gets the remaining time encoded as {@link List} of {@link Integer} values.
99      *
100      * @return The remaining time encoded as {@link List} of {@link Integer} values.
101      */
102     public Optional<List<Integer>> getRemainingTime() {
103         if (remainingTime == null) {
104             return Optional.empty();
105         }
106
107         return Optional.ofNullable(Collections.unmodifiableList(remainingTime));
108     }
109
110     /**
111      * Gets the start time encoded as {@link List} of {@link Integer} values.
112      *
113      * @return The start time encoded as {@link List} of {@link Integer} values.
114      */
115     public Optional<List<Integer>> getStartTime() {
116         if (startTime == null) {
117             return Optional.empty();
118         }
119
120         return Optional.ofNullable(Collections.unmodifiableList(startTime));
121     }
122
123     public List<Temperature> getTargetTemperature() {
124         if (targetTemperature == null) {
125             return Collections.emptyList();
126         }
127
128         return Collections.unmodifiableList(targetTemperature);
129     }
130
131     public List<Temperature> getTemperature() {
132         if (temperature == null) {
133             return Collections.emptyList();
134         }
135
136         return Collections.unmodifiableList(temperature);
137     }
138
139     public Optional<Boolean> getSignalInfo() {
140         return Optional.ofNullable(signalInfo);
141     }
142
143     public Optional<Boolean> getSignalFailure() {
144         return Optional.ofNullable(signalFailure);
145     }
146
147     public Optional<Boolean> getSignalDoor() {
148         return Optional.ofNullable(signalDoor);
149     }
150
151     public Optional<RemoteEnable> getRemoteEnable() {
152         return Optional.ofNullable(remoteEnable);
153     }
154
155     public Light getLight() {
156         return Light.fromId(light);
157     }
158
159     /**
160      * Gets the elapsed time encoded as {@link List} of {@link Integer} values.
161      *
162      * @return The elapsed time encoded as {@link List} of {@link Integer} values.
163      */
164     public Optional<List<Integer>> getElapsedTime() {
165         if (elapsedTime == null) {
166             return Optional.empty();
167         }
168
169         return Optional.ofNullable(Collections.unmodifiableList(elapsedTime));
170     }
171
172     public Optional<SpinningSpeed> getSpinningSpeed() {
173         return Optional.ofNullable(spinningSpeed);
174     }
175
176     public Optional<DryingStep> getDryingStep() {
177         return Optional.ofNullable(dryingStep);
178     }
179
180     public Optional<VentilationStep> getVentilationStep() {
181         return Optional.ofNullable(ventilationStep);
182     }
183
184     public List<PlateStep> getPlateStep() {
185         if (plateStep == null) {
186             return Collections.emptyList();
187         }
188
189         return Collections.unmodifiableList(plateStep);
190     }
191
192     public Optional<Integer> getBatteryLevel() {
193         return Optional.ofNullable(batteryLevel);
194     }
195
196     @Override
197     public int hashCode() {
198         return Objects.hash(dryingStep, elapsedTime, light, programPhase, ProgramID, programId, programType,
199                 remainingTime, remoteEnable, signalDoor, signalFailure, signalInfo, startTime, status,
200                 targetTemperature, temperature, ventilationStep, plateStep, batteryLevel);
201     }
202
203     @Override
204     public boolean equals(@Nullable Object obj) {
205         if (this == obj) {
206             return true;
207         }
208         if (obj == null) {
209             return false;
210         }
211         if (getClass() != obj.getClass()) {
212             return false;
213         }
214         State other = (State) obj;
215         return Objects.equals(dryingStep, other.dryingStep) && Objects.equals(elapsedTime, other.elapsedTime)
216                 && Objects.equals(light, other.light) && Objects.equals(programPhase, other.programPhase)
217                 && Objects.equals(ProgramID, other.ProgramID) && Objects.equals(programId, other.programId)
218                 && Objects.equals(programType, other.programType) && Objects.equals(remainingTime, other.remainingTime)
219                 && Objects.equals(remoteEnable, other.remoteEnable) && Objects.equals(signalDoor, other.signalDoor)
220                 && Objects.equals(signalFailure, other.signalFailure) && Objects.equals(signalInfo, other.signalInfo)
221                 && Objects.equals(startTime, other.startTime) && Objects.equals(status, other.status)
222                 && Objects.equals(targetTemperature, other.targetTemperature)
223                 && Objects.equals(temperature, other.temperature)
224                 && Objects.equals(ventilationStep, other.ventilationStep) && Objects.equals(plateStep, other.plateStep)
225                 && Objects.equals(batteryLevel, other.batteryLevel);
226     }
227
228     @Override
229     public String toString() {
230         return "State [status=" + status + ", programId=" + getProgramId() + ", programType=" + programType
231                 + ", programPhase=" + programPhase + ", remainingTime=" + remainingTime + ", startTime=" + startTime
232                 + ", targetTemperature=" + targetTemperature + ", temperature=" + temperature + ", signalInfo="
233                 + signalInfo + ", signalFailure=" + signalFailure + ", signalDoor=" + signalDoor + ", remoteEnable="
234                 + remoteEnable + ", light=" + light + ", elapsedTime=" + elapsedTime + ", dryingStep=" + dryingStep
235                 + ", ventilationStep=" + ventilationStep + ", plateStep=" + plateStep + ", batteryLevel=" + batteryLevel
236                 + "]";
237     }
238 }