]> git.basschouten.com Git - openhab-addons.git/blob
856cf4dc877e8ddf61ca418161b259724eff615c
[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.digitalstrom.internal.lib.structure.devices.deviceparameters.impl;
14
15 /**
16  * The {@link DSUID} represents the digitalSTROM-Device unique identifier.
17  *
18  * @author Alexander Friese - Initial contribution
19  */
20 public class DSUID {
21
22     private final String dsuid;
23     private static final String DEFAULT_DSUID = "3504175fe0000000000000000000000001";
24
25     /**
26      * Creates a new {@link DSUID}.
27      *
28      * @param dsuid to create
29      */
30     public DSUID(String dsuid) {
31         var trimmedDsuid = dsuid != null ? dsuid.trim() : "";
32         if (trimmedDsuid.length() == 34) {
33             this.dsuid = trimmedDsuid;
34         } else {
35             this.dsuid = DEFAULT_DSUID;
36         }
37     }
38
39     /**
40      * Returns the dSUID as {@link String}.
41      *
42      * @return dsuid
43      */
44     public String getValue() {
45         return dsuid;
46     }
47
48     @Override
49     public boolean equals(Object obj) {
50         if (obj instanceof DSUID) {
51             return ((DSUID) obj).getValue().equals(this.getValue());
52         }
53         return false;
54     }
55
56     @Override
57     public int hashCode() {
58         return dsuid.hashCode();
59     }
60
61     @Override
62     public String toString() {
63         return dsuid;
64     }
65 }