2 * Copyright (c) 2010-2023 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.mielecloud.internal.webservice.api.json;
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Objects;
18 import java.util.Optional;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
24 * Immutable POJO representing the state of a device. Queried from the Miele REST API.
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
33 private Status status;
35 * Currently used by Miele webservice.
38 private ProgramId ProgramID;
40 * Planned to be used in the future.
43 private ProgramId programId;
45 private ProgramType programType;
47 private ProgramPhase programPhase;
49 private final List<Integer> remainingTime = null;
51 private final List<Integer> startTime = null;
53 private final List<Temperature> targetTemperature = null;
55 private final List<Temperature> temperature = null;
57 private Boolean signalInfo;
59 private Boolean signalFailure;
61 private Boolean signalDoor;
63 private RemoteEnable remoteEnable;
65 private Integer light;
67 private final List<Integer> elapsedTime = null;
69 private SpinningSpeed spinningSpeed;
71 private DryingStep dryingStep;
73 private VentilationStep ventilationStep;
75 private final List<PlateStep> plateStep = null;
77 private EcoFeedback ecoFeedback;
79 private Integer batteryLevel;
81 public Optional<Status> getStatus() {
82 return Optional.ofNullable(status);
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);
91 public Optional<ProgramType> getProgramType() {
92 return Optional.ofNullable(programType);
95 public Optional<ProgramPhase> getProgramPhase() {
96 return Optional.ofNullable(programPhase);
100 * Gets the remaining time encoded as {@link List} of {@link Integer} values.
102 * @return The remaining time encoded as {@link List} of {@link Integer} values.
104 public Optional<List<Integer>> getRemainingTime() {
105 if (remainingTime == null) {
106 return Optional.empty();
109 return Optional.ofNullable(Collections.unmodifiableList(remainingTime));
113 * Gets the start time encoded as {@link List} of {@link Integer} values.
115 * @return The start time encoded as {@link List} of {@link Integer} values.
117 public Optional<List<Integer>> getStartTime() {
118 if (startTime == null) {
119 return Optional.empty();
122 return Optional.ofNullable(Collections.unmodifiableList(startTime));
125 public List<Temperature> getTargetTemperature() {
126 if (targetTemperature == null) {
127 return Collections.emptyList();
130 return Collections.unmodifiableList(targetTemperature);
133 public List<Temperature> getTemperature() {
134 if (temperature == null) {
135 return Collections.emptyList();
138 return Collections.unmodifiableList(temperature);
141 public Optional<Boolean> getSignalInfo() {
142 return Optional.ofNullable(signalInfo);
145 public Optional<Boolean> getSignalFailure() {
146 return Optional.ofNullable(signalFailure);
149 public Optional<Boolean> getSignalDoor() {
150 return Optional.ofNullable(signalDoor);
153 public Optional<RemoteEnable> getRemoteEnable() {
154 return Optional.ofNullable(remoteEnable);
157 public Light getLight() {
158 return Light.fromId(light);
162 * Gets the elapsed time encoded as {@link List} of {@link Integer} values.
164 * @return The elapsed time encoded as {@link List} of {@link Integer} values.
166 public Optional<List<Integer>> getElapsedTime() {
167 if (elapsedTime == null) {
168 return Optional.empty();
171 return Optional.ofNullable(Collections.unmodifiableList(elapsedTime));
174 public Optional<SpinningSpeed> getSpinningSpeed() {
175 return Optional.ofNullable(spinningSpeed);
178 public Optional<DryingStep> getDryingStep() {
179 return Optional.ofNullable(dryingStep);
182 public Optional<VentilationStep> getVentilationStep() {
183 return Optional.ofNullable(ventilationStep);
186 public List<PlateStep> getPlateStep() {
187 if (plateStep == null) {
188 return Collections.emptyList();
191 return Collections.unmodifiableList(plateStep);
194 public Optional<EcoFeedback> getEcoFeedback() {
195 return Optional.ofNullable(ecoFeedback);
198 public Optional<Integer> getBatteryLevel() {
199 return Optional.ofNullable(batteryLevel);
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);
210 public boolean equals(@Nullable Object obj) {
217 if (getClass() != obj.getClass()) {
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);
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 + "]";