[systeminfo] Upgrade OSHI dependency for latest fixes/improvements (#11274)

Upgrades OSHI from 4.5.2 to 5.8.2.

For all OSHI fixes and improvements, see:

https://github.com/oshi/oshi/blob/master/CHANGELOG.md#580-2021-07-18-581-2021-08-22-582-2021-09-05

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2021-09-20 14:49:32 +02:00 committed by GitHub
parent 02fffccdad
commit 20f8a56560
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 49 deletions

View File

@ -22,19 +22,19 @@
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.5.0</version>
<version>5.9.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.5.0</version>
<version>5.9.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>4.5.2</version>
<version>5.8.2</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@ -4,9 +4,9 @@
<feature name="openhab-binding-systeminfo" description="System Info Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle dependency="true">mvn:net.java.dev.jna/jna/5.5.0</bundle>
<bundle dependency="true">mvn:net.java.dev.jna/jna-platform/5.5.0</bundle>
<bundle dependency="true">mvn:com.github.oshi/oshi-core/4.5.2</bundle>
<bundle dependency="true">mvn:net.java.dev.jna/jna/5.9.0</bundle>
<bundle dependency="true">mvn:net.java.dev.jna/jna-platform/5.9.0</bundle>
<bundle dependency="true">mvn:com.github.oshi/oshi-core/5.8.2</bundle>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.systeminfo/${project.version}</bundle>
</feature>
</features>

View File

@ -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<NetworkIF> networks;
private @NonNullByDefault({}) List<Display> displays;
private @NonNullByDefault({}) List<OSFileStore> fileStores;
private @NonNullByDefault({}) List<PowerSource> powerSources;
private @NonNullByDefault({}) List<HWDiskStore> 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> 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> 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));

View File

@ -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)'

View File

@ -23,17 +23,17 @@
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.5.0</version>
<version>5.9.0</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.5.0</version>
<version>5.9.0</version>
</dependency>
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>4.5.2</version>
<version>5.8.2</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>