]> git.basschouten.com Git - openhab-addons.git/blob
6d7f23f5ad6ddf7d9f95e550fa810be520e082a3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.solax.internal.model.local;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.solax.internal.connectivity.rawdata.local.LocalConnectRawDataBean;
18 import org.openhab.binding.solax.internal.model.InverterType;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * The {@link CommonLocalInverterData} is an abstract class that contains the common information, applicable for all
24  * inverters.
25  *
26  * @author Konstantin Polihronov - Initial contribution
27  */
28 @NonNullByDefault
29 public abstract class CommonLocalInverterData implements LocalInverterData {
30
31     private final Logger logger = LoggerFactory.getLogger(CommonLocalInverterData.class);
32
33     private LocalConnectRawDataBean data;
34
35     public CommonLocalInverterData(LocalConnectRawDataBean data) {
36         this.data = data;
37     }
38
39     @Override
40     public @Nullable String getRawData() {
41         return data.getRawData();
42     }
43
44     @Override
45     public @Nullable String getWifiSerial() {
46         return data.getSn();
47     }
48
49     @Override
50     public @Nullable String getWifiVersion() {
51         return data.getVer();
52     }
53
54     @Override
55     public InverterType getInverterType() {
56         return InverterType.fromIndex(data.getType());
57     }
58
59     protected short getData(int index) {
60         try {
61             short[] dataArray = data.getData();
62             if (dataArray != null) {
63                 return dataArray[index];
64             }
65         } catch (IndexOutOfBoundsException e) {
66             logger.debug("Tried to get data out of bounds of the raw data array.", e);
67         }
68         return 0;
69     }
70
71     public long packU16(int indexMajor, int indexMinor) {
72         short major = getData(indexMajor);
73         short minor = getData(indexMinor);
74         if (major == 0) {
75             return minor;
76         }
77
78         return Integer.toUnsignedLong(major << 16 | minor & 0xFFFF);
79     }
80 }