]> git.basschouten.com Git - openhab-addons.git/blob
67ac4a7bdc9039fe344e0277a5be3d298b700952
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.homematic.internal.model;
14
15 import org.apache.commons.lang.builder.EqualsBuilder;
16 import org.apache.commons.lang.builder.HashCodeBuilder;
17
18 /**
19  * Simple representation of a datapoint.
20  *
21  * @author Gerhard Riegler - Initial contribution
22  */
23 public class HmDatapointInfo {
24     private String address;
25     private Integer channel;
26     private String name;
27     private HmParamsetType paramsetType;
28
29     public HmDatapointInfo(HmDatapoint dp) {
30         this(dp.getParamsetType(), dp.getChannel(), dp.getName());
31     }
32
33     public HmDatapointInfo(HmParamsetType paramsetType, HmChannel channel, String name) {
34         this(channel.getDevice().getAddress(), paramsetType, channel.getNumber(), name);
35     }
36
37     public HmDatapointInfo(String address, HmParamsetType paramsetType, Integer channel, String name) {
38         this.address = address;
39         this.channel = channel;
40         this.paramsetType = paramsetType;
41         this.name = name;
42     }
43
44     /**
45      * Creates a values HmDatapointInfo.
46      */
47     public static HmDatapointInfo createValuesInfo(HmChannel channel, String name) {
48         return new HmDatapointInfo(HmParamsetType.VALUES, channel, name);
49     }
50
51     /**
52      * Returns the address of the device.
53      */
54     public String getAddress() {
55         return address;
56     }
57
58     /**
59      * Returns the channel number.
60      */
61     public Integer getChannel() {
62         return channel;
63     }
64
65     /**
66      * Returns the name of the datapoint.
67      */
68     public String getName() {
69         return name;
70     }
71
72     /**
73      * Sets the name of the datapoint.
74      */
75     public void setName(String name) {
76         this.name = name;
77     }
78
79     /**
80      * Returns the paramset type.
81      */
82     public HmParamsetType getParamsetType() {
83         return paramsetType;
84     }
85
86     /**
87      * Return true, if this is a pong datapoint info.
88      */
89     public boolean isPong() {
90         return "CENTRAL".equals(address) && "PONG".equals(name);
91     }
92
93     @Override
94     public int hashCode() {
95         return new HashCodeBuilder().append(address).append(paramsetType).append(channel).append(name).toHashCode();
96     }
97
98     @Override
99     public boolean equals(Object obj) {
100         if (obj == null || !(obj instanceof HmDatapointInfo)) {
101             return false;
102         }
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();
106     }
107
108     @Override
109     public String toString() {
110         if (paramsetType == HmParamsetType.VALUES) {
111             return String.format("%s:%s#%s", address, channel, name);
112         }
113         return String.format("%s:%s_%s#%s", address, paramsetType.getId(), channel, name);
114     }
115 }