]> git.basschouten.com Git - openhab-addons.git/blob
923ad0fac66fe722c7f86cd5f91dcc0fe67ce7bf
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.verisure.internal.dto;
14
15 import java.math.BigDecimal;
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.verisure.internal.VerisureThingConfiguration;
22 import org.openhab.binding.verisure.internal.dto.VerisureAlarmsDTO.ArmState;
23 import org.openhab.binding.verisure.internal.dto.VerisureBroadbandConnectionsDTO.Broadband;
24 import org.openhab.binding.verisure.internal.dto.VerisureClimatesDTO.Climate;
25 import org.openhab.binding.verisure.internal.dto.VerisureDoorWindowsDTO.DoorWindow;
26 import org.openhab.binding.verisure.internal.dto.VerisureEventLogDTO.EventLog;
27 import org.openhab.binding.verisure.internal.dto.VerisureGatewayDTO.CommunicationState;
28 import org.openhab.binding.verisure.internal.dto.VerisureMiceDetectionDTO.Mouse;
29 import org.openhab.binding.verisure.internal.dto.VerisureSmartLocksDTO.Doorlock;
30 import org.openhab.binding.verisure.internal.dto.VerisureSmartPlugsDTO.Smartplug;
31 import org.openhab.binding.verisure.internal.dto.VerisureUserPresencesDTO.UserTracking;
32 import org.openhab.core.thing.ThingTypeUID;
33
34 import com.google.gson.annotations.SerializedName;
35
36 /**
37  * A base JSON thing for other Verisure things to inherit from.
38  *
39  * @author Jarle Hjortland - Initial contribution
40  *
41  */
42 @NonNullByDefault
43 public abstract class VerisureBaseThingDTO implements VerisureThingDTO {
44
45     protected String deviceId = "";
46     protected @Nullable String name;
47     protected @Nullable String location;
48     protected @Nullable String status;
49     protected @Nullable String siteName;
50     protected BigDecimal siteId = BigDecimal.ZERO;
51     protected Data data = new Data();
52
53     public @Nullable String getStatus() {
54         return status;
55     }
56
57     public void setStatus(String status) {
58         this.status = status;
59     }
60
61     public @Nullable String getName() {
62         return name;
63     }
64
65     public void setName(String name) {
66         this.name = name;
67     }
68
69     @Override
70     public String getDeviceId() {
71         return deviceId;
72     }
73
74     @Override
75     public void setDeviceId(String deviceId) {
76         // Make sure device id is normalized
77         this.deviceId = VerisureThingConfiguration.normalizeDeviceId(deviceId);
78     }
79
80     @Override
81     public @Nullable String getLocation() {
82         return location;
83     }
84
85     public void setLocation(@Nullable String location) {
86         this.location = location;
87     }
88
89     @Override
90     public @Nullable String getSiteName() {
91         return siteName;
92     }
93
94     @Override
95     public void setSiteName(@Nullable String siteName) {
96         this.siteName = siteName;
97     }
98
99     @Override
100     public BigDecimal getSiteId() {
101         return siteId;
102     }
103
104     @Override
105     public void setSiteId(BigDecimal siteId) {
106         this.siteId = siteId;
107     }
108
109     @Override
110     public abstract ThingTypeUID getThingTypeUID();
111
112     public Data getData() {
113         return data;
114     }
115
116     public void setData(Data data) {
117         this.data = data;
118     }
119
120     @Override
121     public int hashCode() {
122         final int prime = 31;
123         int result = 1;
124         result = prime * result + data.hashCode();
125         result = prime * result + deviceId.hashCode();
126         String localLocation = location;
127         result = prime * result + ((localLocation == null) ? 0 : localLocation.hashCode());
128         String localName = name;
129         result = prime * result + ((localName == null) ? 0 : localName.hashCode());
130         result = prime * result + siteId.hashCode();
131         String localSiteName = siteName;
132         result = prime * result + ((localSiteName == null) ? 0 : localSiteName.hashCode());
133         String localStatus = status;
134         result = prime * result + ((localStatus == null) ? 0 : localStatus.hashCode());
135         return result;
136     }
137
138     @Override
139     public boolean equals(@Nullable Object obj) {
140         if (this == obj) {
141             return true;
142         }
143         if (obj == null) {
144             return false;
145         }
146         if (getClass() != obj.getClass()) {
147             return false;
148         }
149         VerisureBaseThingDTO other = (VerisureBaseThingDTO) obj;
150         if (!data.equals(other.data)) {
151             return false;
152         }
153         if (!deviceId.equals(other.deviceId)) {
154             return false;
155         }
156         String localLocation = location;
157         if (localLocation == null) {
158             if (other.location != null) {
159                 return false;
160             }
161         } else if (!localLocation.equals(other.location)) {
162             return false;
163         }
164         String localName = name;
165         if (localName == null) {
166             if (other.name != null) {
167                 return false;
168             }
169         } else if (!localName.equals(other.name)) {
170             return false;
171         }
172         if (!siteId.equals(other.siteId)) {
173             return false;
174         }
175         String localSiteName = siteName;
176         if (localSiteName == null) {
177             if (other.siteName != null) {
178                 return false;
179             }
180         } else if (!localSiteName.equals(other.siteName)) {
181             return false;
182         }
183         String localStatus = status;
184         if (localStatus == null) {
185             if (other.status != null) {
186                 return false;
187             }
188         } else if (!localStatus.equals(other.status)) {
189             return false;
190         }
191         return true;
192     }
193
194     @Override
195     public String toString() {
196         return "VerisureBaseThingDTO [deviceId=" + deviceId + ", name=" + name + ", location=" + location + ", status="
197                 + status + ", siteName=" + siteName + ", siteId=" + siteId + ", data=" + data + "]";
198     }
199
200     public static class Data {
201         private Installation installation = new Installation();
202
203         public Installation getInstallation() {
204             return installation;
205         }
206
207         public void setInstallation(Installation installation) {
208             this.installation = installation;
209         }
210
211         @Override
212         public int hashCode() {
213             final int prime = 31;
214             int result = 1;
215             result = prime * result + installation.hashCode();
216             return result;
217         }
218
219         @Override
220         public boolean equals(@Nullable Object obj) {
221             if (this == obj) {
222                 return true;
223             }
224             if (obj == null) {
225                 return false;
226             }
227             if (getClass() != obj.getClass()) {
228                 return false;
229             }
230             Data other = (Data) obj;
231             if (!installation.equals(other.installation)) {
232                 return false;
233             }
234             return true;
235         }
236
237         @Override
238         public String toString() {
239             return "Data [installation=" + installation + "]";
240         }
241     }
242
243     public static class Installation {
244
245         private ArmState armState = new ArmState();
246         private Broadband broadband = new Broadband();
247         private EventLog eventLog = new EventLog();
248         private List<Climate> climates = new ArrayList<>();
249         private List<DoorWindow> doorWindows = new ArrayList<>();
250         private List<CommunicationState> communicationState = new ArrayList<>();
251         private List<Mouse> mice = new ArrayList<>();
252         private List<Doorlock> doorlocks = new ArrayList<>();
253         private List<Smartplug> smartplugs = new ArrayList<>();
254         private List<UserTracking> userTrackings = new ArrayList<>();
255
256         @SerializedName("__typename")
257         private @Nullable String typename;
258
259         public ArmState getArmState() {
260             return armState;
261         }
262
263         public Broadband getBroadband() {
264             return broadband;
265         }
266
267         public @Nullable List<Climate> getClimates() {
268             return climates;
269         }
270
271         public void setClimates(List<Climate> climates) {
272             this.climates = climates;
273         }
274
275         public @Nullable List<DoorWindow> getDoorWindows() {
276             return doorWindows;
277         }
278
279         public void setDoorWindows(List<DoorWindow> doorWindows) {
280             this.doorWindows = doorWindows;
281         }
282
283         public EventLog getEventLog() {
284             return eventLog;
285         }
286
287         public @Nullable List<CommunicationState> getCommunicationState() {
288             return communicationState;
289         }
290
291         public @Nullable List<Mouse> getMice() {
292             return mice;
293         }
294
295         public void setMice(List<Mouse> mice) {
296             this.mice = mice;
297         }
298
299         public @Nullable List<Doorlock> getDoorlocks() {
300             return doorlocks;
301         }
302
303         public void setDoorlocks(List<Doorlock> doorlocks) {
304             this.doorlocks = doorlocks;
305         }
306
307         public @Nullable List<Smartplug> getSmartplugs() {
308             return smartplugs;
309         }
310
311         public void setSmartplugs(List<Smartplug> smartplugs) {
312             this.smartplugs = smartplugs;
313         }
314
315         public @Nullable List<UserTracking> getUserTrackings() {
316             return userTrackings;
317         }
318
319         public void setUserTrackings(List<UserTracking> userTrackings) {
320             this.userTrackings = userTrackings;
321         }
322
323         public @Nullable String getTypename() {
324             return typename;
325         }
326
327         @Override
328         public int hashCode() {
329             final int prime = 31;
330             int result = 1;
331             result = prime * result + armState.hashCode();
332             result = prime * result + broadband.hashCode();
333             result = prime * result + climates.hashCode();
334             result = prime * result + communicationState.hashCode();
335             result = prime * result + doorWindows.hashCode();
336             result = prime * result + doorlocks.hashCode();
337             result = prime * result + eventLog.hashCode();
338             result = prime * result + mice.hashCode();
339             result = prime * result + smartplugs.hashCode();
340             String localTypeName = typename;
341             result = prime * result + ((localTypeName == null) ? 0 : localTypeName.hashCode());
342             result = prime * result + userTrackings.hashCode();
343             return result;
344         }
345
346         @Override
347         public boolean equals(@Nullable Object obj) {
348             if (this == obj) {
349                 return true;
350             }
351             if (obj == null) {
352                 return false;
353             }
354             if (getClass() != obj.getClass()) {
355                 return false;
356             }
357             Installation other = (Installation) obj;
358             if (!armState.equals(other.armState)) {
359                 return false;
360             }
361             if (!broadband.equals(other.broadband)) {
362                 return false;
363             }
364             if (!climates.equals(other.climates)) {
365                 return false;
366             }
367             if (!communicationState.equals(other.communicationState)) {
368                 return false;
369             }
370             if (!doorWindows.equals(other.doorWindows)) {
371                 return false;
372             }
373             if (!doorlocks.equals(other.doorlocks)) {
374                 return false;
375             }
376             if (!eventLog.equals(other.eventLog)) {
377                 return false;
378             }
379             if (!mice.equals(other.mice)) {
380                 return false;
381             }
382             if (!smartplugs.equals(other.smartplugs)) {
383                 return false;
384             }
385             String localTypeName = typename;
386             if (localTypeName == null) {
387                 if (other.typename != null) {
388                     return false;
389                 }
390             } else if (!localTypeName.equals(other.typename)) {
391                 return false;
392             }
393             if (!userTrackings.equals(other.userTrackings)) {
394                 return false;
395             }
396             return true;
397         }
398
399         @Override
400         public String toString() {
401             return "Installation [armState=" + armState + ", broadband=" + broadband + ", eventLog=" + eventLog
402                     + ", climates=" + climates + ", doorWindows=" + doorWindows + ", communicationState="
403                     + communicationState + ", mice=" + mice + ", doorlocks=" + doorlocks + ", smartplugs=" + smartplugs
404                     + ", userTrackings=" + userTrackings + ", typename=" + typename + "]";
405         }
406     }
407
408     public static class Device {
409
410         private @Nullable String deviceLabel;
411         private @Nullable String area;
412         private Gui gui = new Gui();
413         @SerializedName("__typename")
414         private @Nullable String typename;
415
416         public @Nullable String getDeviceLabel() {
417             return deviceLabel;
418         }
419
420         public @Nullable String getArea() {
421             return area;
422         }
423
424         public Gui getGui() {
425             return gui;
426         }
427
428         public @Nullable String getTypename() {
429             return typename;
430         }
431
432         @Override
433         public int hashCode() {
434             final int prime = 31;
435             int result = 1;
436             String localArea = area;
437             result = prime * result + ((localArea == null) ? 0 : localArea.hashCode());
438             String localDeviceLabel = deviceLabel;
439             result = prime * result + ((localDeviceLabel == null) ? 0 : localDeviceLabel.hashCode());
440             result = prime * result + gui.hashCode();
441             String localTypeName = typename;
442             result = prime * result + ((localTypeName == null) ? 0 : localTypeName.hashCode());
443             return result;
444         }
445
446         @Override
447         public boolean equals(@Nullable Object obj) {
448             if (this == obj) {
449                 return true;
450             }
451             if (obj == null) {
452                 return false;
453             }
454             if (getClass() != obj.getClass()) {
455                 return false;
456             }
457             Device other = (Device) obj;
458             String localArea = area;
459             if (localArea == null) {
460                 if (other.area != null) {
461                     return false;
462                 }
463             } else if (!localArea.equals(other.area)) {
464                 return false;
465             }
466             String localDeviceLabel = deviceLabel;
467             if (localDeviceLabel == null) {
468                 if (other.deviceLabel != null) {
469                     return false;
470                 }
471             } else if (!localDeviceLabel.equals(other.deviceLabel)) {
472                 return false;
473             }
474             if (!gui.equals(other.gui)) {
475                 return false;
476             }
477             String localTypeName = typename;
478             if (localTypeName == null) {
479                 if (other.typename != null) {
480                     return false;
481                 }
482             } else if (!localTypeName.equals(other.typename)) {
483                 return false;
484             }
485             return true;
486         }
487
488         @Override
489         public String toString() {
490             return "Device [deviceLabel=" + deviceLabel + ", area=" + area + ", gui=" + gui + ", typename=" + typename
491                     + "]";
492         }
493     }
494
495     public static class Gui {
496
497         private @Nullable String label;
498         private @Nullable String support;
499         @SerializedName("__typename")
500         private @Nullable String typename;
501
502         public @Nullable String getLabel() {
503             return label;
504         }
505
506         public @Nullable String getSupport() {
507             return support;
508         }
509
510         public @Nullable String getTypename() {
511             return typename;
512         }
513
514         @Override
515         public int hashCode() {
516             final int prime = 31;
517             int result = 1;
518             String localLabel = label;
519             result = prime * result + ((localLabel == null) ? 0 : localLabel.hashCode());
520             String localSupport = support;
521             result = prime * result + ((localSupport == null) ? 0 : localSupport.hashCode());
522             String localTypeName = typename;
523             result = prime * result + ((localTypeName == null) ? 0 : localTypeName.hashCode());
524             return result;
525         }
526
527         @Override
528         public boolean equals(@Nullable Object obj) {
529             if (this == obj) {
530                 return true;
531             }
532             if (obj == null) {
533                 return false;
534             }
535             if (getClass() != obj.getClass()) {
536                 return false;
537             }
538             Gui other = (Gui) obj;
539             String localLabel = label;
540             if (localLabel == null) {
541                 if (other.label != null) {
542                     return false;
543                 }
544             } else if (!localLabel.equals(other.label)) {
545                 return false;
546             }
547             String localSupport = support;
548             if (localSupport == null) {
549                 if (other.support != null) {
550                     return false;
551                 }
552             } else if (!localSupport.equals(other.support)) {
553                 return false;
554             }
555             String localTypeName = typename;
556             if (localTypeName == null) {
557                 if (other.typename != null) {
558                     return false;
559                 }
560             } else if (!localTypeName.equals(other.typename)) {
561                 return false;
562             }
563             return true;
564         }
565
566         @Override
567         public String toString() {
568             return "Gui [label=" + label + ", support=" + support + ", typename=" + typename + "]";
569         }
570     }
571 }