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:
parent
b1db199beb
commit
102d8aa266
1 changed files with 7 additions and 4 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue