Rename HalEvent and HalSensor to HalEventData and HalSensorData

Former-commit-id: 2dac97a3080245639b43d290aa4e94127cb1bdd4
This commit is contained in:
Ziver Koc 2016-01-15 10:15:10 +01:00
parent 92e90c5eef
commit cc6da8fccf
26 changed files with 71 additions and 95 deletions

View file

@ -30,7 +30,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
/** List of all registered sensors **/
private ArrayList<Sensor> registeredSensors = new ArrayList<>();
/** List of auto detected sensors **/
private ArrayList<HalSensor> detectedSensors = new ArrayList<>();
private ArrayList<HalSensorData> detectedSensors = new ArrayList<>();
/** All available event plugins **/
@ -38,7 +38,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
/** List of all registered events **/
private ArrayList<Event> registeredEvents = new ArrayList<>();
/** List of auto detected events **/
private ArrayList<HalEvent> detectedEvents = new ArrayList<>();
private ArrayList<HalEventData> detectedEvents = new ArrayList<>();
/** A map of all instantiated controllers **/
@ -87,12 +87,12 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
return availableSensors;
}
public List<HalSensor> getDetectedSensors(){
public List<HalSensorData> getDetectedSensors(){
return detectedSensors;
}
@Override
public void reportReceived(HalSensor sensorData) {
public void reportReceived(HalSensorData sensorData) {
try{
DBConnection db = HalContext.getDB();
Sensor sensor = null;
@ -165,12 +165,12 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
return availableEvents;
}
public List<HalEvent> getDetectedEvents(){
public List<HalEventData> getDetectedEvents(){
return detectedEvents;
}
@Override
public void reportReceived(HalEvent eventData) {
public void reportReceived(HalEventData eventData) {
try {
DBConnection db = HalContext.getDB();
Event event = null;
@ -259,12 +259,12 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
Iterator<PluginData> it = pluginManager.iterator();
while (it.hasNext()){
PluginData plugin = it.next();
Iterator<Class<?>> pluginIt = plugin.getClassIterator(HalSensor.class);
Iterator<Class<?>> pluginIt = plugin.getClassIterator(HalSensorData.class);
while (pluginIt.hasNext()){
manager.availableSensors.add(pluginIt.next());
}
pluginIt = plugin.getClassIterator(HalEvent.class);
pluginIt = plugin.getClassIterator(HalEventData.class);
while (pluginIt.hasNext()){
manager.availableEvents.add(pluginIt.next());
}

View file

@ -4,7 +4,7 @@ import se.hal.bot.AliceBot;
import se.hal.intf.HalBot;
import se.hal.intf.HalSpeachToText;
import se.hal.intf.HalTextToSpeach;
import se.hal.struct.SwitchEvent;
import se.hal.struct.SwitchEventData;
import se.hal.stt.ManualSTTClient;
import se.hal.tts.MaryRemoteTTSClient;
@ -20,7 +20,7 @@ import java.util.regex.Pattern;
* Time: 10:59
*/
public class HalSpeechClient {
private static HashMap<String, SwitchEvent> switches = new HashMap<String, SwitchEvent>();
private static HashMap<String, SwitchEventData> switches = new HashMap<String, SwitchEventData>();
public static void main(String[] args){
@ -53,22 +53,22 @@ public class HalSpeechClient {
/* NexaSelfLearning nexa1 = new NexaSelfLearning();
nexa1.setHouse(15087918);
nexa1.setUnit(0);
switches.put("livingroom", new SwitchEvent("livingroom", nexa1));
switches.put("livingroom", new SwitchEventData("livingroom", nexa1));
NexaSelfLearning nexa2 = new NexaSelfLearning();
nexa2.setHouse(15087918);
nexa2.setUnit(1);
switches.put("bedroom", new SwitchEvent("bedroom", nexa2));
switches.put("bedroom", new SwitchEventData("bedroom", nexa2));
NexaSelfLearning nexa3 = new NexaSelfLearning();
nexa3.setHouse(15087918);
nexa3.setUnit(3);
switches.put("kitchen", new SwitchEvent("kitchen", nexa3));
switches.put("kitchen", new SwitchEventData("kitchen", nexa3));
TellstickSerialComm.getInstance().setListener(new TellstickChangeListener() {
@Override
public void stateChange(TellstickProtocol protocol) {
for(SwitchEvent s : switches.values()) {
for(SwitchEventData s : switches.values()) {
if(s.equals(protocol)) {
String response = s.getName()+" window is "+(((NexaSelfLearning)protocol).isEnabled() ? "open": "closed");
System.out.println(">>> " + response);
@ -118,7 +118,7 @@ public class HalSpeechClient {
if(m.find()){
String name = m.group(1);
if(name.equals("all")){
for(SwitchEvent s : switches.values())
for(SwitchEventData s : switches.values())
s.turnOn();
return "I've turned everything on for you";
}
@ -132,7 +132,7 @@ public class HalSpeechClient {
if(m.find()){
String name = m.group(1);
if(name.equals("all")){
for(SwitchEvent s : switches.values())
for(SwitchEventData s : switches.values())
s.turnOff();
return "I turned everything off";
}

View file

@ -3,8 +3,7 @@ package se.hal.deamon;
import se.hal.HalContext;
import se.hal.intf.HalDaemon;
import se.hal.struct.Sensor;
import se.hal.intf.HalSensor.AggregationMethod;
import se.hal.struct.PowerConsumptionSensor;
import se.hal.intf.HalSensorData.AggregationMethod;
import se.hal.util.TimeUtility;
import zutil.db.DBConnection;
import zutil.db.SQLResultHandler;
@ -43,7 +42,7 @@ public class SensorDataAggregatorDaemon implements HalDaemon {
}
public void aggregateSensor(Sensor sensor) {
//if(sensor.getSensorData() instanceof PowerConsumptionSensor){
//if(sensor.getSensorData() instanceof PowerConsumptionSensorData){
logger.fine("The sensor is of type: " + sensor.getDeviceData().getClass().getName());
logger.fine("aggregating raw data to five minute periods");
aggregateRawData(sensor, TimeUtility.FIVE_MINUTES_IN_MS, 5);

View file

@ -3,7 +3,6 @@ package se.hal.deamon;
import se.hal.HalContext;
import se.hal.intf.HalDaemon;
import se.hal.struct.Sensor;
import se.hal.struct.PowerConsumptionSensor;
import se.hal.util.TimeUtility;
import zutil.db.DBConnection;
import zutil.db.SQLResultHandler;
@ -42,7 +41,7 @@ public class SensorDataCleanupDaemon implements HalDaemon {
}
public void cleanupSensor(Sensor sensor) {
//if(sensor instanceof PowerConsumptionSensor){
//if(sensor instanceof PowerConsumptionSensorData){
logger.fine("The sensor is of type: " + sensor.getDeviceData().getClass().getName());
if(sensor.getUser().isExternal()){
cleanupExternalSensorData(sensor.getId(), TimeUtility.FIVE_MINUTES_IN_MS, TimeUtility.DAY_IN_MS);

View file

@ -10,18 +10,18 @@ public interface HalEventController {
/**
* Will register an event type to be handled by this controller
*/
public void register(HalEvent event);
public void register(HalEventData event);
/**
* Deregisters an event from this controller, the controller
* will no longer handle that type of event
*/
public void deregister(HalEvent event);
public void deregister(HalEventData event);
/**
* @param event transmit this event if possible.
*/
public void send(HalEvent event); // TODO: where to put data?
public void send(HalEventData event); // TODO: where to put data?
/**
* @return the number of registered objects

View file

@ -3,7 +3,7 @@ package se.hal.intf;
/**
* Created by Ziver on 2015-12-23.
*/
public interface HalEvent {
public interface HalEventData {
long getTimestamp();

View file

@ -2,6 +2,6 @@ package se.hal.intf;
public interface HalEventReportListener {
void reportReceived(HalEvent e);
void reportReceived(HalEventData e);
}

View file

@ -10,13 +10,13 @@ public interface HalSensorController {
/**
* Will register a sensor type to be handled by this controller
*/
void register(HalSensor sensor);
void register(HalSensorData sensor);
/**
* Deregisters a sensor from this controller, the controller
* will no longer handle that type of sensor
*/
void deregister(HalSensor sensor);
void deregister(HalSensorData sensor);
/**
* @return the number of registered objects

View file

@ -3,7 +3,7 @@ package se.hal.intf;
/**
* Created by Ziver on 2015-12-23.
*/
public interface HalSensor {
public interface HalSensorData {
enum AggregationMethod{
SUM,
AVERAGE

View file

@ -2,6 +2,6 @@ package se.hal.intf;
public interface HalSensorReportListener {
void reportReceived(HalSensor s);
void reportReceived(HalSensorData s);
}

View file

@ -1,6 +1,6 @@
package se.hal.plugin.localsensor;
import se.hal.intf.HalSensor;
import se.hal.intf.HalSensorData;
import se.hal.intf.HalSensorController;
import se.hal.intf.HalSensorReportListener;
@ -14,12 +14,12 @@ public class RPiController implements HalSensorController {
}
@Override
public void register(HalSensor sensor) {
public void register(HalSensorData sensor) {
}
@Override
public void deregister(HalSensor sensor) {
public void deregister(HalSensorData sensor) {
}

View file

@ -1,13 +1,12 @@
package se.hal.plugin.localsensor;
import se.hal.intf.HalSensor;
import se.hal.intf.HalSensorController;
import se.hal.struct.PowerConsumptionSensor;
import se.hal.struct.PowerConsumptionSensorData;
/**
* Created by ezivkoc on 2016-01-14.
*/
public class RPiSensor implements PowerConsumptionSensor {
public class RPiSensor implements PowerConsumptionSensorData {
@Override
public long getTimestamp() {

View file

@ -2,6 +2,6 @@
"version": 1.0,
"name": "RPiImpulsCountSensor",
"interfaces": [
{"se.hal.intf.HalSensor": "se.hal.plugin.localsensor.RPiSensor"}
{"se.hal.intf.HalSensorData": "se.hal.plugin.localsensor.RPiSensor"}
]
}

View file

@ -122,10 +122,10 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
protocol.setTimestamp(System.currentTimeMillis());
set.add(data);
if (sensorListener != null && protocol instanceof HalSensor)
sensorListener.reportReceived((HalSensor) protocol);
else if (eventListener != null && protocol instanceof HalEvent)
eventListener.reportReceived((HalEvent) protocol);
if (sensorListener != null && protocol instanceof HalSensorData)
sensorListener.reportReceived((HalSensorData) protocol);
else if (eventListener != null && protocol instanceof HalEventData)
eventListener.reportReceived((HalEventData) protocol);
}
}
}
@ -157,7 +157,7 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
@Override
public void send(HalEvent event) {
public void send(HalEventData event) {
if(event instanceof TellstickProtocol)
write((TellstickProtocol) event);
}
@ -182,14 +182,14 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
@Override
public void register(HalEvent event) {++registeredObjects;}
public void register(HalEventData event) {++registeredObjects;}
@Override
public void register(HalSensor sensor) {++registeredObjects;}
public void register(HalSensorData sensor) {++registeredObjects;}
@Override
public void deregister(HalSensor sensor) {--registeredObjects;}
public void deregister(HalSensorData sensor) {--registeredObjects;}
@Override
public void deregister(HalEvent event) {--registeredObjects;}
public void deregister(HalEventData event) {--registeredObjects;}
@Override
public int size() {

View file

@ -2,7 +2,7 @@
"version": 1.0,
"name": "Tellstick",
"interfaces": [
{"se.hal.intf.HalSensor": "se.hal.plugin.tellstick.protocols.Oregon0x1A2D"},
{"se.hal.intf.HalEvent": "se.hal.plugin.tellstick.protocols.NexaSelfLearning"}
{"se.hal.intf.HalSensorData": "se.hal.plugin.tellstick.protocols.Oregon0x1A2D"},
{"se.hal.intf.HalEventData": "se.hal.plugin.tellstick.protocols.NexaSelfLearning"}
]
}

View file

@ -23,13 +23,13 @@
package se.hal.plugin.tellstick.protocols;
import se.hal.plugin.tellstick.TellstickProtocol;
import se.hal.struct.SwitchEvent;
import se.hal.struct.SwitchEventData;
import zutil.ui.Configurator;
/**
* Created by Ziver on 2015-02-18.
*/
public class NexaSelfLearning extends TellstickProtocol implements SwitchEvent {
public class NexaSelfLearning extends TellstickProtocol implements SwitchEventData {
@Configurator.Configurable("House code")
private int house = 0;

View file

@ -1,13 +1,13 @@
package se.hal.plugin.tellstick.protocols;
import se.hal.plugin.tellstick.TellstickProtocol;
import se.hal.struct.PowerConsumptionSensor;
import se.hal.struct.PowerConsumptionSensorData;
import zutil.ui.Configurator;
/**
* Created by Ziver on 2015-11-19.
*/
public class Oregon0x1A2D extends TellstickProtocol implements PowerConsumptionSensor {
public class Oregon0x1A2D extends TellstickProtocol implements PowerConsumptionSensorData {
@Configurator.Configurable("Address")
private int address = 0;

View file

@ -1,7 +1,5 @@
package se.hal.struct;
import se.hal.intf.HalSensor;
import se.hal.intf.HalSensorController;
import zutil.db.DBConnection;
import zutil.db.bean.DBBean;
import zutil.log.LogUtil;

View file

@ -22,11 +22,11 @@
package se.hal.struct;
import se.hal.intf.HalEvent;
import se.hal.intf.HalEventData;
/**
* Created by Ziver on 2015-05-07.
*/
public abstract class DimmerEvent implements HalEvent {
public abstract class DimmerEventData implements HalEventData {
}

View file

@ -1,32 +1,22 @@
package se.hal.struct;
import se.hal.intf.HalEvent;
import se.hal.intf.HalEventData;
import se.hal.intf.HalEventController;
import se.hal.intf.HalSensor;
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 zutil.ui.Configurator;
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;
/**
* Created by Ziver on 2015-12-15.
*/
@DBBean.DBTable("event")
public class Event extends AbstractDevice<HalEvent>{
public class Event extends AbstractDevice<HalEventData>{
private static final Logger logger = LogUtil.getLogger();

View file

@ -1,9 +0,0 @@
package se.hal.struct;
import se.hal.intf.HalSensor;
/**
* Created by Ziver on 2015-12-03.
*/
public interface PowerConsumptionSensor extends HalSensor {
}

View file

@ -0,0 +1,9 @@
package se.hal.struct;
import se.hal.intf.HalSensorData;
/**
* Created by Ziver on 2015-12-03.
*/
public interface PowerConsumptionSensorData extends HalSensorData {
}

View file

@ -1,31 +1,22 @@
package se.hal.struct;
import se.hal.HalContext;
import se.hal.intf.HalSensor;
import se.hal.intf.HalSensorData;
import se.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.json.JSONObjectInputStream;
import zutil.parser.json.JSONObjectOutputStream;
import zutil.parser.json.JSONParser;
import zutil.parser.json.JSONWriter;
import zutil.ui.Configurator;
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(value="sensor", superBean=true)
public class Sensor extends AbstractDevice<HalSensor>{
public class Sensor extends AbstractDevice<HalSensorData>{
private static final Logger logger = LogUtil.getLogger();
private long external_id = -1;
@ -88,7 +79,7 @@ public class Sensor extends AbstractDevice<HalSensor>{
}
public HalSensor.AggregationMethod getAggregationMethod(){
public HalSensorData.AggregationMethod getAggregationMethod(){
return getDeviceData().getAggregationMethod();
}

View file

@ -22,12 +22,12 @@
package se.hal.struct;
import se.hal.intf.HalEvent;
import se.hal.intf.HalEventData;
/**
* Created by Ziver on 2015-05-07.
*/
public interface SwitchEvent extends HalEvent {
public interface SwitchEventData extends HalEventData {
boolean isOn();

View file

@ -1,11 +1,11 @@
package se.hal.struct;
import se.hal.intf.HalSensor;
import se.hal.intf.HalSensorData;
/**
* Created by Ziver on 2015-12-03.
*/
public interface TemperatureSensor extends HalSensor {
public interface TemperatureSensorData extends HalSensorData {
double getTemperature();

View file

@ -1,7 +1,7 @@
package se.hal.plugin.tellstick;
import se.hal.HalContext;
import se.hal.intf.HalSensor;
import se.hal.intf.HalSensorData;
import se.hal.intf.HalSensorReportListener;
import se.hal.plugin.tellstick.protocols.Oregon0x1A2D;
import zutil.db.DBConnection;
@ -32,7 +32,7 @@ public class TelstickSerialCommTest {
TellstickSerialComm comm = new TellstickSerialComm();
comm.setListener(new HalSensorReportListener() {
@Override
public void reportReceived(HalSensor s) {
public void reportReceived(HalSensorData s) {
if(s instanceof Oregon0x1A2D){
logger.info("Power used: "+ ((Oregon0x1A2D)s).getTemperature() +" pulses");
try {