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; return null;
} }
@SuppressWarnings("unchecked")
public C getDeviceConfig() { public C getDeviceConfig() {
if (deviceConfig == null || !deviceConfig.getClass().getName().equals(type)) { if (deviceConfig == null || !deviceConfig.getClass().getName().equals(type)) {
try { try {
Class c = Class.forName(type); Class clazz = Class.forName(type);
deviceConfig = (C) c.newInstance(); deviceConfig = (C) clazz.getDeclaredConstructor().newInstance();
applyConfig(); applyConfig();
deviceData = getLatestDeviceData(HalContext.getDB()); 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 * @return the latest known data from the device
*/ */
public D getDeviceData() { public D getDeviceData() {
if (deviceData == null)
deviceData = getLatestDeviceData(HalContext.getDB());
return deviceData; return deviceData;
} }
public void setDeviceData(D latest) { public void setDeviceData(D deviceData) {
this.deviceData = latest; this.deviceData = deviceData;
} }
/** /**