diff --git a/bundles/org.openhab.binding.systeminfo/pom.xml b/bundles/org.openhab.binding.systeminfo/pom.xml
index e9cea023520..a9c0fffde05 100644
--- a/bundles/org.openhab.binding.systeminfo/pom.xml
+++ b/bundles/org.openhab.binding.systeminfo/pom.xml
@@ -22,19 +22,19 @@
net.java.dev.jna
jna-platform
- 5.5.0
+ 5.9.0
compile
net.java.dev.jna
jna
- 5.5.0
+ 5.9.0
compile
com.github.oshi
oshi-core
- 4.5.2
+ 5.8.2
compile
diff --git a/bundles/org.openhab.binding.systeminfo/src/main/feature/feature.xml b/bundles/org.openhab.binding.systeminfo/src/main/feature/feature.xml
index 6b8275687f5..28179ca46f4 100644
--- a/bundles/org.openhab.binding.systeminfo/src/main/feature/feature.xml
+++ b/bundles/org.openhab.binding.systeminfo/src/main/feature/feature.xml
@@ -4,9 +4,9 @@
openhab-runtime-base
- mvn:net.java.dev.jna/jna/5.5.0
- mvn:net.java.dev.jna/jna-platform/5.5.0
- mvn:com.github.oshi/oshi-core/4.5.2
+ mvn:net.java.dev.jna/jna/5.9.0
+ mvn:net.java.dev.jna/jna-platform/5.9.0
+ mvn:com.github.oshi/oshi-core/5.8.2
mvn:org.openhab.addons.bundles/org.openhab.binding.systeminfo/${project.version}
diff --git a/bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/model/OSHISysteminfo.java b/bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/model/OSHISysteminfo.java
index 7bb4b63badc..83088c1a6cf 100644
--- a/bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/model/OSHISysteminfo.java
+++ b/bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/model/OSHISysteminfo.java
@@ -14,6 +14,7 @@ package org.openhab.binding.systeminfo.internal.model;
import java.math.BigDecimal;
import java.math.RoundingMode;
+import java.util.List;
import org.apache.commons.lang3.ArrayUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -68,11 +69,11 @@ public class OSHISysteminfo implements SysteminfoInterface {
// Static objects, should be recreated on each request
private @NonNullByDefault({}) ComputerSystem computerSystem;
private @NonNullByDefault({}) OperatingSystem operatingSystem;
- private @NonNullByDefault({}) NetworkIF[] networks;
- private @NonNullByDefault({}) Display[] displays;
- private @NonNullByDefault({}) OSFileStore[] fileStores;
- private @NonNullByDefault({}) PowerSource[] powerSources;
- private @NonNullByDefault({}) HWDiskStore[] drives;
+ private @NonNullByDefault({}) List networks;
+ private @NonNullByDefault({}) List displays;
+ private @NonNullByDefault({}) List fileStores;
+ private @NonNullByDefault({}) List powerSources;
+ private @NonNullByDefault({}) List drives;
public static final int PRECISION_AFTER_DECIMAL_SIGN = 1;
@@ -105,8 +106,15 @@ public class OSHISysteminfo implements SysteminfoInterface {
drives = hal.getDiskStores();
}
- private Object getDevice(Object @Nullable [] devices, int index) throws DeviceNotFoundException {
- if ((devices == null) || (devices.length <= index)) {
+ private T getDevice(List<@Nullable T> devices, int index) throws DeviceNotFoundException {
+ if (devices.size() <= index) {
+ throw new DeviceNotFoundException("Device with index: " + index + " can not be found!");
+ }
+ return (T) devices.get(index);
+ }
+
+ private T getDevice(T @Nullable [] devices, int index) throws DeviceNotFoundException {
+ if (devices == null || devices.length <= index) {
throw new DeviceNotFoundException("Device with index: " + index + " can not be found!");
}
return devices[index];
@@ -196,8 +204,8 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override
public DecimalType getStorageTotal(int index) throws DeviceNotFoundException {
- OSFileStore fileStore = (OSFileStore) getDevice(fileStores, index);
- fileStore.updateAtrributes();
+ OSFileStore fileStore = getDevice(fileStores, index);
+ fileStore.updateAttributes();
long totalSpace = fileStore.getTotalSpace();
totalSpace = getSizeInMB(totalSpace);
return new DecimalType(totalSpace);
@@ -205,8 +213,8 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override
public DecimalType getStorageAvailable(int index) throws DeviceNotFoundException {
- OSFileStore fileStore = (OSFileStore) getDevice(fileStores, index);
- fileStore.updateAtrributes();
+ OSFileStore fileStore = getDevice(fileStores, index);
+ fileStore.updateAttributes();
long freeSpace = fileStore.getUsableSpace();
freeSpace = getSizeInMB(freeSpace);
return new DecimalType(freeSpace);
@@ -214,8 +222,8 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override
public DecimalType getStorageUsed(int index) throws DeviceNotFoundException {
- OSFileStore fileStore = (OSFileStore) getDevice(fileStores, index);
- fileStore.updateAtrributes();
+ OSFileStore fileStore = getDevice(fileStores, index);
+ fileStore.updateAttributes();
long totalSpace = fileStore.getTotalSpace();
long freeSpace = fileStore.getUsableSpace();
long usedSpace = totalSpace - freeSpace;
@@ -225,8 +233,8 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override
public @Nullable DecimalType getStorageAvailablePercent(int deviceIndex) throws DeviceNotFoundException {
- OSFileStore fileStore = (OSFileStore) getDevice(fileStores, deviceIndex);
- fileStore.updateAtrributes();
+ OSFileStore fileStore = getDevice(fileStores, deviceIndex);
+ fileStore.updateAttributes();
long totalSpace = fileStore.getTotalSpace();
long freeSpace = fileStore.getUsableSpace();
if (totalSpace > 0) {
@@ -240,8 +248,8 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override
public @Nullable DecimalType getStorageUsedPercent(int deviceIndex) throws DeviceNotFoundException {
- OSFileStore fileStore = (OSFileStore) getDevice(fileStores, deviceIndex);
- fileStore.updateAtrributes();
+ OSFileStore fileStore = getDevice(fileStores, deviceIndex);
+ fileStore.updateAttributes();
long totalSpace = fileStore.getTotalSpace();
long freeSpace = fileStore.getUsableSpace();
long usedSpace = totalSpace - freeSpace;
@@ -256,51 +264,51 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override
public StringType getStorageName(int index) throws DeviceNotFoundException {
- OSFileStore fileStore = (OSFileStore) getDevice(fileStores, index);
+ OSFileStore fileStore = getDevice(fileStores, index);
String name = fileStore.getName();
return new StringType(name);
}
@Override
public StringType getStorageType(int deviceIndex) throws DeviceNotFoundException {
- OSFileStore fileStore = (OSFileStore) getDevice(fileStores, deviceIndex);
+ OSFileStore fileStore = getDevice(fileStores, deviceIndex);
String type = fileStore.getType();
return new StringType(type);
}
@Override
public StringType getStorageDescription(int index) throws DeviceNotFoundException {
- OSFileStore fileStore = (OSFileStore) getDevice(fileStores, index);
+ OSFileStore fileStore = getDevice(fileStores, index);
String description = fileStore.getDescription();
return new StringType(description);
}
@Override
public StringType getNetworkIp(int index) throws DeviceNotFoundException {
- NetworkIF netInterface = (NetworkIF) getDevice(networks, index);
+ NetworkIF netInterface = getDevice(networks, index);
netInterface.updateAttributes();
String[] ipAddresses = netInterface.getIPv4addr();
- String ipv4 = (String) getDevice(ipAddresses, 0);
+ String ipv4 = getDevice(ipAddresses, 0);
return new StringType(ipv4);
}
@Override
public StringType getNetworkName(int index) throws DeviceNotFoundException {
- NetworkIF netInterface = (NetworkIF) getDevice(networks, index);
+ NetworkIF netInterface = getDevice(networks, index);
String name = netInterface.getName();
return new StringType(name);
}
@Override
public StringType getNetworkDisplayName(int index) throws DeviceNotFoundException {
- NetworkIF netInterface = (NetworkIF) getDevice(networks, index);
+ NetworkIF netInterface = getDevice(networks, index);
String adapterName = netInterface.getDisplayName();
return new StringType(adapterName);
}
@Override
public StringType getDisplayInformation(int index) throws DeviceNotFoundException {
- Display display = (Display) getDevice(displays, index);
+ Display display = getDevice(displays, index);
byte[] edid = display.getEdid();
String manufacturer = EdidUtil.getManufacturerID(edid);
@@ -331,13 +339,13 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override
public @Nullable DecimalType getSensorsFanSpeed(int index) throws DeviceNotFoundException {
int[] fanSpeeds = sensors.getFanSpeeds();
- int speed = (int) getDevice(ArrayUtils.toObject(fanSpeeds), index);
+ int speed = getDevice(ArrayUtils.toObject(fanSpeeds), index);
return speed > 0 ? new DecimalType(speed) : null;
}
@Override
public @Nullable DecimalType getBatteryRemainingTime(int index) throws DeviceNotFoundException {
- PowerSource powerSource = (PowerSource) getDevice(powerSources, index);
+ PowerSource powerSource = getDevice(powerSources, index);
powerSource.updateAttributes();
double remainingTimeInSeconds = powerSource.getTimeRemainingEstimated();
// The getTimeRemaining() method returns (-1.0) if is calculating or (-2.0) if the time is unlimited.
@@ -347,7 +355,7 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override
public DecimalType getBatteryRemainingCapacity(int index) throws DeviceNotFoundException {
- PowerSource powerSource = (PowerSource) getDevice(powerSources, index);
+ PowerSource powerSource = getDevice(powerSources, index);
powerSource.updateAttributes();
double remainingCapacity = powerSource.getRemainingCapacityPercent();
BigDecimal remainingCapacityPercents = getPercentsValue(remainingCapacity);
@@ -356,7 +364,7 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override
public StringType getBatteryName(int index) throws DeviceNotFoundException {
- PowerSource powerSource = (PowerSource) getDevice(powerSources, index);
+ PowerSource powerSource = getDevice(powerSources, index);
String name = powerSource.getName();
return new StringType(name);
}
@@ -390,21 +398,21 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override
public StringType getDriveName(int deviceIndex) throws DeviceNotFoundException {
- HWDiskStore drive = (HWDiskStore) getDevice(drives, deviceIndex);
+ HWDiskStore drive = getDevice(drives, deviceIndex);
String name = drive.getName();
return new StringType(name);
}
@Override
public StringType getDriveModel(int deviceIndex) throws DeviceNotFoundException {
- HWDiskStore drive = (HWDiskStore) getDevice(drives, deviceIndex);
+ HWDiskStore drive = getDevice(drives, deviceIndex);
String model = drive.getModel();
return new StringType(model);
}
@Override
public StringType getDriveSerialNumber(int deviceIndex) throws DeviceNotFoundException {
- HWDiskStore drive = (HWDiskStore) getDevice(drives, deviceIndex);
+ HWDiskStore drive = getDevice(drives, deviceIndex);
String serialNumber = drive.getSerial();
return new StringType(serialNumber);
}
@@ -544,14 +552,14 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override
public StringType getNetworkMac(int networkIndex) throws DeviceNotFoundException {
- NetworkIF network = (NetworkIF) getDevice(networks, networkIndex);
+ NetworkIF network = getDevice(networks, networkIndex);
String mac = network.getMacaddr();
return new StringType(mac);
}
@Override
public DecimalType getNetworkPacketsReceived(int networkIndex) throws DeviceNotFoundException {
- NetworkIF network = (NetworkIF) getDevice(networks, networkIndex);
+ NetworkIF network = getDevice(networks, networkIndex);
network.updateAttributes();
long packRecv = network.getPacketsRecv();
return new DecimalType(packRecv);
@@ -559,7 +567,7 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override
public DecimalType getNetworkPacketsSent(int networkIndex) throws DeviceNotFoundException {
- NetworkIF network = (NetworkIF) getDevice(networks, networkIndex);
+ NetworkIF network = getDevice(networks, networkIndex);
network.updateAttributes();
long packSent = network.getPacketsSent();
return new DecimalType(packSent);
@@ -567,7 +575,7 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override
public DecimalType getNetworkDataSent(int networkIndex) throws DeviceNotFoundException {
- NetworkIF network = (NetworkIF) getDevice(networks, networkIndex);
+ NetworkIF network = getDevice(networks, networkIndex);
network.updateAttributes();
long bytesSent = network.getBytesSent();
return new DecimalType(getSizeInMB(bytesSent));
@@ -575,7 +583,7 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override
public DecimalType getNetworkDataReceived(int networkIndex) throws DeviceNotFoundException {
- NetworkIF network = (NetworkIF) getDevice(networks, networkIndex);
+ NetworkIF network = getDevice(networks, networkIndex);
network.updateAttributes();
long bytesRecv = network.getBytesRecv();
return new DecimalType(getSizeInMB(bytesRecv));
diff --git a/itests/org.openhab.binding.systeminfo.tests/itest.bndrun b/itests/org.openhab.binding.systeminfo.tests/itest.bndrun
index 20f4f3913f8..f71325316b5 100644
--- a/itests/org.openhab.binding.systeminfo.tests/itest.bndrun
+++ b/itests/org.openhab.binding.systeminfo.tests/itest.bndrun
@@ -21,8 +21,6 @@ Fragment-Host: org.openhab.binding.systeminfo
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
org.osgi.service.event;version='[1.4.0,1.4.1)',\
org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\
- com.sun.jna;version='[5.5.0,5.5.1)',\
- com.sun.jna.platform;version='[5.5.0,5.5.1)',\
org.hamcrest;version='[2.2.0,2.2.1)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
com.sun.xml.bind.jaxb-osgi;version='[2.3.3,2.3.4)',\
@@ -74,4 +72,6 @@ Fragment-Host: org.openhab.binding.systeminfo
org.eclipse.jetty.servlet;version='[9.4.43,9.4.44)',\
org.eclipse.jetty.util;version='[9.4.43,9.4.44)',\
org.eclipse.jetty.util.ajax;version='[9.4.43,9.4.44)',\
- org.ops4j.pax.logging.pax-logging-api;version='[2.0.10,2.0.11)'
+ org.ops4j.pax.logging.pax-logging-api;version='[2.0.10,2.0.11)',\
+ com.sun.jna;version='[5.9.0,5.9.1)',\
+ com.sun.jna.platform;version='[5.9.0,5.9.1)'
diff --git a/itests/org.openhab.binding.systeminfo.tests/pom.xml b/itests/org.openhab.binding.systeminfo.tests/pom.xml
index 96c5c409fae..d0a963d868b 100644
--- a/itests/org.openhab.binding.systeminfo.tests/pom.xml
+++ b/itests/org.openhab.binding.systeminfo.tests/pom.xml
@@ -23,17 +23,17 @@
net.java.dev.jna
jna-platform
- 5.5.0
+ 5.9.0
net.java.dev.jna
jna
- 5.5.0
+ 5.9.0
com.github.oshi
oshi-core
- 4.5.2
+ 5.8.2
org.slf4j