[systeminfo] Add CPU load channel, update dependencies (#13292)

* Add CPU load channel, update dependencies
* use PercentType, correct process CPU load
* Add and fix test

Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
This commit is contained in:
Mark Herwege
2022-09-11 11:06:52 +02:00
committed by GitHub
parent 55e27c8c12
commit 909d390581
11 changed files with 97 additions and 29 deletions

View File

@@ -34,8 +34,8 @@ Fragment-Host: org.openhab.binding.systeminfo
org.jsr-305;version='[3.0.2,3.0.3)',\
tech.units.indriya;version='[2.1.2,2.1.3)',\
uom-lib-common;version='[2.1.0,2.1.1)',\
com.sun.jna;version='[5.9.0,5.9.1)',\
com.sun.jna.platform;version='[5.9.0,5.9.1)',\
com.sun.jna;version='[5.12.1,5.12.2)',\
com.sun.jna.platform;version='[5.12.1,5.12.2)',\
si-units;version='[2.1.0,2.1.1)',\
si.uom.si-quantity;version='[2.1.0,2.1.1)',\
junit-jupiter-api;version='[5.8.1,5.8.2)',\

View File

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

View File

@@ -45,6 +45,7 @@ import org.openhab.core.items.ItemRegistry;
import org.openhab.core.library.items.NumberItem;
import org.openhab.core.library.items.StringItem;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
@@ -346,6 +347,18 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
assertItemState(acceptedItemType, DEFAULT_TEST_ITEM_NAME, DEFAULT_CHANNEL_TEST_PRIORITY, UnDefType.UNDEF);
}
@Test
public void assertChannelCpuLoadIsUpdated() {
String channnelID = SysteminfoBindingConstants.CHANNEL_CPU_LOAD;
String acceptedItemType = "Number";
PercentType mockedCpuLoadValue = new PercentType(9);
when(mockedSystemInfo.getSystemCpuLoad()).thenReturn(mockedCpuLoadValue);
initializeThingWithChannel(channnelID, acceptedItemType);
assertItemState(acceptedItemType, DEFAULT_TEST_ITEM_NAME, DEFAULT_CHANNEL_TEST_PRIORITY, mockedCpuLoadValue);
}
@Test
public void assertChannelCpuLoad1IsUpdated() {
String channnelID = SysteminfoBindingConstants.CHANNEL_CPU_LOAD_1;
@@ -1007,7 +1020,7 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
// The pid of the System idle process in Windows
int pid = 0;
DecimalType mockedProcessLoad = new DecimalType(3);
PercentType mockedProcessLoad = new PercentType(3);
when(mockedSystemInfo.getProcessCpuUsage(pid)).thenReturn(mockedProcessLoad);
initializeThingWithChannelAndPID(channnelID, acceptedItemType, pid);