AbstractDevice was not loading latest DeviceData at startup
This commit is contained in:
parent
3cb72a1d17
commit
889f9fc85f
4 changed files with 15 additions and 15 deletions
|
|
@ -51,7 +51,7 @@ based on Christopher Laws, March, 2013 code.
|
|||
|
||||
void SensorBH1750::setup() {
|
||||
Wire.begin();
|
||||
configure(BH1750_ONE_TIME_HIGH_RES_MODE);
|
||||
//configure(BH1750_ONE_TIME_HIGH_RES_MODE);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -78,11 +78,11 @@ void SensorBH1750::configure(uint8_t mode) {
|
|||
|
||||
|
||||
void SensorBH1750::read(LightData& data) {
|
||||
uint16_t level;
|
||||
configure(BH1750_ONE_TIME_HIGH_RES_MODE);
|
||||
|
||||
Wire.beginTransmission(BH1750_I2CADDR);
|
||||
Wire.requestFrom(BH1750_I2CADDR, 2);
|
||||
level = Wire.read();
|
||||
uint16_t level = Wire.read();
|
||||
level <<= 8;
|
||||
level |= Wire.read();
|
||||
Wire.endTransmission();
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
{{#events}}
|
||||
<tr>
|
||||
<td><a href="?id={{.getId()}}">{{.getName()}}</a></td>
|
||||
<td>{{.getDeviceData().getClass().getSimpleName()}}</td>
|
||||
<td>{{.getDeviceConfig().getClass().getSimpleName()}}</td>
|
||||
<td>{{.getDeviceData()}}</td>
|
||||
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
|
||||
<td>
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
{{#sensors}}
|
||||
<tr>
|
||||
<td><a href="?id={{.getId()}}">{{.getName()}}</a></td>
|
||||
<td>{{.getDeviceData().getClass().getSimpleName()}}</td>
|
||||
<td>{{.getDeviceConfig().getClass().getSimpleName()}}</td>
|
||||
<td>{{.getDeviceData()}}</td>
|
||||
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
|
||||
</tr>
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ public abstract class AbstractDevice<T,D> extends DBBean {
|
|||
deviceConfig = (T) c.newInstance();
|
||||
|
||||
applyConfig();
|
||||
deviceData = getLatestDeviceData(HalContext.getDB());
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "Unable instantiate DeviceConfig: "+type, e);
|
||||
}
|
||||
|
|
@ -95,7 +96,7 @@ public abstract class AbstractDevice<T,D> extends DBBean {
|
|||
/**
|
||||
* Will update the config String that will be stored in DB.
|
||||
*/
|
||||
protected void updateConfigString() {
|
||||
private void updateConfigString() {
|
||||
Configurator<T> configurator = getDeviceConfigurator();
|
||||
this.config = JSONWriter.toString(configurator.getValuesAsNode());
|
||||
}
|
||||
|
|
@ -103,7 +104,7 @@ public abstract class AbstractDevice<T,D> extends DBBean {
|
|||
* This method will configure the current DeviceData with the
|
||||
* configuration from the config String.
|
||||
*/
|
||||
protected void applyConfig(){
|
||||
private void applyConfig(){
|
||||
if (config != null && !config.isEmpty()) {
|
||||
Configurator<T> configurator = getDeviceConfigurator();
|
||||
configurator.setValues(JSONParser.read(config));
|
||||
|
|
@ -153,9 +154,8 @@ public abstract class AbstractDevice<T,D> extends DBBean {
|
|||
*/
|
||||
public void setType(String type) {
|
||||
if (this.type == null || !this.type.equals(type)) {
|
||||
setDeviceConfig(null); // reset
|
||||
this.type = type;
|
||||
this.config = null;
|
||||
this.deviceConfig = null; // invalidate current sensor data object
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue