]> git.basschouten.com Git - openhab-addons.git/commitdiff
[systeminfo] Upgrade OSHI dependency for latest fixes/improvements (#11274)
authorWouter Born <github@maindrain.net>
Mon, 20 Sep 2021 12:49:32 +0000 (14:49 +0200)
committerGitHub <noreply@github.com>
Mon, 20 Sep 2021 12:49:32 +0000 (14:49 +0200)
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>
bundles/org.openhab.binding.systeminfo/pom.xml
bundles/org.openhab.binding.systeminfo/src/main/feature/feature.xml
bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/model/OSHISysteminfo.java
itests/org.openhab.binding.systeminfo.tests/itest.bndrun
itests/org.openhab.binding.systeminfo.tests/pom.xml

index e9cea0235202a48299770f3051360215efd5a946..a9c0fffde05775dd70a77c5ec0de638c167d0bf6 100644 (file)
     <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>
index 6b8275687f5fca9c65113cd06e5eda3d6ae4ac9d..28179ca46f4d925121e4fedc2a5a12950e23bb51 100644 (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>
index 7bb4b63badced4a2b99f09813dd953fbc88a23ea..83088c1a6cf79b5f3607b8570bbe29dc5709fa2c 100644 (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));
index 20f4f3913f86754698ff0e3a054efbfde97b41e9..f71325316b548e24e12fb796feb7313930afb26d 100644 (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)'
index 96c5c409fae43581d96152a8b2e89e0358596c46..d0a963d868bc1641a175c72539c99c3633a6091d 100644 (file)
     <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>