]> git.basschouten.com Git - openhab-addons.git/blob
2abe4b8c7d7a38112df407e9b9a398485da960f4
[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.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         @SuppressWarnings("PMD.SimplifyBooleanReturns")
220         @Override
221         public boolean equals(@Nullable Object obj) {
222             if (this == obj) {
223                 return true;
224             }
225             if (obj == null) {
226                 return false;
227             }
228             if (getClass() != obj.getClass()) {
229                 return false;
230             }
231             Data other = (Data) obj;
232             if (!installation.equals(other.installation)) {
233                 return false;
234             }
235             return true;
236         }
237
238         @Override
239         public String toString() {
240             return "Data [installation=" + installation + "]";
241         }
242     }
243
244     public static class Installation {
245
246         private ArmState armState = new ArmState();
247         private Broadband broadband = new Broadband();
248         private EventLog eventLog = new EventLog();
249         private List<Climate> climates = new ArrayList<>();
250         private List<DoorWindow> doorWindows = new ArrayList<>();
251         private List<CommunicationState> communicationState = new ArrayList<>();
252         private List<Mouse> mice = new ArrayList<>();
253         private List<Doorlock> doorlocks = new ArrayList<>();
254         private List<Smartplug> smartplugs = new ArrayList<>();
255         private List<UserTracking> userTrackings = new ArrayList<>();
256
257         @SerializedName("__typename")
258         private @Nullable String typename;
259
260         public ArmState getArmState() {
261             return armState;
262         }
263
264         public Broadband getBroadband() {
265             return broadband;
266         }
267
268         public @Nullable List<Climate> getClimates() {
269             return climates;
270         }
271
272         public void setClimates(List<Climate> climates) {
273             this.climates = climates;
274         }
275
276         public @Nullable List<DoorWindow> getDoorWindows() {
277             return doorWindows;
278         }
279
280         public void setDoorWindows(List<DoorWindow> doorWindows) {
281             this.doorWindows = doorWindows;
282         }
283
284         public EventLog getEventLog() {
285             return eventLog;
286         }
287
288         public @Nullable List<CommunicationState> getCommunicationState() {
289             return communicationState;
290         }
291
292         public @Nullable List<Mouse> getMice() {
293             return mice;
294         }
295
296         public void setMice(List<Mouse> mice) {
297             this.mice = mice;
298         }
299
300         public @Nullable List<Doorlock> getDoorlocks() {
301             return doorlocks;
302         }
303
304         public void setDoorlocks(List<Doorlock> doorlocks) {
305             this.doorlocks = doorlocks;
306         }
307
308         public @Nullable List<Smartplug> getSmartplugs() {
309             return smartplugs;
310         }
311
312         public void setSmartplugs(List<Smartplug> smartplugs) {
313             this.smartplugs = smartplugs;
314         }
315
316         public @Nullable List<UserTracking> getUserTrackings() {
317             return userTrackings;
318         }
319
320         public void setUserTrackings(List<UserTracking> userTrackings) {
321             this.userTrackings = userTrackings;
322         }
323
324         public @Nullable String getTypename() {
325             return typename;
326         }
327
328         @Override
329         public int hashCode() {
330             final int prime = 31;
331             int result = 1;
332             result = prime * result + armState.hashCode();
333             result = prime * result + broadband.hashCode();
334             result = prime * result + climates.hashCode();
335             result = prime * result + communicationState.hashCode();
336             result = prime * result + doorWindows.hashCode();
337             result = prime * result + doorlocks.hashCode();
338             result = prime * result + eventLog.hashCode();
339             result = prime * result + mice.hashCode();
340             result = prime * result + smartplugs.hashCode();
341             String localTypeName = typename;
342             result = prime * result + ((localTypeName == null) ? 0 : localTypeName.hashCode());
343             result = prime * result + userTrackings.hashCode();
344             return result;
345         }
346
347         @SuppressWarnings("PMD.SimplifyBooleanReturns")
348         @Override
349         public boolean equals(@Nullable Object obj) {
350             if (this == obj) {
351                 return true;
352             }
353             if (obj == null) {
354                 return false;
355             }
356             if (getClass() != obj.getClass()) {
357                 return false;
358             }
359             Installation other = (Installation) obj;
360             if (!armState.equals(other.armState)) {
361                 return false;
362             }
363             if (!broadband.equals(other.broadband)) {
364                 return false;
365             }
366             if (!climates.equals(other.climates)) {
367                 return false;
368             }
369             if (!communicationState.equals(other.communicationState)) {
370                 return false;
371             }
372             if (!doorWindows.equals(other.doorWindows)) {
373                 return false;
374             }
375             if (!doorlocks.equals(other.doorlocks)) {
376                 return false;
377             }
378             if (!eventLog.equals(other.eventLog)) {
379                 return false;
380             }
381             if (!mice.equals(other.mice)) {
382                 return false;
383             }
384             if (!smartplugs.equals(other.smartplugs)) {
385                 return false;
386             }
387             String localTypeName = typename;
388             if (localTypeName == null) {
389                 if (other.typename != null) {
390                     return false;
391                 }
392             } else if (!localTypeName.equals(other.typename)) {
393                 return false;
394             }
395             if (!userTrackings.equals(other.userTrackings)) {
396                 return false;
397             }
398             return true;
399         }
400
401         @Override
402         public String toString() {
403             return "Installation [armState=" + armState + ", broadband=" + broadband + ", eventLog=" + eventLog
404                     + ", climates=" + climates + ", doorWindows=" + doorWindows + ", communicationState="
405                     + communicationState + ", mice=" + mice + ", doorlocks=" + doorlocks + ", smartplugs=" + smartplugs
406                     + ", userTrackings=" + userTrackings + ", typename=" + typename + "]";
407         }
408     }
409
410     public static class Device {
411
412         private @Nullable String deviceLabel;
413         private @Nullable String area;
414         private Gui gui = new Gui();
415         @SerializedName("__typename")
416         private @Nullable String typename;
417
418         public @Nullable String getDeviceLabel() {
419             return deviceLabel;
420         }
421
422         public @Nullable String getArea() {
423             return area;
424         }
425
426         public Gui getGui() {
427             return gui;
428         }
429
430         public @Nullable String getTypename() {
431             return typename;
432         }
433
434         @Override
435         public int hashCode() {
436             final int prime = 31;
437             int result = 1;
438             String localArea = area;
439             result = prime * result + ((localArea == null) ? 0 : localArea.hashCode());
440             String localDeviceLabel = deviceLabel;
441             result = prime * result + ((localDeviceLabel == null) ? 0 : localDeviceLabel.hashCode());
442             result = prime * result + gui.hashCode();
443             String localTypeName = typename;
444             result = prime * result + ((localTypeName == null) ? 0 : localTypeName.hashCode());
445             return result;
446         }
447
448         @Override
449         public boolean equals(@Nullable Object obj) {
450             if (this == obj) {
451                 return true;
452             }
453             if (obj == null) {
454                 return false;
455             }
456             if (getClass() != obj.getClass()) {
457                 return false;
458             }
459             Device other = (Device) obj;
460             String localArea = area;
461             if (localArea == null) {
462                 if (other.area != null) {
463                     return false;
464                 }
465             } else if (!localArea.equals(other.area)) {
466                 return false;
467             }
468             String localDeviceLabel = deviceLabel;
469             if (localDeviceLabel == null) {
470                 if (other.deviceLabel != null) {
471                     return false;
472                 }
473             } else if (!localDeviceLabel.equals(other.deviceLabel)) {
474                 return false;
475             }
476             if (!gui.equals(other.gui)) {
477                 return false;
478             }
479             String localTypeName = typename;
480             if (localTypeName == null) {
481                 if (other.typename != null) {
482                     return false;
483                 }
484             } else if (!localTypeName.equals(other.typename)) {
485                 return false;
486             }
487             return true;
488         }
489
490         @Override
491         public String toString() {
492             return "Device [deviceLabel=" + deviceLabel + ", area=" + area + ", gui=" + gui + ", typename=" + typename
493                     + "]";
494         }
495     }
496
497     public static class Gui {
498
499         private @Nullable String label;
500         private @Nullable String support;
501         @SerializedName("__typename")
502         private @Nullable String typename;
503
504         public @Nullable String getLabel() {
505             return label;
506         }
507
508         public @Nullable String getSupport() {
509             return support;
510         }
511
512         public @Nullable String getTypename() {
513             return typename;
514         }
515
516         @Override
517         public int hashCode() {
518             final int prime = 31;
519             int result = 1;
520             String localLabel = label;
521             result = prime * result + ((localLabel == null) ? 0 : localLabel.hashCode());
522             String localSupport = support;
523             result = prime * result + ((localSupport == null) ? 0 : localSupport.hashCode());
524             String localTypeName = typename;
525             result = prime * result + ((localTypeName == null) ? 0 : localTypeName.hashCode());
526             return result;
527         }
528
529         @Override
530         public boolean equals(@Nullable Object obj) {
531             if (this == obj) {
532                 return true;
533             }
534             if (obj == null) {
535                 return false;
536             }
537             if (getClass() != obj.getClass()) {
538                 return false;
539             }
540             Gui other = (Gui) obj;
541             String localLabel = label;
542             if (localLabel == null) {
543                 if (other.label != null) {
544                     return false;
545                 }
546             } else if (!localLabel.equals(other.label)) {
547                 return false;
548             }
549             String localSupport = support;
550             if (localSupport == null) {
551                 if (other.support != null) {
552                     return false;
553                 }
554             } else if (!localSupport.equals(other.support)) {
555                 return false;
556             }
557             String localTypeName = typename;
558             if (localTypeName == null) {
559                 if (other.typename != null) {
560                     return false;
561                 }
562             } else if (!localTypeName.equals(other.typename)) {
563                 return false;
564             }
565             return true;
566         }
567
568         @Override
569         public String toString() {
570             return "Gui [label=" + label + ", support=" + support + ", typename=" + typename + "]";
571         }
572     }
573 }