]> git.basschouten.com Git - openhab-addons.git/blob
5dd17327168829946c5b680749a254cb0569e121
[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.tellstick.internal.local.dto;
14
15 import java.util.List;
16
17 import org.openhab.binding.tellstick.internal.live.xml.LiveDataType;
18 import org.tellstick.device.iface.Device;
19 import org.tellstick.enums.DeviceType;
20
21 import com.google.gson.annotations.SerializedName;
22
23 /**
24  * Class used to deserialize JSON from Telldus local API.
25  *
26  * @author Jan Gustafsson - Initial contribution
27  */
28 public class TellstickLocalSensorDTO implements Device {
29
30     private int battery;
31     private boolean updated;
32     private List<LocalDataTypeValueDTO> data = null;
33     @SerializedName("id")
34     private int deviceId;
35     private String model;
36     private String name;
37     private String protocol;
38     private int sensorId;
39
40     public int getBattery() {
41         return battery;
42     }
43
44     public void setBattery(int battery) {
45         this.battery = battery;
46     }
47
48     public List<LocalDataTypeValueDTO> getData() {
49         return data;
50     }
51
52     public void setData(List<LocalDataTypeValueDTO> data) {
53         this.data = data;
54     }
55
56     @Override
57     public int getId() {
58         return deviceId;
59     }
60
61     public void setId(int id) {
62         this.deviceId = id;
63     }
64
65     @Override
66     public String getModel() {
67         return model;
68     }
69
70     public void setModel(String model) {
71         this.model = model;
72     }
73
74     @Override
75     public String getName() {
76         return name;
77     }
78
79     public void setName(String name) {
80         this.name = name;
81     }
82
83     @Override
84     public String getProtocol() {
85         return protocol;
86     }
87
88     public void setProtocol(String protocol) {
89         this.protocol = protocol;
90     }
91
92     public void setUpdated(boolean b) {
93         this.updated = b;
94     }
95
96     public boolean isUpdated() {
97         return updated;
98     }
99
100     public boolean isSensorOfType(LiveDataType type) {
101         boolean res = false;
102         if (data != null) {
103             for (LocalDataTypeValueDTO val : data) {
104                 if (val.getName() == type) {
105                     res = true;
106                     break;
107                 }
108             }
109         }
110         return res;
111     }
112
113     @Override
114     public DeviceType getDeviceType() {
115         return DeviceType.SENSOR;
116     }
117
118     public int getSensorId() {
119         return sensorId;
120     }
121
122     public void setSensorId(int sensorId) {
123         this.sensorId = sensorId;
124     }
125
126     @Override
127     public String getUUId() {
128         return Integer.toString(deviceId);
129     }
130
131     @Override
132     public boolean equals(Object obj) {
133         // used to test if sensor exist
134         if (this == obj) {
135             return true;
136         }
137         if (!(obj instanceof TellstickLocalSensorDTO other)) {
138             return false;
139         }
140         return deviceId == other.deviceId;
141     }
142
143     @Override
144     public int hashCode() {
145         return deviceId;
146     }
147 }