Implemented loading and saving Events and Sensors
Former-commit-id: 26ce2c437dd31a0236f6e13f1dff0709ed6a4966
This commit is contained in:
parent
588ac41956
commit
27c5204ec1
6 changed files with 86 additions and 11 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package se.koc.hal.intf;
|
||||
|
||||
import zutil.parser.DataNode;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-12-23.
|
||||
*/
|
||||
|
|
@ -7,5 +9,4 @@ public interface HalEvent {
|
|||
|
||||
public Class<? extends HalEventController> getController();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package se.koc.hal.intf;
|
||||
|
||||
import zutil.parser.DataNode;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-12-23.
|
||||
*/
|
||||
|
|
@ -10,9 +12,10 @@ public interface HalSensor {
|
|||
}
|
||||
|
||||
|
||||
public AggregationMethod getAggregationMethod();
|
||||
|
||||
public Class<? extends HalSensorController> getController();
|
||||
AggregationMethod getAggregationMethod();
|
||||
|
||||
Class<? extends HalSensorController> getController();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,14 +23,20 @@
|
|||
package se.koc.hal.plugin.tellstick.protocols;
|
||||
|
||||
import se.koc.hal.plugin.tellstick.TellstickProtocol;
|
||||
import zutil.ui.Configurator;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-02-18.
|
||||
*/
|
||||
public class NexaSelfLearning implements TellstickProtocol {
|
||||
|
||||
@Configurator.Configurable("House code")
|
||||
private int house = 0;
|
||||
@Configurator.Configurable("Group code")
|
||||
private int group = 0;
|
||||
@Configurator.Configurable("Unit code")
|
||||
private int unit = 0;
|
||||
|
||||
private boolean enable = false;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,14 +5,19 @@ import se.koc.hal.intf.HalSensorController;
|
|||
import se.koc.hal.plugin.tellstick.TellstickProtocol;
|
||||
import se.koc.hal.plugin.tellstick.TellstickSerialComm;
|
||||
import se.koc.hal.struct.PowerConsumptionSensor;
|
||||
import zutil.parser.DataNode;
|
||||
import zutil.ui.Configurator;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-11-19.
|
||||
*/
|
||||
public class Oregon0x1A2D implements TellstickProtocol, PowerConsumptionSensor {
|
||||
|
||||
double temperature = 0;
|
||||
double humidity = 0;
|
||||
@Configurator.Configurable("Address")
|
||||
private int address = 0;
|
||||
|
||||
private double temperature = 0;
|
||||
private double humidity = 0;
|
||||
|
||||
@Override
|
||||
public String encode() {
|
||||
|
|
@ -42,7 +47,7 @@ public class Oregon0x1A2D implements TellstickProtocol, PowerConsumptionSensor {
|
|||
int temp3 = (data[5] >> 4) & 0xF;
|
||||
|
||||
checksum += ((data[6] >> 4) & 0xF) + (data[6] & 0xF);
|
||||
int address = data[6] & 0xFF;
|
||||
address = data[6] & 0xFF;
|
||||
|
||||
checksum += ((data[7] >> 4) & 0xF) + (data[7] & 0xF);
|
||||
// channel not used
|
||||
|
|
|
|||
|
|
@ -5,8 +5,15 @@ import se.koc.hal.intf.HalEventController;
|
|||
import zutil.db.DBConnection;
|
||||
import zutil.db.bean.DBBean;
|
||||
import zutil.db.bean.DBBeanSQLResultHandler;
|
||||
import zutil.io.StringInputStream;
|
||||
import zutil.io.StringOutputStream;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.parser.json.JSONObjectInputStream;
|
||||
import zutil.parser.json.JSONObjectOutputStream;
|
||||
import zutil.parser.json.JSONParser;
|
||||
import zutil.parser.json.JSONWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
|
@ -41,13 +48,34 @@ public class Event extends DBBean{
|
|||
if(eventData == null) {
|
||||
try {
|
||||
Class c = Class.forName(type);
|
||||
eventData = (HalEvent) c.newInstance();
|
||||
|
||||
JSONObjectInputStream in = new JSONObjectInputStream(
|
||||
new StringInputStream(config));
|
||||
eventData = (HalEvent) in.readObject(c);
|
||||
in.close();
|
||||
} catch (Exception e){
|
||||
logger.log(Level.SEVERE, null, e);
|
||||
logger.log(Level.SEVERE, "Unable to read event data", e);
|
||||
}
|
||||
}
|
||||
return eventData;
|
||||
}
|
||||
public void save(DBConnection db) throws SQLException {
|
||||
if(eventData != null) {
|
||||
try {
|
||||
StringOutputStream buff = new StringOutputStream();
|
||||
JSONObjectOutputStream out = new JSONObjectOutputStream(buff);
|
||||
out.enableMetaData(false);
|
||||
out.writeObject(eventData);
|
||||
out.close();
|
||||
this.config = buff.toString();
|
||||
} catch (IOException e){
|
||||
logger.log(Level.SEVERE, "Unable to save event data", e);
|
||||
}
|
||||
}
|
||||
else
|
||||
this.config = null;
|
||||
super.save(db);
|
||||
}
|
||||
|
||||
|
||||
public Class<? extends HalEventController> getController(){
|
||||
|
|
|
|||
|
|
@ -1,21 +1,31 @@
|
|||
package se.koc.hal.struct;
|
||||
|
||||
import se.koc.hal.HalContext;
|
||||
import se.koc.hal.intf.HalEvent;
|
||||
import se.koc.hal.intf.HalSensor;
|
||||
import se.koc.hal.intf.HalSensorController;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.db.bean.DBBean;
|
||||
import zutil.db.bean.DBBeanSQLResultHandler;
|
||||
import zutil.db.handler.SimpleSQLResult;
|
||||
import zutil.io.StringInputStream;
|
||||
import zutil.io.StringOutputStream;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.parser.DataNode;
|
||||
import zutil.parser.json.JSONObjectInputStream;
|
||||
import zutil.parser.json.JSONObjectOutputStream;
|
||||
import zutil.parser.json.JSONParser;
|
||||
import zutil.parser.json.JSONWriter;
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.Configurator.ConfigurationParam;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
@DBBean.DBTable("sensor")
|
||||
public class Sensor extends DBBean{
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
|
@ -73,13 +83,35 @@ public class Sensor extends DBBean{
|
|||
if(sensorData == null) {
|
||||
try {
|
||||
Class c = Class.forName(type);
|
||||
sensorData = (HalSensor) c.newInstance();
|
||||
|
||||
JSONObjectInputStream in = new JSONObjectInputStream(
|
||||
new StringInputStream(config));
|
||||
sensorData = (HalSensor) in.readObject(c);
|
||||
in.close();
|
||||
} catch (Exception e){
|
||||
logger.log(Level.SEVERE, null, e);
|
||||
logger.log(Level.SEVERE, "Unable to read sensor data", e);
|
||||
}
|
||||
}
|
||||
return sensorData;
|
||||
}
|
||||
public void save(DBConnection db) throws SQLException {
|
||||
if(sensorData != null) {
|
||||
try {
|
||||
StringOutputStream buff = new StringOutputStream();
|
||||
JSONObjectOutputStream out = new JSONObjectOutputStream(buff);
|
||||
out.enableMetaData(false);
|
||||
out.writeObject(sensorData);
|
||||
out.close();
|
||||
this.config = buff.toString();
|
||||
} catch (IOException e){
|
||||
logger.log(Level.SEVERE, "Unable to save sensor data", e);
|
||||
}
|
||||
}
|
||||
else
|
||||
this.config = null;
|
||||
super.save(db);
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue