]> git.basschouten.com Git - openhab-addons.git/blob
f8e37768e20f87c4cbb51c5deb39ed352d156e92
[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.sinope.internal.config;
14
15 /**
16  * Holds Config for the Sinope Gateway
17  *
18  * @author Pascal Larin - Initial contribution
19  *
20  */
21 public class SinopeConfig {
22     /**
23      * Hostname of the Sinope Gateway
24      */
25     public String hostname;
26     /**
27      * ip port
28      */
29     public Integer port;
30     /**
31      * Gateway ID
32      */
33     public String gatewayId;
34     /**
35      * API Key returned by the Gateway
36      */
37     public String apiKey;
38     /**
39      * The number of seconds between fetches from the sinope deivces
40      */
41     public Integer refresh;
42
43     /**
44      * Convert Hex Config String to byte
45      */
46     public static byte[] convert(String value) {
47         if (value == null) {
48             return null;
49         }
50         String _value = value;
51
52         _value = _value.replace("-", "");
53         _value = _value.replace("0x", "");
54         _value = _value.replace(" ", "");
55
56         if (_value.length() == 0) {
57             return null;
58         }
59
60         if (_value.length() % 2 == 0 && _value.length() > 1) {
61             byte[] b = new byte[_value.length() / 2];
62
63             for (int i = 0; i < _value.length(); i = i + 2) {
64                 b[i / 2] = (byte) Integer.parseInt(_value.substring(i, i + 2), 16);
65             }
66             return b;
67         } else {
68             return null;
69         }
70     }
71 }