]> git.basschouten.com Git - openhab-addons.git/blob
d01ea6198d3aa319a3349e70f55db7cfd1ab8dcd
[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.live.xml;
14
15 import java.util.List;
16
17 import javax.xml.bind.annotation.XmlAccessType;
18 import javax.xml.bind.annotation.XmlAccessorType;
19 import javax.xml.bind.annotation.XmlAttribute;
20 import javax.xml.bind.annotation.XmlElement;
21 import javax.xml.bind.annotation.XmlRootElement;
22 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
23
24 import org.tellstick.device.iface.Device;
25 import org.tellstick.enums.DeviceType;
26
27 /**
28  * Class used to deserialize XML from Telldus Live.
29  *
30  * @author Jarle Hjortland - Initial contribution
31  */
32 @XmlAccessorType(XmlAccessType.FIELD)
33 @XmlRootElement(name = "sensor")
34 public class TellstickNetSensor implements Device {
35     @XmlAttribute(name = "id")
36     int deviceId;
37     @XmlAttribute()
38     private String protocol;
39     @XmlAttribute()
40     private String name;
41     @XmlAttribute()
42     @XmlJavaTypeAdapter(value = NumberToBooleanMapper.class)
43     private Boolean online;
44     @XmlElement(name = "data")
45     private List<DataTypeValue> data;
46     @XmlAttribute()
47     private Long lastUpdated;
48     private boolean updated;
49     @XmlAttribute()
50     private Long battery;
51
52     public TellstickNetSensor() {
53     }
54
55     public TellstickNetSensor(int id) {
56         this.deviceId = id;
57     }
58
59     @Override
60     public int getId() {
61         return deviceId;
62     }
63
64     @Override
65     public String getUUId() {
66         return Integer.toString(deviceId);
67     }
68
69     @Override
70     public String getProtocol() {
71         return protocol;
72     }
73
74     @Override
75     public DeviceType getDeviceType() {
76         return DeviceType.SENSOR;
77     }
78
79     @Override
80     public String getName() {
81         return name;
82     }
83
84     public void setId(int deviceId) {
85         this.deviceId = deviceId;
86     }
87
88     public void setProtocol(String protocol) {
89         this.protocol = protocol;
90     }
91
92     public void setName(String name) {
93         this.name = name;
94     }
95
96     public boolean getOnline() {
97         return online;
98     }
99
100     // @XmlJavaTypeAdapter(value = NumberToBooleanMapper.class)
101     public void setOnline(boolean online) {
102         this.online = online;
103     }
104
105     public List<DataTypeValue> getData() {
106         return data;
107     }
108
109     public void setData(List<DataTypeValue> data) {
110         this.data = data;
111     }
112
113     @Override
114     public String getModel() {
115         return null;
116     }
117
118     public Long getLastUpdated() {
119         return lastUpdated;
120     }
121
122     public void setLastUpdated(Long lastUpdated) {
123         this.lastUpdated = lastUpdated;
124     }
125
126     @Override
127     public int hashCode() {
128         int prime = 31;
129         int result = 1;
130         result = prime * result + deviceId;
131         return result;
132     }
133
134     @Override
135     public boolean equals(Object obj) {
136         if (this == obj) {
137             return true;
138         }
139         if (obj == null) {
140             return false;
141         }
142         if (getClass() != obj.getClass()) {
143             return false;
144         }
145         TellstickNetSensor other = (TellstickNetSensor) obj;
146         return deviceId == other.deviceId;
147     }
148
149     public void setUpdated(boolean b) {
150         this.updated = b;
151     }
152
153     public boolean isUpdated() {
154         return updated;
155     }
156
157     public boolean isSensorOfType(LiveDataType type) {
158         boolean res = false;
159         if (data != null) {
160             for (DataTypeValue val : data) {
161                 if (val.getName() == type) {
162                     res = true;
163                     break;
164                 }
165             }
166         }
167         return res;
168     }
169
170     public Long getBattery() {
171         return battery;
172     }
173
174     public void setBattery(Long battery) {
175         this.battery = battery;
176     }
177
178     @Override
179     public String toString() {
180         StringBuilder builder = new StringBuilder();
181         builder.append("TellstickNetSensor [deviceId=").append(deviceId).append(", protocol=").append(protocol)
182                 .append(", name=").append(name).append(", online=").append(online).append(", data=").append(data)
183                 .append(", lastUpdated=").append(lastUpdated).append(", updated=").append(updated).append("]");
184         return builder.toString();
185     }
186 }