]> git.basschouten.com Git - openhab-addons.git/blob
d9f3f0113044ddf7d9c9e9155a91d8a7c7913936
[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.dsmr.internal.meter;
14
15 import java.util.Objects;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 /**
21  * The DSMRMeterDescriptor describes a meter.
22  *
23  * A DSMR Meter consists of the following properties:
24  * - MeterType
25  * - M-Bus channel
26  * - Identifier
27  *
28  * @author M. Volaart - Initial contribution
29  */
30 @NonNullByDefault
31 public class DSMRMeterDescriptor {
32     /**
33      * Meter type
34      */
35     private final DSMRMeterType meterType;
36
37     /**
38      * M-Bus channel
39      */
40     private final int channel;
41
42     /**
43      * Constructor for new DSMRMeterDescriptor
44      *
45      * @param meterType The meter type
46      * @param channel The M-Bus channel this meter is connected to
47      */
48     public DSMRMeterDescriptor(DSMRMeterType meterType, int channel) {
49         this.meterType = meterType;
50         this.channel = channel;
51     }
52
53     /**
54      * @return the meterType
55      */
56     public DSMRMeterType getMeterType() {
57         return meterType;
58     }
59
60     /**
61      * @return the channel
62      */
63     public int getChannel() {
64         return channel;
65     }
66
67     /**
68      * @return the id to identify of channel as String or as "default" is its the unknown channel.
69      */
70     public String getChannelId() {
71         return channel == DSMRMeterConstants.UNKNOWN_CHANNEL ? "default" : String.valueOf(channel);
72     }
73
74     /**
75      * Returns true if both DSMRMeterDescriptor are equal. I.e.:
76      * - meterType is the same
77      * - channel is the same
78      * - identification is the same
79      *
80      * @param other DSMRMeterDescriptor to check
81      * @return true if both objects are equal, false otherwise
82      */
83     @Override
84     public boolean equals(@Nullable Object other) {
85         if (!(other instanceof DSMRMeterDescriptor)) {
86             return false;
87         }
88         DSMRMeterDescriptor o = (DSMRMeterDescriptor) other;
89
90         return meterType == o.meterType && channel == o.channel;
91     }
92
93     @Override
94     public int hashCode() {
95         return Objects.hash(meterType, channel);
96     }
97
98     @Override
99     public String toString() {
100         return "[Meter type: " + meterType + ", channel: " + channel + ']';
101     }
102 }