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() {
|
void SensorBH1750::setup() {
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
configure(BH1750_ONE_TIME_HIGH_RES_MODE);
|
//configure(BH1750_ONE_TIME_HIGH_RES_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -78,15 +78,15 @@ void SensorBH1750::configure(uint8_t mode) {
|
||||||
|
|
||||||
|
|
||||||
void SensorBH1750::read(LightData& data) {
|
void SensorBH1750::read(LightData& data) {
|
||||||
uint16_t level;
|
configure(BH1750_ONE_TIME_HIGH_RES_MODE);
|
||||||
|
|
||||||
Wire.beginTransmission(BH1750_I2CADDR);
|
Wire.beginTransmission(BH1750_I2CADDR);
|
||||||
Wire.requestFrom(BH1750_I2CADDR, 2);
|
Wire.requestFrom(BH1750_I2CADDR, 2);
|
||||||
level = Wire.read();
|
uint16_t level = Wire.read();
|
||||||
level <<= 8;
|
level <<= 8;
|
||||||
level |= Wire.read();
|
level |= Wire.read();
|
||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
|
|
||||||
data.lumen = level/1.2; // convert to lux
|
data.lumen = level/1.2; // convert to lux
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
{{#events}}
|
{{#events}}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="?id={{.getId()}}">{{.getName()}}</a></td>
|
<td><a href="?id={{.getId()}}">{{.getName()}}</a></td>
|
||||||
<td>{{.getDeviceData().getClass().getSimpleName()}}</td>
|
<td>{{.getDeviceConfig().getClass().getSimpleName()}}</td>
|
||||||
<td>{{.getDeviceData()}}</td>
|
<td>{{.getDeviceData()}}</td>
|
||||||
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
|
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
|
||||||
<td>
|
<td>
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
{{#sensors}}
|
{{#sensors}}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="?id={{.getId()}}">{{.getName()}}</a></td>
|
<td><a href="?id={{.getId()}}">{{.getName()}}</a></td>
|
||||||
<td>{{.getDeviceData().getClass().getSimpleName()}}</td>
|
<td>{{.getDeviceConfig().getClass().getSimpleName()}}</td>
|
||||||
<td>{{.getDeviceData()}}</td>
|
<td>{{.getDeviceData()}}</td>
|
||||||
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
|
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ public abstract class AbstractDevice<T,D> extends DBBean {
|
||||||
deviceConfig = (T) c.newInstance();
|
deviceConfig = (T) c.newInstance();
|
||||||
|
|
||||||
applyConfig();
|
applyConfig();
|
||||||
|
deviceData = getLatestDeviceData(HalContext.getDB());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(Level.SEVERE, "Unable instantiate DeviceConfig: "+type, 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.
|
* Will update the config String that will be stored in DB.
|
||||||
*/
|
*/
|
||||||
protected void updateConfigString() {
|
private void updateConfigString() {
|
||||||
Configurator<T> configurator = getDeviceConfigurator();
|
Configurator<T> configurator = getDeviceConfigurator();
|
||||||
this.config = JSONWriter.toString(configurator.getValuesAsNode());
|
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
|
* This method will configure the current DeviceData with the
|
||||||
* configuration from the config String.
|
* configuration from the config String.
|
||||||
*/
|
*/
|
||||||
protected void applyConfig(){
|
private void applyConfig(){
|
||||||
if (config != null && !config.isEmpty()) {
|
if (config != null && !config.isEmpty()) {
|
||||||
Configurator<T> configurator = getDeviceConfigurator();
|
Configurator<T> configurator = getDeviceConfigurator();
|
||||||
configurator.setValues(JSONParser.read(config));
|
configurator.setValues(JSONParser.read(config));
|
||||||
|
|
@ -153,9 +154,8 @@ public abstract class AbstractDevice<T,D> extends DBBean {
|
||||||
*/
|
*/
|
||||||
public void setType(String type) {
|
public void setType(String type) {
|
||||||
if (this.type == null || !this.type.equals(type)) {
|
if (this.type == null || !this.type.equals(type)) {
|
||||||
|
setDeviceConfig(null); // reset
|
||||||
this.type = type;
|
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