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;
19 import java.util.stream.Collectors;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
24 import com.google.gson.annotations.SerializedName;
27 * Immutable POJO representing the device actions queried from the Miele REST API.
29 * @author Roland Edelhoff - Initial contribution
32 public class Actions {
33 @SerializedName("processAction")
35 private final List<ProcessAction> processAction = null;
36 @SerializedName("light")
38 private final List<Integer> light = null;
39 @SerializedName("startTime")
41 private final List<List<Integer>> startTime = null;
42 @SerializedName("programId")
44 private final List<Integer> programId = null;
45 @SerializedName("deviceName")
47 private String deviceName;
48 @SerializedName("powerOff")
50 private Boolean powerOff;
51 @SerializedName("powerOn")
53 private Boolean powerOn;
55 public List<ProcessAction> getProcessAction() {
56 if (processAction == null) {
57 return Collections.emptyList();
60 return Collections.unmodifiableList(processAction);
63 public List<Light> getLight() {
64 final List<Integer> lightRefCopy = light;
65 if (lightRefCopy == null) {
66 return Collections.emptyList();
69 return Collections.unmodifiableList(lightRefCopy.stream().map(Light::fromId).collect(Collectors.toList()));
73 * Gets the start time encoded as {@link List} of {@link List} of {@link Integer} values.
74 * The first list entry defines the lower time constraint for setting the delayed start time. The second list
75 * entry defines the upper time constraint. The time constraints are defined as a list of integers with the full
76 * hour as first and minutes as second element.
78 * @return The possible start time interval encoded as described above.
80 public Optional<List<List<Integer>>> getStartTime() {
81 if (startTime == null) {
82 return Optional.empty();
85 return Optional.of(Collections.unmodifiableList(startTime));
88 public List<Integer> getProgramId() {
89 if (programId == null) {
90 return Collections.emptyList();
93 return Collections.unmodifiableList(programId);
96 public Optional<String> getDeviceName() {
97 return Optional.ofNullable(deviceName);
100 public Optional<Boolean> getPowerOn() {
101 return Optional.ofNullable(powerOn);
104 public Optional<Boolean> getPowerOff() {
105 return Optional.ofNullable(powerOff);
109 public String toString() {
110 return "ActionState [processAction=" + processAction + ", light=" + light + ", startTime=" + startTime
111 + ", programId=" + programId + ", deviceName=" + deviceName + ", powerOff=" + powerOff + ", powerOn="
116 public int hashCode() {
117 return Objects.hash(deviceName, light, powerOn, powerOff, processAction, startTime, programId);
121 public boolean equals(@Nullable Object obj) {
128 if (getClass() != obj.getClass()) {
131 Actions other = (Actions) obj;
132 return Objects.equals(deviceName, other.deviceName) && Objects.equals(light, other.light)
133 && Objects.equals(powerOn, other.powerOn) && Objects.equals(powerOff, other.powerOff)
134 && Objects.equals(processAction, other.processAction) && Objects.equals(startTime, other.startTime)
135 && Objects.equals(programId, other.programId);