]> git.basschouten.com Git - openhab-addons.git/blob
fd8a39ac611e2ee830e0a1ce97896699140263f3
[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.ecobee.internal.dto;
14
15 import java.util.Set;
16
17 /**
18  * The {@link SelectionDTO} defines the resources and information to return
19  * as part of a response. The selection is required in all requests however
20  * meaning of some selection fields is only meaningful to certain types of requests.
21  *
22  * The selectionType parameter defines the type of selection to perform. The selectionMatch
23  * specifies the matching criteria for the type specified.
24  *
25  * @author Mark Hilbush - Initial contribution
26  */
27 public class SelectionDTO {
28
29     /*
30      * The type of match data supplied: Values: thermostats, registered, managementSet.
31      */
32     public SelectionType selectionType;
33
34     /*
35      * The match data based on selectionType (e.g. a comma-separated list of thermostat
36      * idendifiers in the case of a selectionType of thermostats)
37      */
38     public String selectionMatch;
39
40     /*
41      * Include the thermostat's unacknowledged alert objects. If not specified, defaults to false.
42      */
43     public Boolean includeAlerts;
44
45     /*
46      * Include the audio configuration for the selected Thermostat(s). If not specified, defaults to false.
47      */
48     public Boolean includeAudio;
49
50     /*
51      * Include the thermostat device configuration objects. If not specified, defaults to false.
52      */
53     public Boolean includeDevice;
54
55     /*
56      * Include the electricity readings object. If not specified, defaults to false.
57      */
58     public Boolean includeElectricity;
59
60     /*
61      * Include the energy configuration for the selected Thermostat(s). If not specified, defaults to false.
62      */
63     public Boolean includeEnergy;
64
65     /*
66      * Include the current thermostat equipment status information. If not specified, defaults to false.
67      */
68     public Boolean includeEquipmentStatus;
69
70     /*
71      * Include the thermostat calendar events objects. If not specified, defaults to false.
72      */
73     public Boolean includeEvents;
74
75     /*
76      * Include the extended thermostat runtime object. If not specified, defaults to false.
77      */
78     public Boolean includeExtendedRuntime;
79
80     /*
81      * Include the current thermostat house details object. If not specified, defaults to false.
82      */
83     public Boolean includeHouseDetails;
84
85     /*
86      * Include the thermostat location object. If not specified, defaults to false.
87      */
88     public Boolean includeLocation;
89
90     /*
91      * Include the thermostat management company object. If not specified, defaults to false.
92      */
93     public Boolean includeManagement;
94
95     /*
96      * Include the current thermostat alert and reminders settings. If not specified, defaults to false.
97      */
98     public Boolean includeNotificationSettings;
99
100     /*
101      * Include the current thermostat OemCfg object. If not specified, defaults to false.
102      */
103     public Boolean includeOemCfg;
104
105     /*
106      * Include the current thermostat privacy settings. Note: access to this object is restricted
107      * to callers with implict authentication, setting this value to true without proper
108      * credentials will result in an authentication exception.
109      */
110     public Boolean includePrivacy;
111
112     /*
113      * Include the thermostat program object. If not specified, defaults to false.
114      */
115     public Boolean includeProgram;
116
117     /*
118      * Include the thermostat reminder object. If not specified, defaults to false.
119      */
120     public Boolean includeReminders;
121
122     /*
123      * Include the thermostat runtime object. If not specified, defaults to false.
124      */
125     public Boolean includeRuntime;
126
127     /*
128      * Include the current securitySettings object for the selected Thermostat(s). If not specified, defaults to false.
129      */
130     public Boolean includeSecuritySettings;
131
132     /*
133      * Include the list of current thermostatRemoteSensor objects for the selected Thermostat(s).
134      * If not specified, defaults to false.
135      */
136     public Boolean includeSensors;
137
138     /*
139      * Include the thermostat settings object. If not specified, defaults to false.
140      */
141     public Boolean includeSettings;
142
143     /*
144      * Include the thermostat technician object. If not specified, defaults to false.
145      */
146     public Boolean includeTechnician;
147
148     /*
149      * Include the thermostat utility company object. If not specified, defaults to false.
150      */
151     public Boolean includeUtility;
152
153     /*
154      * Include the current firmware version the Thermostat is running. If not specified, defaults to false.
155      */
156     public Boolean includeVersion;
157
158     /*
159      * Include the current thermostat weather forecast object. If not specified, defaults to false.
160      */
161     public Boolean includeWeather;
162
163     public SelectionDTO() {
164         selectionType = SelectionType.REGISTERED;
165     }
166
167     public void setThermostats(Set<String> thermostatIds) {
168         if (thermostatIds == null || thermostatIds.isEmpty()) {
169             selectionType = SelectionType.REGISTERED;
170             selectionMatch = "";
171         } else {
172             selectionType = SelectionType.THERMOSTATS;
173             selectionMatch = String.join(",", thermostatIds);
174         }
175     }
176
177     public void setSelectionType(SelectionType selectionType) {
178         this.selectionType = selectionType;
179     }
180
181     /**
182      * Merge this selection object with the one passed in as a parameter.
183      *
184      * @param selection
185      * @return A SelectionDTO object representing the merged selection objects
186      */
187     public SelectionDTO mergeSelection(SelectionDTO selection) {
188         // Always get alerts, equipmentStatus, events, program, runtime, and sensors
189         this.includeAlerts = Boolean.TRUE;
190         this.includeEquipmentStatus = Boolean.TRUE;
191         this.includeEvents = Boolean.TRUE;
192         this.includeProgram = Boolean.TRUE;
193         this.includeRuntime = Boolean.TRUE;
194         this.includeSensors = Boolean.TRUE;
195
196         this.includeAudio = Boolean.TRUE.equals(selection.includeAudio) ? Boolean.TRUE : includeAudio;
197         this.includeDevice = Boolean.TRUE.equals(selection.includeDevice) ? Boolean.TRUE : includeDevice;
198         this.includeElectricity = Boolean.TRUE.equals(selection.includeElectricity) ? Boolean.TRUE : includeElectricity;
199         this.includeEnergy = Boolean.TRUE.equals(selection.includeEnergy) ? Boolean.TRUE : includeEnergy;
200         this.includeExtendedRuntime = Boolean.TRUE.equals(selection.includeExtendedRuntime) ? Boolean.TRUE
201                 : includeExtendedRuntime;
202         this.includeHouseDetails = Boolean.TRUE.equals(selection.includeHouseDetails) ? Boolean.TRUE
203                 : includeHouseDetails;
204         this.includeLocation = Boolean.TRUE.equals(selection.includeLocation) ? Boolean.TRUE : includeLocation;
205         this.includeManagement = Boolean.TRUE.equals(selection.includeManagement) ? Boolean.TRUE : includeManagement;
206         this.includeNotificationSettings = Boolean.TRUE.equals(selection.includeNotificationSettings) ? Boolean.TRUE
207                 : includeNotificationSettings;
208         this.includeOemCfg = Boolean.TRUE.equals(selection.includeOemCfg) ? Boolean.TRUE : includeOemCfg;
209         this.includePrivacy = Boolean.TRUE.equals(selection.includePrivacy) ? Boolean.TRUE : includePrivacy;
210         this.includeReminders = Boolean.TRUE.equals(selection.includeReminders) ? Boolean.TRUE : includeReminders;
211         this.includeSecuritySettings = Boolean.TRUE.equals(selection.includeSecuritySettings) ? Boolean.TRUE
212                 : includeSecuritySettings;
213         this.includeSettings = Boolean.TRUE.equals(selection.includeSettings) ? Boolean.TRUE : includeSettings;
214         this.includeTechnician = Boolean.TRUE.equals(selection.includeTechnician) ? Boolean.TRUE : includeTechnician;
215         this.includeUtility = Boolean.TRUE.equals(selection.includeUtility) ? Boolean.TRUE : includeUtility;
216         this.includeVersion = Boolean.TRUE.equals(selection.includeVersion) ? Boolean.TRUE : includeVersion;
217         this.includeWeather = Boolean.TRUE.equals(selection.includeWeather) ? Boolean.TRUE : includeWeather;
218         return this;
219     }
220
221     @Override
222     public String toString() {
223         StringBuilder sb = new StringBuilder();
224         sb.append("selectionType=").append(selectionType).append(",");
225         sb.append("selectionMatch=").append(selectionMatch).append(",");
226         sb.append("includeAlerts=").append(includeAlerts).append(",");
227         sb.append("includeAudio=").append(includeAudio).append(",");
228         sb.append("includeDevice=").append(includeDevice).append(",");
229         sb.append("includeElectricity=").append(includeElectricity).append(",");
230         sb.append("includeEnergy=").append(includeEnergy).append(",");
231         sb.append("includeEquipmentStatus=").append(includeEquipmentStatus).append(",");
232         sb.append("includeExtendedRuntime=").append(includeExtendedRuntime).append(",");
233         sb.append("includeHouseDetails=").append(includeHouseDetails).append(",");
234         sb.append("includeLocation=").append(includeLocation).append(",");
235         sb.append("includeManagement=").append(includeManagement).append(",");
236         sb.append("includeNotificationSettings=").append(includeNotificationSettings).append(",");
237         sb.append("includeOemCfg=").append(includeOemCfg).append(",");
238         sb.append("includePrivacy=").append(includePrivacy).append(",");
239         sb.append("includeProgram=").append(includeProgram).append(",");
240         sb.append("includeReminders=").append(includeReminders).append(",");
241         sb.append("includeRuntime=").append(includeRuntime).append(",");
242         sb.append("includeSecuritySettings=").append(includeSecuritySettings).append(",");
243         sb.append("includeSensors=").append(includeSensors).append(",");
244         sb.append("includeSettings=").append(includeSettings).append(",");
245         sb.append("includeTechnician=").append(includeTechnician).append(",");
246         sb.append("includeUtility=").append(includeUtility).append(",");
247         sb.append("includeVersion=").append(includeVersion).append(",");
248         sb.append("includeWeather=").append(includeWeather);
249         return sb.toString();
250     }
251 }