2 * Copyright (c) 2010-2023 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();
219 @SuppressWarnings("PMD.SimplifyBooleanReturns")
221 public boolean equals(@Nullable Object obj) {
228 if (getClass() != obj.getClass()) {
231 Data other = (Data) obj;
232 if (!installation.equals(other.installation)) {
239 public String toString() {
240 return "Data [installation=" + installation + "]";
244 public static class Installation {
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<>();
257 @SerializedName("__typename")
258 private @Nullable String typename;
260 public ArmState getArmState() {
264 public Broadband getBroadband() {
268 public @Nullable List<Climate> getClimates() {
272 public void setClimates(List<Climate> climates) {
273 this.climates = climates;
276 public @Nullable List<DoorWindow> getDoorWindows() {
280 public void setDoorWindows(List<DoorWindow> doorWindows) {
281 this.doorWindows = doorWindows;
284 public EventLog getEventLog() {
288 public @Nullable List<CommunicationState> getCommunicationState() {
289 return communicationState;
292 public @Nullable List<Mouse> getMice() {
296 public void setMice(List<Mouse> mice) {
300 public @Nullable List<Doorlock> getDoorlocks() {
304 public void setDoorlocks(List<Doorlock> doorlocks) {
305 this.doorlocks = doorlocks;
308 public @Nullable List<Smartplug> getSmartplugs() {
312 public void setSmartplugs(List<Smartplug> smartplugs) {
313 this.smartplugs = smartplugs;
316 public @Nullable List<UserTracking> getUserTrackings() {
317 return userTrackings;
320 public void setUserTrackings(List<UserTracking> userTrackings) {
321 this.userTrackings = userTrackings;
324 public @Nullable String getTypename() {
329 public int hashCode() {
330 final int prime = 31;
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();
347 @SuppressWarnings("PMD.SimplifyBooleanReturns")
349 public boolean equals(@Nullable Object obj) {
356 if (getClass() != obj.getClass()) {
359 Installation other = (Installation) obj;
360 if (!armState.equals(other.armState)) {
363 if (!broadband.equals(other.broadband)) {
366 if (!climates.equals(other.climates)) {
369 if (!communicationState.equals(other.communicationState)) {
372 if (!doorWindows.equals(other.doorWindows)) {
375 if (!doorlocks.equals(other.doorlocks)) {
378 if (!eventLog.equals(other.eventLog)) {
381 if (!mice.equals(other.mice)) {
384 if (!smartplugs.equals(other.smartplugs)) {
387 String localTypeName = typename;
388 if (localTypeName == null) {
389 if (other.typename != null) {
392 } else if (!localTypeName.equals(other.typename)) {
395 if (!userTrackings.equals(other.userTrackings)) {
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 + "]";
410 public static class Device {
412 private @Nullable String deviceLabel;
413 private @Nullable String area;
414 private Gui gui = new Gui();
415 @SerializedName("__typename")
416 private @Nullable String typename;
418 public @Nullable String getDeviceLabel() {
422 public @Nullable String getArea() {
426 public Gui getGui() {
430 public @Nullable String getTypename() {
435 public int hashCode() {
436 final int prime = 31;
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());
449 public boolean equals(@Nullable Object obj) {
456 if (getClass() != obj.getClass()) {
459 Device other = (Device) obj;
460 String localArea = area;
461 if (localArea == null) {
462 if (other.area != null) {
465 } else if (!localArea.equals(other.area)) {
468 String localDeviceLabel = deviceLabel;
469 if (localDeviceLabel == null) {
470 if (other.deviceLabel != null) {
473 } else if (!localDeviceLabel.equals(other.deviceLabel)) {
476 if (!gui.equals(other.gui)) {
479 String localTypeName = typename;
480 if (localTypeName == null) {
481 if (other.typename != null) {
484 } else if (!localTypeName.equals(other.typename)) {
491 public String toString() {
492 return "Device [deviceLabel=" + deviceLabel + ", area=" + area + ", gui=" + gui + ", typename=" + typename
497 public static class Gui {
499 private @Nullable String label;
500 private @Nullable String support;
501 @SerializedName("__typename")
502 private @Nullable String typename;
504 public @Nullable String getLabel() {
508 public @Nullable String getSupport() {
512 public @Nullable String getTypename() {
517 public int hashCode() {
518 final int prime = 31;
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());
530 public boolean equals(@Nullable Object obj) {
537 if (getClass() != obj.getClass()) {
540 Gui other = (Gui) obj;
541 String localLabel = label;
542 if (localLabel == null) {
543 if (other.label != null) {
546 } else if (!localLabel.equals(other.label)) {
549 String localSupport = support;
550 if (localSupport == null) {
551 if (other.support != null) {
554 } else if (!localSupport.equals(other.support)) {
557 String localTypeName = typename;
558 if (localTypeName == null) {
559 if (other.typename != null) {
562 } else if (!localTypeName.equals(other.typename)) {
569 public String toString() {
570 return "Gui [label=" + label + ", support=" + support + ", typename=" + typename + "]";