]> git.basschouten.com Git - openhab-addons.git/blob
009e3e27adad17bdc2d3fbc34e3d0eca4e1a7475
[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 import java.util.stream.Collectors;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23
24 import com.google.gson.annotations.SerializedName;
25
26 /**
27  * Immutable POJO representing the device actions queried from the Miele REST API.
28  *
29  * @author Roland Edelhoff - Initial contribution
30  */
31 @NonNullByDefault
32 public class Actions {
33     @SerializedName("processAction")
34     @Nullable
35     private final List<ProcessAction> processAction = null;
36     @SerializedName("light")
37     @Nullable
38     private final List<Integer> light = null;
39     @SerializedName("startTime")
40     @Nullable
41     private final List<List<Integer>> startTime = null;
42     @SerializedName("programId")
43     @Nullable
44     private final List<Integer> programId = null;
45     @SerializedName("deviceName")
46     @Nullable
47     private String deviceName;
48     @SerializedName("powerOff")
49     @Nullable
50     private Boolean powerOff;
51     @SerializedName("powerOn")
52     @Nullable
53     private Boolean powerOn;
54
55     public List<ProcessAction> getProcessAction() {
56         if (processAction == null) {
57             return Collections.emptyList();
58         }
59
60         return Collections.unmodifiableList(processAction);
61     }
62
63     public List<Light> getLight() {
64         final List<Integer> lightRefCopy = light;
65         if (lightRefCopy == null) {
66             return Collections.emptyList();
67         }
68
69         return Collections.unmodifiableList(lightRefCopy.stream().map(Light::fromId).collect(Collectors.toList()));
70     }
71
72     /**
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.
77      *
78      * @return The possible start time interval encoded as described above.
79      */
80     public Optional<List<List<Integer>>> getStartTime() {
81         if (startTime == null) {
82             return Optional.empty();
83         }
84
85         return Optional.of(Collections.unmodifiableList(startTime));
86     }
87
88     public List<Integer> getProgramId() {
89         if (programId == null) {
90             return Collections.emptyList();
91         }
92
93         return Collections.unmodifiableList(programId);
94     }
95
96     public Optional<String> getDeviceName() {
97         return Optional.ofNullable(deviceName);
98     }
99
100     public Optional<Boolean> getPowerOn() {
101         return Optional.ofNullable(powerOn);
102     }
103
104     public Optional<Boolean> getPowerOff() {
105         return Optional.ofNullable(powerOff);
106     }
107
108     @Override
109     public String toString() {
110         return "ActionState [processAction=" + processAction + ", light=" + light + ", startTime=" + startTime
111                 + ", programId=" + programId + ", deviceName=" + deviceName + ", powerOff=" + powerOff + ", powerOn="
112                 + powerOn + "]";
113     }
114
115     @Override
116     public int hashCode() {
117         return Objects.hash(deviceName, light, powerOn, powerOff, processAction, startTime, programId);
118     }
119
120     @Override
121     public boolean equals(@Nullable Object obj) {
122         if (this == obj) {
123             return true;
124         }
125         if (obj == null) {
126             return false;
127         }
128         if (getClass() != obj.getClass()) {
129             return false;
130         }
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);
136     }
137 }