2 * Copyright (c) 2010-2021 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.verisure.internal.dto;
15 import java.math.BigDecimal;
16 import java.util.ArrayList;
17 import java.util.List;
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;
34 import com.google.gson.annotations.SerializedName;
37 * A base JSON thing for other Verisure things to inherit from.
39 * @author Jarle Hjortland - Initial contribution
43 public abstract class VerisureBaseThingDTO implements VerisureThingDTO {
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();
53 public @Nullable String getStatus() {
57 public void setStatus(String status) {
61 public @Nullable String getName() {
65 public void setName(String name) {
70 public String getDeviceId() {
75 public void setDeviceId(String deviceId) {
76 // Make sure device id is normalized
77 this.deviceId = VerisureThingConfiguration.normalizeDeviceId(deviceId);
81 public @Nullable String getLocation() {
85 public void setLocation(@Nullable String location) {
86 this.location = location;
90 public @Nullable String getSiteName() {
95 public void setSiteName(@Nullable String siteName) {
96 this.siteName = siteName;
100 public BigDecimal getSiteId() {
105 public void setSiteId(BigDecimal siteId) {
106 this.siteId = siteId;
110 public abstract ThingTypeUID getThingTypeUID();
112 public Data getData() {
116 public void setData(Data data) {
121 public int hashCode() {
122 final int prime = 31;
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());
139 public boolean equals(@Nullable Object obj) {
146 if (getClass() != obj.getClass()) {
149 VerisureBaseThingDTO other = (VerisureBaseThingDTO) obj;
150 if (!data.equals(other.data)) {
153 if (!deviceId.equals(other.deviceId)) {
156 String localLocation = location;
157 if (localLocation == null) {
158 if (other.location != null) {
161 } else if (!localLocation.equals(other.location)) {
164 String localName = name;
165 if (localName == null) {
166 if (other.name != null) {
169 } else if (!localName.equals(other.name)) {
172 if (!siteId.equals(other.siteId)) {
175 String localSiteName = siteName;
176 if (localSiteName == null) {
177 if (other.siteName != null) {
180 } else if (!localSiteName.equals(other.siteName)) {
183 String localStatus = status;
184 if (localStatus == null) {
185 if (other.status != null) {
188 } else if (!localStatus.equals(other.status)) {
195 public String toString() {
196 return "VerisureBaseThingDTO [deviceId=" + deviceId + ", name=" + name + ", location=" + location + ", status="
197 + status + ", siteName=" + siteName + ", siteId=" + siteId + ", data=" + data + "]";
200 public static class Data {
201 private Installation installation = new Installation();
203 public Installation getInstallation() {
207 public void setInstallation(Installation installation) {
208 this.installation = installation;
212 public int hashCode() {
213 final int prime = 31;
215 result = prime * result + installation.hashCode();
220 public boolean equals(@Nullable Object obj) {
227 if (getClass() != obj.getClass()) {
230 Data other = (Data) obj;
231 if (!installation.equals(other.installation)) {
238 public String toString() {
239 return "Data [installation=" + installation + "]";
243 public static class Installation {
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<>();
256 @SerializedName("__typename")
257 private @Nullable String typename;
259 public ArmState getArmState() {
263 public Broadband getBroadband() {
267 public @Nullable List<Climate> getClimates() {
271 public void setClimates(List<Climate> climates) {
272 this.climates = climates;
275 public @Nullable List<DoorWindow> getDoorWindows() {
279 public void setDoorWindows(List<DoorWindow> doorWindows) {
280 this.doorWindows = doorWindows;
283 public EventLog getEventLog() {
287 public @Nullable List<CommunicationState> getCommunicationState() {
288 return communicationState;
291 public @Nullable List<Mouse> getMice() {
295 public void setMice(List<Mouse> mice) {
299 public @Nullable List<Doorlock> getDoorlocks() {
303 public void setDoorlocks(List<Doorlock> doorlocks) {
304 this.doorlocks = doorlocks;
307 public @Nullable List<Smartplug> getSmartplugs() {
311 public void setSmartplugs(List<Smartplug> smartplugs) {
312 this.smartplugs = smartplugs;
315 public @Nullable List<UserTracking> getUserTrackings() {
316 return userTrackings;
319 public void setUserTrackings(List<UserTracking> userTrackings) {
320 this.userTrackings = userTrackings;
323 public @Nullable String getTypename() {
328 public int hashCode() {
329 final int prime = 31;
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();
347 public boolean equals(@Nullable Object obj) {
354 if (getClass() != obj.getClass()) {
357 Installation other = (Installation) obj;
358 if (!armState.equals(other.armState)) {
361 if (!broadband.equals(other.broadband)) {
364 if (!climates.equals(other.climates)) {
367 if (!communicationState.equals(other.communicationState)) {
370 if (!doorWindows.equals(other.doorWindows)) {
373 if (!doorlocks.equals(other.doorlocks)) {
376 if (!eventLog.equals(other.eventLog)) {
379 if (!mice.equals(other.mice)) {
382 if (!smartplugs.equals(other.smartplugs)) {
385 String localTypeName = typename;
386 if (localTypeName == null) {
387 if (other.typename != null) {
390 } else if (!localTypeName.equals(other.typename)) {
393 if (!userTrackings.equals(other.userTrackings)) {
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 + "]";
408 public static class Device {
410 private @Nullable String deviceLabel;
411 private @Nullable String area;
412 private Gui gui = new Gui();
413 @SerializedName("__typename")
414 private @Nullable String typename;
416 public @Nullable String getDeviceLabel() {
420 public @Nullable String getArea() {
424 public Gui getGui() {
428 public @Nullable String getTypename() {
433 public int hashCode() {
434 final int prime = 31;
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());
447 public boolean equals(@Nullable Object obj) {
454 if (getClass() != obj.getClass()) {
457 Device other = (Device) obj;
458 String localArea = area;
459 if (localArea == null) {
460 if (other.area != null) {
463 } else if (!localArea.equals(other.area)) {
466 String localDeviceLabel = deviceLabel;
467 if (localDeviceLabel == null) {
468 if (other.deviceLabel != null) {
471 } else if (!localDeviceLabel.equals(other.deviceLabel)) {
474 if (!gui.equals(other.gui)) {
477 String localTypeName = typename;
478 if (localTypeName == null) {
479 if (other.typename != null) {
482 } else if (!localTypeName.equals(other.typename)) {
489 public String toString() {
490 return "Device [deviceLabel=" + deviceLabel + ", area=" + area + ", gui=" + gui + ", typename=" + typename
495 public static class Gui {
497 private @Nullable String label;
498 private @Nullable String support;
499 @SerializedName("__typename")
500 private @Nullable String typename;
502 public @Nullable String getLabel() {
506 public @Nullable String getSupport() {
510 public @Nullable String getTypename() {
515 public int hashCode() {
516 final int prime = 31;
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());
528 public boolean equals(@Nullable Object obj) {
535 if (getClass() != obj.getClass()) {
538 Gui other = (Gui) obj;
539 String localLabel = label;
540 if (localLabel == null) {
541 if (other.label != null) {
544 } else if (!localLabel.equals(other.label)) {
547 String localSupport = support;
548 if (localSupport == null) {
549 if (other.support != null) {
552 } else if (!localSupport.equals(other.support)) {
555 String localTypeName = typename;
556 if (localTypeName == null) {
557 if (other.typename != null) {
560 } else if (!localTypeName.equals(other.typename)) {
567 public String toString() {
568 return "Gui [label=" + label + ", support=" + support + ", typename=" + typename + "]";