This commit is contained in:
Ziver Koc 2016-05-25 20:30:40 +02:00
parent 7109abeea2
commit 17e50573d6
6 changed files with 36 additions and 17 deletions

View file

@ -113,11 +113,13 @@
// Set dynamic data
modal.find("select[name=type]").val(button.data("type"));
modal.find("select[name=type]").change(); // Update dynamic inputs
$.each(button.attr(), function(name, value) {
if(name.startsWith("data-")) {
name = name.substring(5);
console.log(name, value);
modal.find("input[name="+name+"]").val(value);
$.each(button.attr(), function(fieldName, value) {
if(fieldName.startsWith("data-")) {
fieldName = fieldName.substring(5);
// case insensitive search
modal.find("input").filter(function() {
return this.name.toLowerCase() == fieldName;
}).val(value);
}
});
});

View file

@ -28,6 +28,7 @@ $(function(){
};
})($.fn.attr);
// converts all timestamps to human readable time and date
$.fn.relTimestamp = function() {
return this.each(function() {
var timestamp = parseInt($(this).text());

View file

@ -215,11 +215,14 @@
// set dynamic form data
modal.find("select[name=type]").val(button.data("type"));
modal.find("select[name=type]").change(); // Update dynamic inputs
$.each(button.attr(), function(name, value) {
if(name.startsWith("data-")) {
name = name.substring(5);
console.log(name, value);
modal.find("input[name="+name+"]").val(value);
$.each(button.attr(), function(fieldName, value) {
if(fieldName.startsWith("data-")) {
fieldName = fieldName.substring(5);
console.log(fieldName, value);
// case insensitive search
modal.find("input").filter(function() {
return this.name.toLowerCase() == fieldName;
}).val(value);
}
});
});

View file

@ -115,7 +115,8 @@ public class ControllerManager implements HalSensorReportListener,
db.exec(stmt);
}
else { // unknown sensor
logger.finest("Received report from unregistered sensor: "+ sensorData);
logger.finest("Received report from unregistered sensor" +
"("+sensorData.getClass().getSimpleName()+"): "+ sensorData);
sensor = findSensor(sensorData, detectedSensors);
if(sensor == null) {
sensor = new Sensor();
@ -200,7 +201,8 @@ public class ControllerManager implements HalSensorReportListener,
db.exec(stmt);
}
else { // unknown sensor
logger.info("Received report from unregistered event: "+ eventData);
logger.info("Received report from unregistered event" +
"("+eventData.getClass().getSimpleName()+"): "+ eventData);
event = findEvent(eventData, detectedEvents);
if(event == null) {
event = new Event();

View file

@ -5,16 +5,20 @@ import se.hal.intf.HalAutoScannableController;
import se.hal.intf.HalSensorController;
import se.hal.intf.HalSensorData;
import se.hal.intf.HalSensorReportListener;
import zutil.log.LogUtil;
import zutil.osal.app.linux.NutUPSClient;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Created by Ziver on 2016-05-25.
*/
public class NutUpsController implements HalSensorController, HalAutoScannableController, Runnable{
public static Logger logger = LogUtil.getLogger();
private static final int SYNC_INTERVAL = 60 * 1000;
private NutUPSClient client;
@ -49,10 +53,14 @@ public class NutUpsController implements HalSensorController, HalAutoScannableCo
@Override
public void run() {
if(client != null && listener != null){
for (NutUPSClient.UPSDevice ups : client.getUPSList()){
listener.reportReceived(new NutUpsDevice(ups));
try {
if (client != null && listener != null) {
for (NutUPSClient.UPSDevice ups : client.getUPSList()) {
listener.reportReceived(new NutUpsDevice(ups));
}
}
} catch (Exception e){
logger.log(Level.SEVERE, "NutUps thread crashed", e);
}
}

View file

@ -43,11 +43,14 @@ public class NutUpsDevice implements PowerConsumptionSensorData{
return false;
}
public String toString(){
return "id: "+deviceId +
", consumption: "+consumption;
}
@Override
public AggregationMethod getAggregationMethod() {
return AggregationMethod.SUM;
return AggregationMethod.AVERAGE;
}
@Override
public Class<? extends HalSensorController> getSensorController() {