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.tellstick.internal.live.xml;
15 import java.util.List;
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;
24 import org.tellstick.device.iface.Device;
25 import org.tellstick.enums.DeviceType;
28 * Class used to deserialize XML from Telldus Live.
30 * @author Jarle Hjortland - Initial contribution
32 @XmlAccessorType(XmlAccessType.FIELD)
33 @XmlRootElement(name = "sensor")
34 public class TellstickNetSensor implements Device {
35 @XmlAttribute(name = "id")
38 private String protocol;
42 @XmlJavaTypeAdapter(value = NumberToBooleanMapper.class)
43 private Boolean online;
44 @XmlElement(name = "data")
45 private List<DataTypeValue> data;
47 private Long lastUpdated;
48 private boolean updated;
52 public TellstickNetSensor() {
55 public TellstickNetSensor(int id) {
65 public String getUUId() {
66 return Integer.toString(deviceId);
70 public String getProtocol() {
75 public DeviceType getDeviceType() {
76 return DeviceType.SENSOR;
80 public String getName() {
84 public void setId(int deviceId) {
85 this.deviceId = deviceId;
88 public void setProtocol(String protocol) {
89 this.protocol = protocol;
92 public void setName(String name) {
96 public boolean getOnline() {
100 // @XmlJavaTypeAdapter(value = NumberToBooleanMapper.class)
101 public void setOnline(boolean online) {
102 this.online = online;
105 public List<DataTypeValue> getData() {
109 public void setData(List<DataTypeValue> data) {
114 public String getModel() {
118 public Long getLastUpdated() {
122 public void setLastUpdated(Long lastUpdated) {
123 this.lastUpdated = lastUpdated;
127 public int hashCode() {
130 result = prime * result + deviceId;
135 public boolean equals(Object obj) {
142 if (getClass() != obj.getClass()) {
145 TellstickNetSensor other = (TellstickNetSensor) obj;
146 return deviceId == other.deviceId;
149 public void setUpdated(boolean b) {
153 public boolean isUpdated() {
157 public boolean isSensorOfType(LiveDataType type) {
160 for (DataTypeValue val : data) {
161 if (val.getName() == type) {
170 public Long getBattery() {
174 public void setBattery(Long battery) {
175 this.battery = battery;
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();