Added enum configuration to Oregon and updated configuration pages to show new device structure correctly

This commit is contained in:
Ziver Koc 2016-08-24 17:26:36 +02:00
parent 95240dd392
commit c50e50305f
5 changed files with 84 additions and 20 deletions

View file

@ -22,7 +22,7 @@
<tr> <tr>
<td>{{.getName()}}</td> <td>{{.getName()}}</td>
<td>{{.getType()}}</td> <td>{{.getType()}}</td>
<td>{{.getDeviceData()}}</td> <td>{{.getDeviceConfig()}}</td>
<td> <td>
<form method="POST"> <form method="POST">
<input type="hidden" name="action" value="remove_local_event"> <input type="hidden" name="action" value="remove_local_event">
@ -57,13 +57,15 @@
<thead> <thead>
<th>Type</th> <th>Type</th>
<th>Date</th> <th>Date</th>
<th>Data</th>
<th>Configuration</th> <th>Configuration</th>
</thead> </thead>
{{#detectedEvents}} {{#detectedEvents}}
<tr> <tr>
<td>{{.getType()}}</td> <td>{{.getType()}}</td>
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td> <td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
<td>{{.getDeviceData()}}</td> <td>{{.getDeviceData()}}</span></td>
<td>{{.getDeviceConfig()}}</td>
<td> <td>
<div class="btn-toolbar pull-right"> <div class="btn-toolbar pull-right">
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" <button type="button" class="btn btn-default btn-xs" data-toggle="modal"
@ -172,7 +174,14 @@
{{#.params}} {{#.params}}
<div class="form-group"> <div class="form-group">
<label class="control-label">{{.getNiceName()}}:</label> <label class="control-label">{{.getNiceName()}}:</label>
<input type="text" class="form-control" name="{{.getName()}}"> {{#.isTypeString()}}<input type="text" class="form-control" name="{{.getName()}}">{{/#.isTypeString()}}
{{#.isTypeInt()}}<input type="number" class="form-control" name="{{.getName()}}">{{/#.isTypeInt()}}
{{#.isTypeBoolean()}}<input type="checkbox" name="{{.getName()}}">{{/#.isTypeBoolean()}}
{{#.isTypeEnum()}}
<select class="form-control" name="{{.getName()}}">
{{#.getPossibleValues()}}<option>{{.}}</option>{{/.getPossibleValues()}}
</select>
{{/#.isTypeEnum()}}
</div> </div>
{{/.params}} {{/.params}}
</div> </div>

View file

@ -24,7 +24,7 @@
<td>{{.getName()}}</td> <td>{{.getName()}}</td>
<td>{{.getType()}}</td> <td>{{.getType()}}</td>
<td>{{.isSynced()}}</td> <td>{{.isSynced()}}</td>
<td>{{.getDeviceData()}}</td> <td>{{.getDeviceConfig()}}</td>
<td> <td>
<form method="POST"> <form method="POST">
<input type="hidden" name="action" value="remove_local_sensor"> <input type="hidden" name="action" value="remove_local_sensor">
@ -60,13 +60,15 @@
<thead> <thead>
<th>Type</th> <th>Type</th>
<th>Date</th> <th>Date</th>
<th>Data</th>
<th>Configuration</th> <th>Configuration</th>
</thead> </thead>
{{#detectedSensors}} {{#detectedSensors}}
<tr> <tr>
<td>{{.getType()}}</td> <td>{{.getType()}}</td>
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td> <td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
<td>{{.getDeviceData()}}</td> <td>{{.getDeviceData()}}</span></td>
<td>{{.getDeviceConfig()}}</td>
<td> <td>
<div class="btn-toolbar pull-right"> <div class="btn-toolbar pull-right">
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" <button type="button" class="btn btn-default btn-xs" data-toggle="modal"
@ -156,7 +158,7 @@
<tr> <tr>
<td>{{.getName()}}</td> <td>{{.getName()}}</td>
<td>{{.getType()}}</td> <td>{{.getType()}}</td>
<td>{{.getDeviceData()}}</td> <td>{{.getDeviceConfig()}}</td>
<td> <td>
<form method="POST"> <form method="POST">
<div class="btn-toolbar pull-right"> <div class="btn-toolbar pull-right">
@ -299,7 +301,14 @@
{{#.params}} {{#.params}}
<div class="form-group"> <div class="form-group">
<label class="control-label">{{.getNiceName()}}:</label> <label class="control-label">{{.getNiceName()}}:</label>
<input type="text" class="form-control" name="{{.getName()}}"> {{#.isTypeString()}}<input type="text" class="form-control" name="{{.getName()}}">{{/#.isTypeString()}}
{{#.isTypeInt()}}<input type="number" class="form-control" name="{{.getName()}}">{{/#.isTypeInt()}}
{{#.isTypeBoolean()}}<input type="checkbox" name="{{.getName()}}">{{/#.isTypeBoolean()}}
{{#.isTypeEnum()}}
<select class="form-control" name="{{.getName()}}">
{{#.getPossibleValues()}}<option>{{.}}</option>{{/.getPossibleValues()}}
</select>
{{/#.isTypeEnum()}}
</div> </div>
{{/.params}} {{/.params}}
</div> </div>

View file

@ -1,14 +1,15 @@
package se.hal.plugin.tellstick.device; package se.hal.plugin.tellstick.device;
import se.hal.intf.HalEventController;
import se.hal.intf.HalSensorConfig; import se.hal.intf.HalSensorConfig;
import se.hal.intf.HalSensorController; import se.hal.intf.HalSensorController;
import se.hal.intf.HalSensorData; import se.hal.intf.HalSensorData;
import se.hal.plugin.tellstick.TellstickDevice; import se.hal.plugin.tellstick.TellstickDevice;
import se.hal.plugin.tellstick.TellstickProtocol;
import se.hal.plugin.tellstick.TellstickSerialComm; import se.hal.plugin.tellstick.TellstickSerialComm;
import se.hal.plugin.tellstick.protocol.Oregon0x1A2DProtocol; import se.hal.plugin.tellstick.protocol.Oregon0x1A2DProtocol;
import se.hal.struct.devicedata.HumiditySensorData;
import se.hal.struct.devicedata.LightSensorData;
import se.hal.struct.devicedata.PowerConsumptionSensorData; import se.hal.struct.devicedata.PowerConsumptionSensorData;
import se.hal.struct.devicedata.TemperatureSensorData;
import zutil.log.LogUtil; import zutil.log.LogUtil;
import zutil.ui.Configurator; import zutil.ui.Configurator;
@ -20,11 +21,16 @@ import java.util.logging.Logger;
public class Oregon0x1A2D implements HalSensorConfig,TellstickDevice { public class Oregon0x1A2D implements HalSensorConfig,TellstickDevice {
private static final Logger logger = LogUtil.getLogger(); private static final Logger logger = LogUtil.getLogger();
public enum OregonSensorType{
HUMIDITY,LIGHT,POWER,TEMPERATURE
}
@Configurator.Configurable("Address") @Configurator.Configurable("Address")
private int address = 0; private int address = 0;
@Configurator.Configurable("Report Interval(ms)") @Configurator.Configurable("Report Interval(ms)")
private int interval = 60*1000; // default 1 min private int interval = 60*1000; // default 1 min
@Configurator.Configurable("Sensor Type")
private OregonSensorType sensorType;
public Oregon0x1A2D() { } public Oregon0x1A2D() { }
@ -37,11 +43,12 @@ public class Oregon0x1A2D implements HalSensorConfig,TellstickDevice {
public boolean equals(Object obj){ public boolean equals(Object obj){
if(! (obj instanceof Oregon0x1A2D)) if(! (obj instanceof Oregon0x1A2D))
return false; return false;
return ((Oregon0x1A2D)obj).address == this.address; return ((Oregon0x1A2D)obj).address == this.address &&
((Oregon0x1A2D)obj).sensorType == this.sensorType;
} }
public String toString(){ public String toString(){
return "address:"+address; return "address:"+address+",sensorType:"+ sensorType;
} }
@ -53,7 +60,9 @@ public class Oregon0x1A2D implements HalSensorConfig,TellstickDevice {
@Override @Override
public AggregationMethod getAggregationMethod() { public AggregationMethod getAggregationMethod() {
return AggregationMethod.SUM; if (sensorType == OregonSensorType.POWER)
return AggregationMethod.SUM;
return AggregationMethod.AVERAGE;
} }
@Override @Override
@ -63,7 +72,13 @@ public class Oregon0x1A2D implements HalSensorConfig,TellstickDevice {
@Override @Override
public Class<? extends HalSensorData> getSensorDataClass() { public Class<? extends HalSensorData> getSensorDataClass() {
return PowerConsumptionSensorData.class; // TODO: needs to support all data, add enum? switch (sensorType){
case HUMIDITY: return HumiditySensorData.class;
case LIGHT: return LightSensorData.class;
case POWER: return PowerConsumptionSensorData.class;
case TEMPERATURE: return TemperatureSensorData.class;
}
return null;
} }
@Override @Override

View file

@ -0,0 +1,34 @@
package se.hal.struct.devicedata;
import se.hal.intf.HalSensorData;
/**
* Created by Ziver on 2015-12-03.
*/
public class LightSensorData extends HalSensorData {
private double lux;
public LightSensorData(){}
public LightSensorData(double lux){
this.lux = lux;
}
/**
* @return the light intensity in lux
*/
@Override
public double getData() {
return lux;
}
/**
* @param lux set the light intensity in lux
*/
@Override
public void setData(double lux) {
this.lux = lux;
}
}

View file

@ -19,12 +19,6 @@ public class TemperatureSensorData extends HalSensorData {
super.setTimestamp(timestamp); super.setTimestamp(timestamp);
} }
/**
* @param data the temperature to set in degrees C
*/
public void setTemperature(double data){
this.temperature = data;
}
/** /**
* @return temperature in degrees C * @return temperature in degrees C
@ -33,6 +27,9 @@ public class TemperatureSensorData extends HalSensorData {
public double getData() { public double getData() {
return temperature; return temperature;
} }
/**
* @param temperature the temperature to set in degrees C
*/
@Override @Override
public void setData(double temperature) { public void setData(double temperature) {
this.temperature = temperature; this.temperature = temperature;