2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.solax.internal.model.local;
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;
23 * The {@link CommonLocalInverterData} is an abstract class that contains the common information, applicable for all
26 * @author Konstantin Polihronov - Initial contribution
29 public abstract class CommonLocalInverterData implements LocalInverterData {
31 private final Logger logger = LoggerFactory.getLogger(CommonLocalInverterData.class);
33 private LocalConnectRawDataBean data;
35 public CommonLocalInverterData(LocalConnectRawDataBean data) {
40 public @Nullable String getRawData() {
41 return data.getRawData();
45 public @Nullable String getWifiSerial() {
50 public @Nullable String getWifiVersion() {
55 public InverterType getInverterType() {
56 return InverterType.fromIndex(data.getType());
59 protected short getData(int index) {
61 short[] dataArray = data.getData();
62 if (dataArray != null) {
63 return dataArray[index];
65 } catch (IndexOutOfBoundsException e) {
66 logger.debug("Tried to get data out of bounds of the raw data array.", e);
71 public long packU16(int indexMajor, int indexMinor) {
72 short major = getData(indexMajor);
73 short minor = getData(indexMinor);
78 return Integer.toUnsignedLong(major << 16 | minor & 0xFFFF);