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