[systeminfo] QuantityTypes and state descriptions cleanup (#13804)
* State descriptions cleanup * Converted channels to QuantityType, adjusted default translations * Channel definitions and percent to QuanityType * Changed default state descriptions from MB to MiB Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
This commit is contained in:
@@ -24,6 +24,10 @@ import java.net.UnknownHostException;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
import javax.measure.quantity.ElectricPotential;
|
||||
import javax.measure.quantity.Temperature;
|
||||
import javax.measure.quantity.Time;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@@ -48,11 +52,15 @@ import org.openhab.core.config.discovery.inbox.InboxPredicates;
|
||||
import org.openhab.core.items.GenericItem;
|
||||
import org.openhab.core.items.ItemNotFoundException;
|
||||
import org.openhab.core.items.ItemRegistry;
|
||||
import org.openhab.core.library.dimension.DataAmount;
|
||||
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.QuantityType;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
import org.openhab.core.library.unit.SIUnits;
|
||||
import org.openhab.core.library.unit.Units;
|
||||
import org.openhab.core.test.java.JavaOSGiTest;
|
||||
import org.openhab.core.test.storage.VolatileStorageService;
|
||||
import org.openhab.core.thing.Channel;
|
||||
@@ -314,8 +322,8 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
|
||||
private void intializeItem(ChannelUID channelUID, String itemName, String acceptedItemType) {
|
||||
GenericItem item = null;
|
||||
if ("Number".equals(acceptedItemType)) {
|
||||
item = new NumberItem(itemName);
|
||||
if (acceptedItemType.startsWith("Number")) {
|
||||
item = new NumberItem(acceptedItemType, itemName);
|
||||
} else if ("String".equals(acceptedItemType)) {
|
||||
item = new StringItem(itemName);
|
||||
}
|
||||
@@ -447,9 +455,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelCpuUptimeIsUpdated() {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_CPU_UPTIME;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:Time";
|
||||
|
||||
DecimalType mockedCpuUptimeValue = new DecimalType(100);
|
||||
QuantityType<Time> mockedCpuUptimeValue = new QuantityType<>(100, Units.MINUTE);
|
||||
when(mockedSystemInfo.getCpuUptime()).thenReturn(mockedCpuUptimeValue);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -484,9 +492,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelMemoryAvailableIsUpdated() {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_MEMORY_AVAILABLE;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:DataAmount";
|
||||
|
||||
DecimalType mockedMemoryAvailableValue = new DecimalType(1000);
|
||||
QuantityType<DataAmount> mockedMemoryAvailableValue = new QuantityType<>(1000, Units.MEBIBYTE);
|
||||
when(mockedSystemInfo.getMemoryAvailable()).thenReturn(mockedMemoryAvailableValue);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -497,9 +505,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelMemoryUsedIsUpdated() {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_MEMORY_USED;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:DataAmount";
|
||||
|
||||
DecimalType mockedMemoryUsedValue = new DecimalType(24);
|
||||
QuantityType<DataAmount> mockedMemoryUsedValue = new QuantityType<>(24, Units.MEBIBYTE);
|
||||
when(mockedSystemInfo.getMemoryUsed()).thenReturn(mockedMemoryUsedValue);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -509,9 +517,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelMemoryTotalIsUpdated() {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_MEMORY_TOTAL;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:DataAmount";
|
||||
|
||||
DecimalType mockedMemoryTotalValue = new DecimalType(1024);
|
||||
QuantityType<DataAmount> mockedMemoryTotalValue = new QuantityType<>(1024, Units.MEBIBYTE);
|
||||
when(mockedSystemInfo.getMemoryTotal()).thenReturn(mockedMemoryTotalValue);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -524,7 +532,7 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_MEMORY_AVAILABLE_PERCENT;
|
||||
String acceptedItemType = "Number";
|
||||
|
||||
DecimalType mockedMemoryAvailablePercentValue = new DecimalType(97);
|
||||
PercentType mockedMemoryAvailablePercentValue = new PercentType(97);
|
||||
when(mockedSystemInfo.getMemoryAvailablePercent()).thenReturn(mockedMemoryAvailablePercentValue);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -535,9 +543,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelSwapAvailableIsUpdated() {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_SWAP_AVAILABLE;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:DataAmount";
|
||||
|
||||
DecimalType mockedSwapAvailableValue = new DecimalType(482);
|
||||
QuantityType<DataAmount> mockedSwapAvailableValue = new QuantityType<>(482, Units.MEBIBYTE);
|
||||
when(mockedSystemInfo.getSwapAvailable()).thenReturn(mockedSwapAvailableValue);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -548,9 +556,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelSwapUsedIsUpdated() {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_SWAP_USED;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:DataAmount";
|
||||
|
||||
DecimalType mockedSwapUsedValue = new DecimalType(30);
|
||||
QuantityType<DataAmount> mockedSwapUsedValue = new QuantityType<>(30, Units.MEBIBYTE);
|
||||
when(mockedSystemInfo.getSwapUsed()).thenReturn(mockedSwapUsedValue);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -560,9 +568,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelSwapTotalIsUpdated() {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_SWAP_TOTAL;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:DataAmount";
|
||||
|
||||
DecimalType mockedSwapTotalValue = new DecimalType(512);
|
||||
QuantityType<DataAmount> mockedSwapTotalValue = new QuantityType<>(512, Units.MEBIBYTE);
|
||||
when(mockedSystemInfo.getSwapTotal()).thenReturn(mockedSwapTotalValue);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -574,7 +582,7 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_SWAP_AVAILABLE_PERCENT;
|
||||
String acceptedItemType = "Number";
|
||||
|
||||
DecimalType mockedSwapAvailablePercentValue = new DecimalType(94);
|
||||
PercentType mockedSwapAvailablePercentValue = new PercentType(94);
|
||||
when(mockedSystemInfo.getSwapAvailablePercent()).thenReturn(mockedSwapAvailablePercentValue);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -622,9 +630,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelStorageAvailableIsUpdated() throws DeviceNotFoundException {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_STORAGE_AVAILABLE;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:DataAmount";
|
||||
|
||||
DecimalType mockedStorageAvailableValue = new DecimalType(2000);
|
||||
QuantityType<DataAmount> mockedStorageAvailableValue = new QuantityType<>(2000, Units.MEBIBYTE);
|
||||
when(mockedSystemInfo.getStorageAvailable(DEFAULT_DEVICE_INDEX)).thenReturn(mockedStorageAvailableValue);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -635,9 +643,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelStorageUsedIsUpdated() throws DeviceNotFoundException {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_STORAGE_USED;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:DataAmount";
|
||||
|
||||
DecimalType mockedStorageUsedValue = new DecimalType(500);
|
||||
QuantityType<DataAmount> mockedStorageUsedValue = new QuantityType<>(500, Units.MEBIBYTE);
|
||||
when(mockedSystemInfo.getStorageUsed(DEFAULT_DEVICE_INDEX)).thenReturn(mockedStorageUsedValue);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -648,9 +656,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelStorageTotalIsUpdated() throws DeviceNotFoundException {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_STORAGE_TOTAL;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:DataAmount";
|
||||
|
||||
DecimalType mockedStorageTotalValue = new DecimalType(2500);
|
||||
QuantityType<DataAmount> mockedStorageTotalValue = new QuantityType<>(2500, Units.MEBIBYTE);
|
||||
when(mockedSystemInfo.getStorageTotal(DEFAULT_DEVICE_INDEX)).thenReturn(mockedStorageTotalValue);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -663,7 +671,7 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_STORAGE_AVAILABLE_PERCENT;
|
||||
String acceptedItemType = "Number";
|
||||
|
||||
DecimalType mockedStorageAvailablePercent = new DecimalType(20);
|
||||
PercentType mockedStorageAvailablePercent = new PercentType(20);
|
||||
when(mockedSystemInfo.getStorageAvailablePercent(DEFAULT_DEVICE_INDEX))
|
||||
.thenReturn(mockedStorageAvailablePercent);
|
||||
|
||||
@@ -714,9 +722,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelSensorsCpuTempIsUpdated() {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_SENSORS_CPU_TEMPERATURE;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:Temperature";
|
||||
|
||||
DecimalType mockedSensorsCpuTemperatureValue = new DecimalType(60);
|
||||
QuantityType<Temperature> mockedSensorsCpuTemperatureValue = new QuantityType<>(60, SIUnits.CELSIUS);
|
||||
when(mockedSystemInfo.getSensorsCpuTemperature()).thenReturn(mockedSensorsCpuTemperatureValue);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -727,9 +735,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelSensorsCpuVoltageIsUpdated() {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_SENOSRS_CPU_VOLTAGE;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:ElectricPotential";
|
||||
|
||||
DecimalType mockedSensorsCpuVoltageValue = new DecimalType(1000);
|
||||
QuantityType<ElectricPotential> mockedSensorsCpuVoltageValue = new QuantityType<>(1000, Units.VOLT);
|
||||
when(mockedSystemInfo.getSensorsCpuVoltage()).thenReturn(mockedSensorsCpuVoltageValue);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -767,7 +775,7 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_BATTERY_REMAINING_CAPACITY;
|
||||
String acceptedItemType = "Number";
|
||||
|
||||
DecimalType mockedBatteryRemainingCapacity = new DecimalType(200);
|
||||
PercentType mockedBatteryRemainingCapacity = new PercentType(20);
|
||||
when(mockedSystemInfo.getBatteryRemainingCapacity(DEFAULT_DEVICE_INDEX))
|
||||
.thenReturn(mockedBatteryRemainingCapacity);
|
||||
|
||||
@@ -779,9 +787,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelBatteryRemainingTimeIsUpdated() throws DeviceNotFoundException {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_BATTERY_REMAINING_TIME;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:Time";
|
||||
|
||||
DecimalType mockedBatteryRemainingTime = new DecimalType(3600);
|
||||
QuantityType<Time> mockedBatteryRemainingTime = new QuantityType<>(3600, Units.MINUTE);
|
||||
when(mockedSystemInfo.getBatteryRemainingTime(DEFAULT_DEVICE_INDEX)).thenReturn(mockedBatteryRemainingTime);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -828,9 +836,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelNetworkDataSentIsUpdated() throws DeviceNotFoundException {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_NETWORK_DATA_SENT;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:DataAmount";
|
||||
|
||||
DecimalType mockedNetworkDataSent = new DecimalType(1000);
|
||||
QuantityType<DataAmount> mockedNetworkDataSent = new QuantityType<>(1000, Units.MEBIBYTE);
|
||||
when(mockedSystemInfo.getNetworkDataSent(DEFAULT_DEVICE_INDEX)).thenReturn(mockedNetworkDataSent);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -840,9 +848,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelNetworkDataReceivedIsUpdated() throws DeviceNotFoundException {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_NETWORK_DATA_RECEIVED;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:DataAmount";
|
||||
|
||||
DecimalType mockedNetworkDataReceiveed = new DecimalType(800);
|
||||
QuantityType<DataAmount> mockedNetworkDataReceiveed = new QuantityType<>(800, Units.MEBIBYTE);
|
||||
when(mockedSystemInfo.getNetworkDataReceived(DEFAULT_DEVICE_INDEX)).thenReturn(mockedNetworkDataReceiveed);
|
||||
|
||||
initializeThingWithChannel(channnelID, acceptedItemType);
|
||||
@@ -1048,11 +1056,11 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
|
||||
@Test
|
||||
public void assertChannelProcessMemoryIsUpdatedWithPIDset() throws DeviceNotFoundException {
|
||||
String channnelID = SysteminfoBindingConstants.CHANNEL_PROCESS_MEMORY;
|
||||
String acceptedItemType = "Number";
|
||||
String acceptedItemType = "Number:DataAmount";
|
||||
// The pid of the System idle process in Windows
|
||||
int pid = 0;
|
||||
|
||||
DecimalType mockedProcessMemory = new DecimalType(450);
|
||||
QuantityType<DataAmount> mockedProcessMemory = new QuantityType<>(450, Units.MEBIBYTE);
|
||||
when(mockedSystemInfo.getProcessMemoryUsage(pid)).thenReturn(mockedProcessMemory);
|
||||
|
||||
initializeThingWithChannelAndPID(channnelID, acceptedItemType, pid);
|
||||
|
||||
Reference in New Issue
Block a user