]> git.basschouten.com Git - openhab-addons.git/blob
e9bd0c236923974df1c368f9041a0e427cb0be40
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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      * @throws IllegalArgumentException if one of the parameters is null
48      */
49     public DSMRMeterDescriptor(DSMRMeterType meterType, int channel) {
50         this.meterType = meterType;
51         this.channel = channel;
52     }
53
54     /**
55      * @return the meterType
56      */
57     public DSMRMeterType getMeterType() {
58         return meterType;
59     }
60
61     /**
62      * @return the channel
63      */
64     public int getChannel() {
65         return channel;
66     }
67
68     /**
69      * @return the id to identify of channel as String or as "default" is its the unknown channel.
70      */
71     public String getChannelId() {
72         return channel == DSMRMeterConstants.UNKNOWN_CHANNEL ? "default" : String.valueOf(channel);
73     }
74
75     /**
76      * Returns true if both DSMRMeterDescriptor are equal. I.e.:
77      * - meterType is the same
78      * - channel is the same
79      * - identification is the same
80      *
81      * @param other DSMRMeterDescriptor to check
82      * @return true if both objects are equal, false otherwise
83      */
84     @Override
85     public boolean equals(@Nullable Object other) {
86         if (!(other instanceof DSMRMeterDescriptor)) {
87             return false;
88         }
89         DSMRMeterDescriptor o = (DSMRMeterDescriptor) other;
90
91         return meterType == o.meterType && channel == o.channel;
92     }
93
94     @Override
95     public int hashCode() {
96         return Objects.hash(meterType, channel);
97     }
98
99     @Override
100     public String toString() {
101         return "[Meter type: " + meterType + ", channel: " + channel + ']';
102     }
103 }