2 * Copyright (c) 2010-2020 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.homematic.internal.model;
15 import org.apache.commons.lang.builder.EqualsBuilder;
16 import org.apache.commons.lang.builder.HashCodeBuilder;
19 * Simple representation of a datapoint.
21 * @author Gerhard Riegler - Initial contribution
23 public class HmDatapointInfo {
24 private String address;
25 private Integer channel;
27 private HmParamsetType paramsetType;
29 public HmDatapointInfo(HmDatapoint dp) {
30 this(dp.getParamsetType(), dp.getChannel(), dp.getName());
33 public HmDatapointInfo(HmParamsetType paramsetType, HmChannel channel, String name) {
34 this(channel.getDevice().getAddress(), paramsetType, channel.getNumber(), name);
37 public HmDatapointInfo(String address, HmParamsetType paramsetType, Integer channel, String name) {
38 this.address = address;
39 this.channel = channel;
40 this.paramsetType = paramsetType;
45 * Creates a values HmDatapointInfo.
47 public static HmDatapointInfo createValuesInfo(HmChannel channel, String name) {
48 return new HmDatapointInfo(HmParamsetType.VALUES, channel, name);
52 * Returns the address of the device.
54 public String getAddress() {
59 * Returns the channel number.
61 public Integer getChannel() {
66 * Returns the name of the datapoint.
68 public String getName() {
73 * Sets the name of the datapoint.
75 public void setName(String name) {
80 * Returns the paramset type.
82 public HmParamsetType getParamsetType() {
87 * Return true, if this is a pong datapoint info.
89 public boolean isPong() {
90 return "CENTRAL".equals(address) && "PONG".equals(name);
94 public int hashCode() {
95 return new HashCodeBuilder().append(address).append(paramsetType).append(channel).append(name).toHashCode();
99 public boolean equals(Object obj) {
100 if (obj == null || !(obj instanceof HmDatapointInfo)) {
103 HmDatapointInfo comp = (HmDatapointInfo) obj;
104 return new EqualsBuilder().append(address, comp.getAddress()).append(paramsetType, comp.getParamsetType())
105 .append(channel, comp.getChannel()).append(name, comp.getName()).isEquals();
109 public String toString() {
110 if (paramsetType == HmParamsetType.VALUES) {
111 return String.format("%s:%s#%s", address, channel, name);
113 return String.format("%s:%s_%s#%s", address, paramsetType.getId(), channel, name);