]> git.basschouten.com Git - openhab-addons.git/blob
f73833a9a7ace0106af16c60925078f79fb80849
[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.digitalstrom.internal.lib.structure.devices.deviceparameters.impl;
14
15 /**
16  * The {@link DSID} represents the digitalSTROM-Device identifier.
17  *
18  * @author Alexander Betker - initial contributer
19  */
20 public class DSID {
21
22     private String dsid;
23     private final String DEFAULT_DSID = "3504175fe000000000000001";
24     private final String PRE = "3504175fe0000000";
25
26     /**
27      * Creates a new {@link DSID}.
28      *
29      * @param dsid to create
30      */
31     public DSID(String dsid) {
32         this.dsid = dsid;
33         if (dsid != null && !dsid.trim().equals("")) {
34             if (dsid.trim().length() == 24) {
35                 this.dsid = dsid;
36             } else if (dsid.trim().length() == 8) {
37                 this.dsid = this.PRE + dsid;
38             } else if (dsid.trim().toUpperCase().equals("ALL")) {
39                 this.dsid = "ALL";
40             } else {
41                 this.dsid = DEFAULT_DSID;
42             }
43         } else {
44             this.dsid = DEFAULT_DSID;
45         }
46     }
47
48     /**
49      * Returns the dSID as {@link String}.
50      *
51      * @return dSID
52      */
53     public String getValue() {
54         return dsid;
55     }
56
57     @Override
58     public boolean equals(Object obj) {
59         if (obj instanceof DSID) {
60             return ((DSID) obj).getValue().equals(this.getValue());
61         }
62         return false;
63     }
64
65     @Override
66     public int hashCode() {
67         return dsid.hashCode();
68     }
69
70     @Override
71     public String toString() {
72         return dsid;
73     }
74 }