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
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 Integer batteryLevel;
79 public Optional<Status> getStatus() {
80 return Optional.ofNullable(status);
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);
89 public Optional<ProgramType> getProgramType() {
90 return Optional.ofNullable(programType);
93 public Optional<ProgramPhase> getProgramPhase() {
94 return Optional.ofNullable(programPhase);
98 * Gets the remaining time encoded as {@link List} of {@link Integer} values.
100 * @return The remaining time encoded as {@link List} of {@link Integer} values.
102 public Optional<List<Integer>> getRemainingTime() {
103 if (remainingTime == null) {
104 return Optional.empty();
107 return Optional.ofNullable(Collections.unmodifiableList(remainingTime));
111 * Gets the start time encoded as {@link List} of {@link Integer} values.
113 * @return The start time encoded as {@link List} of {@link Integer} values.
115 public Optional<List<Integer>> getStartTime() {
116 if (startTime == null) {
117 return Optional.empty();
120 return Optional.ofNullable(Collections.unmodifiableList(startTime));
123 public List<Temperature> getTargetTemperature() {
124 if (targetTemperature == null) {
125 return Collections.emptyList();
128 return Collections.unmodifiableList(targetTemperature);
131 public List<Temperature> getTemperature() {
132 if (temperature == null) {
133 return Collections.emptyList();
136 return Collections.unmodifiableList(temperature);
139 public Optional<Boolean> getSignalInfo() {
140 return Optional.ofNullable(signalInfo);
143 public Optional<Boolean> getSignalFailure() {
144 return Optional.ofNullable(signalFailure);
147 public Optional<Boolean> getSignalDoor() {
148 return Optional.ofNullable(signalDoor);
151 public Optional<RemoteEnable> getRemoteEnable() {
152 return Optional.ofNullable(remoteEnable);
155 public Light getLight() {
156 return Light.fromId(light);
160 * Gets the elapsed time encoded as {@link List} of {@link Integer} values.
162 * @return The elapsed time encoded as {@link List} of {@link Integer} values.
164 public Optional<List<Integer>> getElapsedTime() {
165 if (elapsedTime == null) {
166 return Optional.empty();
169 return Optional.ofNullable(Collections.unmodifiableList(elapsedTime));
172 public Optional<SpinningSpeed> getSpinningSpeed() {
173 return Optional.ofNullable(spinningSpeed);
176 public Optional<DryingStep> getDryingStep() {
177 return Optional.ofNullable(dryingStep);
180 public Optional<VentilationStep> getVentilationStep() {
181 return Optional.ofNullable(ventilationStep);
184 public List<PlateStep> getPlateStep() {
185 if (plateStep == null) {
186 return Collections.emptyList();
189 return Collections.unmodifiableList(plateStep);
192 public Optional<Integer> getBatteryLevel() {
193 return Optional.ofNullable(batteryLevel);
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);
204 public boolean equals(@Nullable Object obj) {
211 if (getClass() != obj.getClass()) {
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);
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