Updated so that if a device data is not set then the latest one will be loaded from the DB

This commit is contained in:
Ziver Koc 2021-08-30 01:39:29 +02:00
parent b1db199beb
commit 102d8aa266

View file

@ -65,11 +65,12 @@ public abstract class HalAbstractDevice<V extends HalAbstractDevice, C extends H
}
return null;
}
@SuppressWarnings("unchecked")
public C getDeviceConfig() {
if (deviceConfig == null || !deviceConfig.getClass().getName().equals(type)) {
try {
Class c = Class.forName(type);
deviceConfig = (C) c.newInstance();
Class clazz = Class.forName(type);
deviceConfig = (C) clazz.getDeclaredConstructor().newInstance();
applyConfig();
deviceData = getLatestDeviceData(HalContext.getDB());
@ -140,11 +141,13 @@ public abstract class HalAbstractDevice<V extends HalAbstractDevice, C extends H
* @return the latest known data from the device
*/
public D getDeviceData() {
if (deviceData == null)
deviceData = getLatestDeviceData(HalContext.getDB());
return deviceData;
}
public void setDeviceData(D latest) {
this.deviceData = latest;
public void setDeviceData(D deviceData) {
this.deviceData = deviceData;
}
/**