Refactoring of of inheritance structure, ControllerManagers will now also be able to be provided through plugins
This commit is contained in:
parent
28bc108921
commit
c0188cd5cc
73 changed files with 1083 additions and 991 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -10,3 +10,4 @@
|
|||
# Build and Ide files
|
||||
build
|
||||
.gradle
|
||||
.idea
|
||||
|
|
@ -56,6 +56,7 @@ distributions {
|
|||
main {
|
||||
contents {
|
||||
from 'hal.conf.example'
|
||||
from 'hal-default.db'
|
||||
from 'logging.properties'
|
||||
|
||||
from "${buildDir}/resources"
|
||||
|
|
|
|||
|
|
@ -1,463 +0,0 @@
|
|||
package se.hal;
|
||||
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.Event;
|
||||
import se.hal.struct.Sensor;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.plugin.PluginManager;
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.Configurator.PostConfigurationActionListener;
|
||||
import zutil.ui.Configurator.PreConfigurationActionListener;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* This class manages all SensorController and EventController objects
|
||||
*/
|
||||
public class ControllerManager implements HalSensorReportListener,
|
||||
HalEventReportListener,
|
||||
PreConfigurationActionListener,
|
||||
PostConfigurationActionListener {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
private static ControllerManager instance;
|
||||
|
||||
|
||||
/** All available sensor plugins **/
|
||||
private List<Class<? extends HalSensorConfig>> availableSensors = new ArrayList<>();
|
||||
/** List of all registered sensors **/
|
||||
private List<Sensor> registeredSensors = Collections.synchronizedList(new ArrayList<>());
|
||||
/** List of auto detected sensors **/
|
||||
private List<Sensor> detectedSensors = Collections.synchronizedList(new ArrayList<>());
|
||||
/** List of sensors that are currently being reconfigured **/
|
||||
private List<Sensor> limboSensors = Collections.synchronizedList(new LinkedList<>());
|
||||
|
||||
|
||||
/** All available event plugins **/
|
||||
private List<Class<? extends HalEventConfig>> availableEvents = new ArrayList<>();
|
||||
/** List of all registered events **/
|
||||
private List<Event> registeredEvents = Collections.synchronizedList(new ArrayList<>());
|
||||
/** List of auto detected events **/
|
||||
private List<Event> detectedEvents = Collections.synchronizedList(new ArrayList<>());
|
||||
/** List of all registered events **/
|
||||
private List<Event> limboEvents = Collections.synchronizedList(new LinkedList<>());
|
||||
|
||||
|
||||
/** A map of all instantiated controllers **/
|
||||
private HashMap<Class,HalAbstractController> controllerMap = new HashMap<>();
|
||||
|
||||
|
||||
/////////////////////////////// SENSORS ///////////////////////////////////
|
||||
|
||||
/**
|
||||
* Register a Sensor instance on the manager.
|
||||
* The manager will start to save reported data for the registered Sensor.
|
||||
*/
|
||||
public void register(Sensor sensor) {
|
||||
if(sensor.getDeviceConfig() == null) {
|
||||
logger.warning("Sensor config is null: "+ sensor);
|
||||
return;
|
||||
}
|
||||
if(!availableSensors.contains(sensor.getDeviceConfig().getClass())) {
|
||||
logger.warning("Sensor data plugin not available: "+ sensor.getDeviceConfig().getClass());
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Registering new sensor(id: "+ sensor.getId() +"): "+ sensor.getDeviceConfig().getClass());
|
||||
Class<? extends HalSensorController> c = sensor.getController();
|
||||
HalSensorController controller = getControllerInstance(c);
|
||||
|
||||
if(controller != null)
|
||||
controller.register(sensor.getDeviceConfig());
|
||||
registeredSensors.add(sensor);
|
||||
detectedSensors.remove(findSensor(sensor.getDeviceConfig(), detectedSensors)); // Remove if this device was detected
|
||||
}
|
||||
|
||||
/**
|
||||
* Deregisters a Sensor from the manager.
|
||||
* Data reported on the Sensor will no longer be saved but already saved data will not be modified.
|
||||
* The Controller that owns the Sensor will be deallocated if it has no more registered devices.
|
||||
*/
|
||||
public void deregister(Sensor sensor){
|
||||
if(sensor.getDeviceConfig() == null) {
|
||||
logger.warning("Sensor config is null: "+ sensor);
|
||||
return;
|
||||
}
|
||||
|
||||
Class<? extends HalSensorController> c = sensor.getController();
|
||||
HalSensorController controller = (HalSensorController) controllerMap.get(c);
|
||||
if (controller != null) {
|
||||
logger.info("Deregistering sensor(id: "+ sensor.getId() +"): "+ sensor.getDeviceConfig().getClass());
|
||||
controller.deregister(sensor.getDeviceConfig());
|
||||
registeredSensors.remove(sensor);
|
||||
removeControllerIfEmpty(controller);
|
||||
} else {
|
||||
logger.warning("Controller not instantiated:"+ sensor.getController());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a Sensor class type as usable by the manager
|
||||
*/
|
||||
public void addAvailableSensor(Class<? extends HalSensorConfig> sensorClass) {
|
||||
if ( ! availableSensors.contains(sensorClass))
|
||||
availableSensors.add(sensorClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a List of all available Sensors that can be registered to this manager
|
||||
*/
|
||||
public List<Class<? extends HalSensorConfig>> getAvailableSensors(){
|
||||
return availableSensors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a List of Sensor instances that have been registered to this manager
|
||||
*/
|
||||
public List<Sensor> getRegisteredSensors(){
|
||||
return registeredSensors;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return a List of Sensor instances that have been reported but not registered on the manager
|
||||
*/
|
||||
public List<Sensor> getDetectedSensors(){
|
||||
return detectedSensors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all auto detected sensors.
|
||||
*/
|
||||
public void clearDetectedSensors(){
|
||||
detectedSensors.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by Controllers to report received Sensor data
|
||||
*/
|
||||
@Override
|
||||
public void reportReceived(HalSensorConfig sensorConfig, HalSensorData sensorData) {
|
||||
try{
|
||||
DBConnection db = HalContext.getDB();
|
||||
Sensor sensor = findSensor(sensorConfig, registeredSensors);
|
||||
|
||||
if (sensor != null) {
|
||||
logger.finest("Received report from sensor("+sensorConfig.getClass().getSimpleName()+"): "+ sensorConfig);
|
||||
PreparedStatement stmt =
|
||||
db.getPreparedStatement("INSERT INTO sensor_data_raw (timestamp, sensor_id, data) VALUES(?, ?, ?)");
|
||||
stmt.setLong(1, sensorData.getTimestamp());
|
||||
stmt.setLong(2, sensor.getId());
|
||||
stmt.setDouble(3, sensorData.getData());
|
||||
DBConnection.exec(stmt);
|
||||
}
|
||||
else { // unknown sensor
|
||||
logger.finest("Received report from unregistered sensor" +
|
||||
"("+sensorConfig.getClass().getSimpleName()+"): "+ sensorConfig);
|
||||
sensor = findSensor(sensorConfig, detectedSensors);
|
||||
if(sensor == null) {
|
||||
sensor = new Sensor();
|
||||
detectedSensors.add(sensor);
|
||||
}
|
||||
sensor.setDeviceConfig(sensorConfig);
|
||||
}
|
||||
sensor.setDeviceData(sensorData);
|
||||
// call listeners
|
||||
for(HalDeviceReportListener<Sensor> listener : sensor.getReportListeners())
|
||||
listener.receivedReport(sensor);
|
||||
|
||||
}catch (SQLException e){
|
||||
logger.log(Level.WARNING, "Unable to store sensor report", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Sensor findSensor(HalSensorConfig sensorData, List<Sensor> list){
|
||||
for (int i=0; i<list.size(); ++i) { // Don't use foreach for concurrency reasons
|
||||
Sensor s = list.get(i);
|
||||
if (sensorData.equals(s.getDeviceConfig())) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//////////////////////////////// EVENTS ///////////////////////////////////
|
||||
|
||||
/**
|
||||
* Register a Event instance on the manager.
|
||||
* The manager will start to save reported data for the registered Event.
|
||||
*/
|
||||
public void register(Event event) {
|
||||
if(event.getDeviceConfig() == null) {
|
||||
logger.warning("Event config is null: "+ event);
|
||||
return;
|
||||
}
|
||||
if(!availableEvents.contains(event.getDeviceConfig().getClass())) {
|
||||
logger.warning("Event data plugin not available: "+ event.getDeviceConfig().getClass());
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Registering new event(id: "+ event.getId() +"): "+ event.getDeviceConfig().getClass());
|
||||
Class<? extends HalEventController> c = event.getController();
|
||||
HalEventController controller = getControllerInstance(c);
|
||||
|
||||
if(controller != null)
|
||||
controller.register(event.getDeviceConfig());
|
||||
registeredEvents.add(event);
|
||||
detectedEvents.remove(findEvent(event.getDeviceConfig(), detectedEvents)); // Remove if this device was detected
|
||||
}
|
||||
|
||||
/**
|
||||
* Deregisters a Event from the manager.
|
||||
* Data reported on the Event will no longer be saved but already saved data will not be modified.
|
||||
* The Controller that owns the Event will be deallocated if it has no more registered devices.
|
||||
*/
|
||||
public void deregister(Event event){
|
||||
if(event.getDeviceConfig() == null) {
|
||||
logger.warning("Event config is null: "+ event);
|
||||
return;
|
||||
}
|
||||
|
||||
Class<? extends HalEventController> c = event.getController();
|
||||
HalEventController controller = (HalEventController) controllerMap.get(c);
|
||||
if (controller != null) {
|
||||
logger.info("Deregistering event(id: "+ event.getId() +"): "+ event.getDeviceConfig().getClass());
|
||||
controller.deregister(event.getDeviceConfig());
|
||||
registeredEvents.remove(event);
|
||||
removeControllerIfEmpty(controller);
|
||||
} else {
|
||||
logger.warning("Controller not instantiated: "+ event.getController());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a Event class type as usable by the manager
|
||||
*/
|
||||
public void addAvailableEvent(Class<? extends HalEventConfig> eventClass) {
|
||||
if ( ! availableEvents.contains(eventClass))
|
||||
availableEvents.add(eventClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a List of all available Events that can be registered to this manager
|
||||
*/
|
||||
public List<Class<? extends HalEventConfig>> getAvailableEvents(){
|
||||
return availableEvents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a List of Sensor instances that have been registered to this manager
|
||||
*/
|
||||
public List<Event> getRegisteredEvents(){
|
||||
return registeredEvents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a List of Event instances that have been reported but not registered on the manager
|
||||
*/
|
||||
public List<Event> getDetectedEvents(){
|
||||
return detectedEvents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all auto detected events.
|
||||
*/
|
||||
public void clearDetectedEvents(){
|
||||
detectedEvents.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by Controllers to report received Event data
|
||||
*/
|
||||
@Override
|
||||
public void reportReceived(HalEventConfig eventConfig, HalEventData eventData) {
|
||||
try {
|
||||
DBConnection db = HalContext.getDB();
|
||||
Event event = findEvent(eventConfig, registeredEvents);
|
||||
|
||||
if (event != null) {
|
||||
logger.finest("Received report from event("+eventConfig.getClass().getSimpleName()+"): "+ eventConfig);
|
||||
PreparedStatement stmt =
|
||||
db.getPreparedStatement("INSERT INTO event_data_raw (timestamp, event_id, data) VALUES(?, ?, ?)");
|
||||
stmt.setLong(1, eventData.getTimestamp());
|
||||
stmt.setLong(2, event.getId());
|
||||
stmt.setDouble(3, eventData.getData());
|
||||
DBConnection.exec(stmt);
|
||||
}
|
||||
else { // unknown sensor
|
||||
logger.info("Received report from unregistered event" +
|
||||
"("+eventConfig.getClass().getSimpleName()+"): "+ eventConfig);
|
||||
event = findEvent(eventConfig, detectedEvents);
|
||||
if(event == null) {
|
||||
event = new Event();
|
||||
detectedEvents.add(event);
|
||||
}
|
||||
event.setDeviceConfig(eventConfig);
|
||||
}
|
||||
event.setDeviceData(eventData);
|
||||
// call listeners
|
||||
for(HalDeviceReportListener<Event> listener : event.getReportListeners())
|
||||
listener.receivedReport(event);
|
||||
|
||||
}catch (SQLException e){
|
||||
logger.log(Level.WARNING, "Unable to store event report", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Event findEvent(HalEventConfig eventData, List<Event> list){
|
||||
for (int i=0; i<list.size(); ++i) { // Don't use foreach for concurrency reasons
|
||||
Event e = list.get(i);
|
||||
if (eventData.equals(e.getDeviceConfig())) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void send(Event event){
|
||||
HalEventController controller = getControllerInstance(event.getController());
|
||||
if(controller != null) {
|
||||
controller.send(event.getDeviceConfig(), event.getDeviceData());
|
||||
reportReceived(event.getDeviceConfig(), event.getDeviceData()); // save action to db
|
||||
}
|
||||
else
|
||||
logger.warning("No controller found for event id: "+ event.getId());
|
||||
}
|
||||
|
||||
/////////////////////////////// GENERAL ///////////////////////////////////
|
||||
|
||||
/**
|
||||
* @return all instantiated controllers.
|
||||
*/
|
||||
public List<HalAbstractController> getControllers() {
|
||||
return new ArrayList(controllerMap.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preConfigurationAction(Configurator configurator, Object obj) {
|
||||
if(obj instanceof HalSensorConfig) {
|
||||
Sensor sensor = findSensor((HalSensorConfig) obj, registeredSensors);
|
||||
if(sensor != null){
|
||||
deregister(sensor);
|
||||
limboSensors.add(sensor);
|
||||
}
|
||||
}
|
||||
else if(obj instanceof HalEventConfig) {
|
||||
Event event = findEvent((HalEventConfig) obj, registeredEvents);
|
||||
if(event != null){
|
||||
deregister(event);
|
||||
limboEvents.add(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postConfigurationAction(Configurator configurator, Object obj) {
|
||||
if(obj instanceof HalSensorConfig) {
|
||||
Sensor sensor = findSensor((HalSensorConfig) obj, limboSensors);
|
||||
if(sensor != null){
|
||||
register(sensor);
|
||||
limboSensors.remove(sensor);
|
||||
}
|
||||
}
|
||||
else if(obj instanceof HalEventConfig) {
|
||||
Event event = findEvent((HalEventConfig) obj, limboEvents);
|
||||
if(event != null){
|
||||
register(event);
|
||||
limboEvents.remove(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private <T extends HalAbstractController> T getControllerInstance(Class<T> c){
|
||||
HalAbstractController controller;
|
||||
|
||||
if (controllerMap.containsKey(c)) {
|
||||
controller = controllerMap.get(c);
|
||||
} else {
|
||||
try {
|
||||
// Instantiate controller
|
||||
controller = c.newInstance();
|
||||
|
||||
if (controller instanceof HalAutoScannableController &&
|
||||
! ((HalAutoScannableController) controller).isAvailable()) {
|
||||
logger.warning("Controller is not ready: " + c.getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
logger.info("Instantiating new controller: " + c.getName());
|
||||
controller.initialize();
|
||||
|
||||
if(controller instanceof HalSensorController) {
|
||||
((HalSensorController) controller).setListener(this);
|
||||
}
|
||||
if(controller instanceof HalEventController) {
|
||||
((HalEventController) controller).setListener(this);
|
||||
}
|
||||
|
||||
controllerMap.put(c, controller);
|
||||
} catch (Exception e){
|
||||
logger.log(Level.SEVERE, "Unable to instantiate controller: " + c.getName(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return (T) controller;
|
||||
}
|
||||
|
||||
private void removeControllerIfEmpty(Object controller){
|
||||
if (controller instanceof HalAutoScannableController)
|
||||
return; // Don't do anything if controller is scannable
|
||||
|
||||
int size = Integer.MAX_VALUE;
|
||||
if(controller instanceof HalSensorController)
|
||||
size = ((HalSensorController) controller).size();
|
||||
else if(controller instanceof HalEventController)
|
||||
size = ((HalEventController) controller).size();
|
||||
|
||||
if(size < 0){
|
||||
// Remove controller as it has no more registered sensors
|
||||
logger.info("Closing controller as it has no more registered devices: " + controller.getClass().getName());
|
||||
controllerMap.remove(controller.getClass());
|
||||
|
||||
if(controller instanceof HalSensorController)
|
||||
((HalSensorController) controller).close();
|
||||
else if(controller instanceof HalEventController)
|
||||
((HalEventController) controller).close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void initialize(PluginManager pluginManager){
|
||||
ControllerManager manager = new ControllerManager();
|
||||
|
||||
for (Iterator<Class<? extends HalSensorConfig>> it = pluginManager.getClassIterator(HalSensorConfig.class);
|
||||
it.hasNext(); ){
|
||||
manager.addAvailableSensor(it.next());
|
||||
}
|
||||
|
||||
for (Iterator<Class<? extends HalEventConfig>> it = pluginManager.getClassIterator(HalEventConfig.class);
|
||||
it.hasNext(); ){
|
||||
manager.addAvailableEvent(it.next());
|
||||
}
|
||||
|
||||
for (Iterator<Class<? extends HalAutoScannableController>> it = pluginManager.getClassIterator(HalAutoScannableController.class);
|
||||
it.hasNext(); ){
|
||||
Class controller = it.next();
|
||||
|
||||
if (controller.isAssignableFrom(HalAbstractController.class))
|
||||
manager.getControllerInstance(controller); // Instantiate controller
|
||||
}
|
||||
|
||||
instance = manager;
|
||||
}
|
||||
|
||||
|
||||
public static ControllerManager getInstance(){
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
229
hal-core/src/se/hal/EventControllerManager.java
Normal file
229
hal-core/src/se/hal/EventControllerManager.java
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
package se.hal;
|
||||
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.Event;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.plugin.PluginManager;
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.Configurator.PostConfigurationActionListener;
|
||||
import zutil.ui.Configurator.PreConfigurationActionListener;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* This class manages all SensorController and EventController objects
|
||||
*/
|
||||
public class EventControllerManager extends HalAbstractControllerManager<HalEventController,Event,HalEventConfig> implements
|
||||
HalDeviceReportListener<HalEventConfig,HalEventData>,
|
||||
PreConfigurationActionListener,
|
||||
PostConfigurationActionListener {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
private static EventControllerManager instance;
|
||||
|
||||
/** All available event plugins **/
|
||||
private List<Class<? extends HalEventConfig>> availableEvents = new ArrayList<>();
|
||||
/** List of all registered events **/
|
||||
private List<Event> registeredEvents = Collections.synchronizedList(new ArrayList<>());
|
||||
/** List of auto detected events **/
|
||||
private List<Event> detectedEvents = Collections.synchronizedList(new ArrayList<>());
|
||||
/** List of all registered events **/
|
||||
private List<Event> limboEvents = Collections.synchronizedList(new LinkedList<>());
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
// EVENTS
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* Register a Event instance on the manager.
|
||||
* The manager will start to save reported data for the registered Event.
|
||||
*/
|
||||
@Override
|
||||
public void register(Event event) {
|
||||
if(event.getDeviceConfig() == null) {
|
||||
logger.warning("Event config is null: " + event);
|
||||
return;
|
||||
}
|
||||
if(!availableEvents.contains(event.getDeviceConfig().getClass())) {
|
||||
logger.warning("Event data plugin not available: " + event.getDeviceConfig().getClass());
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Registering new event(id: " + event.getId() + "): " + event.getDeviceConfig().getClass());
|
||||
Class<? extends HalEventController> c = event.getController();
|
||||
HalEventController controller = getControllerInstance(c);
|
||||
|
||||
if(controller != null)
|
||||
controller.register(event.getDeviceConfig());
|
||||
registeredEvents.add(event);
|
||||
detectedEvents.remove(findEvent(event.getDeviceConfig(), detectedEvents)); // Remove if this device was detected
|
||||
}
|
||||
|
||||
/**
|
||||
* Deregisters a Event from the manager.
|
||||
* Data reported on the Event will no longer be saved but already saved data will not be modified.
|
||||
* The Controller that owns the Event will be deallocated if it has no more registered devices.
|
||||
*/
|
||||
@Override
|
||||
public void deregister(Event event){
|
||||
if(event.getDeviceConfig() == null) {
|
||||
logger.warning("Event config is null: "+ event);
|
||||
return;
|
||||
}
|
||||
|
||||
Class<? extends HalEventController> c = event.getController();
|
||||
HalEventController controller = controllerMap.get(c);
|
||||
if (controller != null) {
|
||||
logger.info("Deregistering event(id: " + event.getId() + "): " + event.getDeviceConfig().getClass());
|
||||
controller.deregister(event.getDeviceConfig());
|
||||
registeredEvents.remove(event);
|
||||
removeControllerIfEmpty(controller);
|
||||
} else {
|
||||
logger.warning("Controller not instantiated: "+ event.getController());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a Event class type as usable by the manager
|
||||
*/
|
||||
@Override
|
||||
public void addAvailableDevice(Class<? extends HalEventConfig> eventClass) {
|
||||
if (!availableEvents.contains(eventClass))
|
||||
availableEvents.add(eventClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a List of all available Events that can be registered to this manager
|
||||
*/
|
||||
@Override
|
||||
public List<Class<? extends HalEventConfig>> getAvailableDeviceConfigs(){
|
||||
return availableEvents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a List of Sensor instances that have been registered to this manager
|
||||
*/
|
||||
@Override
|
||||
public List<Event> getRegisteredDevices(){
|
||||
return registeredEvents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a List of Event instances that have been reported but not registered on the manager
|
||||
*/
|
||||
@Override
|
||||
public List<Event> getDetectedDevices(){
|
||||
return detectedEvents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all auto detected events.
|
||||
*/
|
||||
@Override
|
||||
public void clearDetectedDevices(){
|
||||
detectedEvents.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by Controllers to report received Event data
|
||||
*/
|
||||
@Override
|
||||
public void reportReceived(HalEventConfig eventConfig, HalEventData eventData) {
|
||||
try {
|
||||
DBConnection db = HalContext.getDB();
|
||||
Event event = findEvent(eventConfig, registeredEvents);
|
||||
|
||||
if (event != null) {
|
||||
logger.finest("Received report from event(" + eventConfig.getClass().getSimpleName() + "): " + eventConfig);
|
||||
PreparedStatement stmt =
|
||||
db.getPreparedStatement("INSERT INTO event_data_raw (timestamp, event_id, data) VALUES(?, ?, ?)");
|
||||
stmt.setLong(1, eventData.getTimestamp());
|
||||
stmt.setLong(2, event.getId());
|
||||
stmt.setDouble(3, eventData.getData());
|
||||
DBConnection.exec(stmt);
|
||||
}
|
||||
else { // unknown sensor
|
||||
logger.info("Received report from unregistered event" +
|
||||
"(" + eventConfig.getClass().getSimpleName() + "): " + eventConfig);
|
||||
event = findEvent(eventConfig, detectedEvents);
|
||||
if(event == null) {
|
||||
event = new Event();
|
||||
detectedEvents.add(event);
|
||||
}
|
||||
event.setDeviceConfig(eventConfig);
|
||||
}
|
||||
event.setDeviceData(eventData);
|
||||
// call listeners
|
||||
for(HalDeviceReportListener<HalEventConfig,HalEventData> listener : event.getReportListeners())
|
||||
listener.reportReceived(event.getDeviceConfig(), eventData);
|
||||
|
||||
}catch (SQLException e){
|
||||
logger.log(Level.WARNING, "Unable to store event report", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Event findEvent(HalEventConfig eventData, List<Event> list){
|
||||
for (int i=0; i<list.size(); ++i) { // Don't use foreach for concurrency reasons
|
||||
Event e = list.get(i);
|
||||
if (eventData.equals(e.getDeviceConfig())) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void send(Event event){
|
||||
HalEventController controller = getControllerInstance(event.getController());
|
||||
if(controller != null) {
|
||||
controller.send(event.getDeviceConfig(), event.getDeviceData());
|
||||
reportReceived(event.getDeviceConfig(), event.getDeviceData()); // save action to db
|
||||
}
|
||||
else
|
||||
logger.warning("No controller found for event id: "+ event.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all instantiated controllers.
|
||||
*/
|
||||
@Override
|
||||
public Collection<HalEventController> getControllers() {
|
||||
return controllerMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preConfigurationAction(Configurator configurator, Object obj) {
|
||||
if(obj instanceof HalEventConfig) {
|
||||
Event event = findEvent((HalEventConfig) obj, registeredEvents);
|
||||
if(event != null){
|
||||
deregister(event);
|
||||
limboEvents.add(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postConfigurationAction(Configurator configurator, Object obj) {
|
||||
if (obj instanceof HalEventConfig) {
|
||||
Event event = findEvent((HalEventConfig) obj, limboEvents);
|
||||
if(event != null){
|
||||
register(event);
|
||||
limboEvents.remove(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize(PluginManager pluginManager){
|
||||
super.initialize(pluginManager);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
|
||||
public static EventControllerManager getInstance(){
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package se.hal;
|
||||
|
||||
|
||||
import se.hal.intf.HalAbstractControllerManager;
|
||||
import se.hal.intf.HalDaemon;
|
||||
import se.hal.intf.HalWebPage;
|
||||
import se.hal.intf.HalJsonPage;
|
||||
|
|
@ -85,9 +86,13 @@ public class HalServer {
|
|||
logger.info("Initializing managers.");
|
||||
|
||||
HalAlertManager.initialize();
|
||||
ControllerManager.initialize(pluginManager);
|
||||
TriggerManager.initialize(pluginManager);
|
||||
|
||||
for (Iterator<HalAbstractControllerManager> it = pluginManager.getSingletonIterator(HalAbstractControllerManager.class); it.hasNext(); ) {
|
||||
HalAbstractControllerManager manager = it.next();
|
||||
manager.initialize(pluginManager);
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// Import sensors,events and triggers
|
||||
// ------------------------------------
|
||||
|
|
@ -95,10 +100,10 @@ public class HalServer {
|
|||
logger.info("Initializing Sensors and Events.");
|
||||
|
||||
for (Sensor sensor : Sensor.getLocalSensors(db)) {
|
||||
ControllerManager.getInstance().register(sensor);
|
||||
SensorControllerManager.getInstance().register(sensor);
|
||||
}
|
||||
for (Event event : Event.getLocalEvents(db)) {
|
||||
ControllerManager.getInstance().register(event);
|
||||
EventControllerManager.getInstance().register(event);
|
||||
}
|
||||
// Import triggers
|
||||
for (TriggerFlow flow : TriggerFlow.getTriggerFlows(db)) {
|
||||
|
|
|
|||
213
hal-core/src/se/hal/SensorControllerManager.java
Normal file
213
hal-core/src/se/hal/SensorControllerManager.java
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
package se.hal;
|
||||
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.Sensor;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.plugin.PluginManager;
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.Configurator.PostConfigurationActionListener;
|
||||
import zutil.ui.Configurator.PreConfigurationActionListener;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* This class manages all SensorController and EventController objects
|
||||
*/
|
||||
public class SensorControllerManager extends HalAbstractControllerManager<HalAbstractController, Sensor, HalSensorConfig> implements
|
||||
HalDeviceReportListener<HalSensorConfig, HalSensorData>,
|
||||
PreConfigurationActionListener,
|
||||
PostConfigurationActionListener {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
private static SensorControllerManager instance;
|
||||
|
||||
|
||||
/** All available sensor plugins **/
|
||||
private List<Class<? extends HalSensorConfig>> availableSensors = new ArrayList<>();
|
||||
/** List of all registered sensors **/
|
||||
private List<Sensor> registeredSensors = Collections.synchronizedList(new ArrayList<>());
|
||||
/** List of auto detected sensors **/
|
||||
private List<Sensor> detectedSensors = Collections.synchronizedList(new ArrayList<>());
|
||||
/** List of sensors that are currently being reconfigured **/
|
||||
private List<Sensor> limboSensors = Collections.synchronizedList(new LinkedList<>());
|
||||
|
||||
// ----------------------------------------------------
|
||||
// SENSORS
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* Register a Sensor instance on the manager.
|
||||
* The manager will start to save reported data for the registered Sensor.
|
||||
*/
|
||||
@Override
|
||||
public void register(Sensor sensor) {
|
||||
if(sensor.getDeviceConfig() == null) {
|
||||
logger.warning("Sensor config is null: " + sensor);
|
||||
return;
|
||||
}
|
||||
if(!availableSensors.contains(sensor.getDeviceConfig().getClass())) {
|
||||
logger.warning("Sensor data plugin not available: " + sensor.getDeviceConfig().getClass());
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Registering new sensor(id: " + sensor.getId() + "): " + sensor.getDeviceConfig().getClass());
|
||||
Class<? extends HalAbstractController> c = sensor.getController();
|
||||
HalAbstractController controller = getControllerInstance(c);
|
||||
|
||||
if(controller != null)
|
||||
controller.register(sensor.getDeviceConfig());
|
||||
registeredSensors.add(sensor);
|
||||
detectedSensors.remove(findSensor(sensor.getDeviceConfig(), detectedSensors)); // Remove if this device was detected
|
||||
}
|
||||
|
||||
/**
|
||||
* Deregisters a Sensor from the manager.
|
||||
* Data reported on the Sensor will no longer be saved but already saved data will not be modified.
|
||||
* The Controller that owns the Sensor will be deallocated if it has no more registered devices.
|
||||
*/
|
||||
@Override
|
||||
public void deregister(Sensor sensor){
|
||||
if(sensor.getDeviceConfig() == null) {
|
||||
logger.warning("Sensor config is null: "+ sensor);
|
||||
return;
|
||||
}
|
||||
|
||||
Class<? extends HalAbstractController> c = sensor.getController();
|
||||
HalAbstractController controller = controllerMap.get(c);
|
||||
if (controller != null) {
|
||||
logger.info("Deregistering sensor(id: " + sensor.getId() + "): " + sensor.getDeviceConfig().getClass());
|
||||
controller.deregister(sensor.getDeviceConfig());
|
||||
registeredSensors.remove(sensor);
|
||||
removeControllerIfEmpty(controller);
|
||||
} else {
|
||||
logger.warning("Controller not instantiated: " + sensor.getController());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a Sensor class type as usable by the manager
|
||||
*/
|
||||
@Override
|
||||
public void addAvailableDevice(Class<? extends HalSensorConfig> sensorConfigClass) {
|
||||
if (!availableSensors.contains(sensorConfigClass))
|
||||
availableSensors.add(sensorConfigClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a List of all available Sensors that can be registered to this manager
|
||||
*/
|
||||
@Override
|
||||
public List<Class<? extends HalSensorConfig>> getAvailableDeviceConfigs(){
|
||||
return availableSensors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a List of Sensor instances that have been registered to this manager
|
||||
*/
|
||||
@Override
|
||||
public List<Sensor> getRegisteredDevices(){
|
||||
return registeredSensors;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return a List of Sensor instances that have been reported but not registered on the manager
|
||||
*/
|
||||
@Override
|
||||
public List<Sensor> getDetectedDevices(){
|
||||
return detectedSensors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all auto detected sensors.
|
||||
*/
|
||||
@Override
|
||||
public void clearDetectedDevices(){
|
||||
detectedSensors.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by Controllers to report received Sensor data
|
||||
*/
|
||||
@Override
|
||||
public void reportReceived(HalSensorConfig sensorConfig, HalSensorData sensorData) {
|
||||
try{
|
||||
DBConnection db = HalContext.getDB();
|
||||
Sensor sensor = findSensor(sensorConfig, registeredSensors);
|
||||
|
||||
if (sensor != null) {
|
||||
logger.finest("Received report from sensor(" + sensorConfig.getClass().getSimpleName() + "): " + sensorConfig);
|
||||
PreparedStatement stmt =
|
||||
db.getPreparedStatement("INSERT INTO sensor_data_raw (timestamp, sensor_id, data) VALUES(?, ?, ?)");
|
||||
stmt.setLong(1, sensorData.getTimestamp());
|
||||
stmt.setLong(2, sensor.getId());
|
||||
stmt.setDouble(3, sensorData.getData());
|
||||
DBConnection.exec(stmt);
|
||||
}
|
||||
else { // unknown sensor
|
||||
logger.finest("Received report from unregistered sensor" +
|
||||
"(" + sensorConfig.getClass().getSimpleName() + "): " + sensorConfig);
|
||||
sensor = findSensor(sensorConfig, detectedSensors);
|
||||
if(sensor == null) {
|
||||
sensor = new Sensor();
|
||||
detectedSensors.add(sensor);
|
||||
}
|
||||
sensor.setDeviceConfig(sensorConfig);
|
||||
}
|
||||
sensor.setDeviceData(sensorData);
|
||||
// call listeners
|
||||
for(HalDeviceReportListener<HalSensorConfig,HalSensorData> listener : sensor.getReportListeners())
|
||||
listener.reportReceived(sensorConfig, sensorData);
|
||||
|
||||
} catch (SQLException e){
|
||||
logger.log(Level.WARNING, "Unable to store sensor report", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Sensor findSensor(HalSensorConfig sensorData, List<Sensor> list){
|
||||
for (int i=0; i<list.size(); ++i) { // Don't use foreach for concurrency reasons
|
||||
Sensor s = list.get(i);
|
||||
if (sensorData.equals(s.getDeviceConfig())) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preConfigurationAction(Configurator configurator, Object obj) {
|
||||
if (obj instanceof HalSensorConfig) {
|
||||
Sensor sensor = findSensor((HalSensorConfig) obj, registeredSensors);
|
||||
if (sensor != null){
|
||||
deregister(sensor);
|
||||
limboSensors.add(sensor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postConfigurationAction(Configurator configurator, Object obj) {
|
||||
if (obj instanceof HalSensorConfig) {
|
||||
Sensor sensor = findSensor((HalSensorConfig) obj, limboSensors);
|
||||
if (sensor != null){
|
||||
register(sensor);
|
||||
limboSensors.remove(sensor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(PluginManager pluginManager){
|
||||
super.initialize(pluginManager);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public static SensorControllerManager getInstance(){
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package se.hal.action;
|
||||
|
||||
import se.hal.ControllerManager;
|
||||
import se.hal.EventControllerManager;
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalAction;
|
||||
import se.hal.intf.HalEventData;
|
||||
|
|
@ -30,11 +30,11 @@ public class SendEventAction implements HalAction {
|
|||
DBConnection db = HalContext.getDB();
|
||||
Event event = Event.getEvent(db, eventId);
|
||||
if (event != null) {
|
||||
HalEventData dataObj = event.getDeviceConfig().getEventDataClass().newInstance();
|
||||
HalEventData dataObj = (HalEventData) event.getDeviceConfig().getDeviceDataClass().newInstance();
|
||||
dataObj.setData(data);
|
||||
event.setDeviceData(dataObj);
|
||||
// Send
|
||||
ControllerManager.getInstance().send(event);
|
||||
EventControllerManager.getInstance().send(event);
|
||||
}
|
||||
else
|
||||
logger.warning("Unable to find event with id: "+ eventId);
|
||||
|
|
@ -49,7 +49,7 @@ public class SendEventAction implements HalAction {
|
|||
Event event = null;
|
||||
try{ event = Event.getEvent(db, eventId); } catch (Exception e){} //ignore exception
|
||||
return "Send event: "+ eventId +
|
||||
" ("+(event!=null ? event.getName() : null)+")" +
|
||||
" (" + (event!=null ? event.getName() : null) + ")" +
|
||||
" with data: "+ data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
package se.hal.intf;
|
||||
|
||||
|
||||
public interface HalAbstractController<C, L> {
|
||||
public interface HalAbstractController {
|
||||
|
||||
/**
|
||||
* The framework might create dummy objects so any type of
|
||||
|
|
@ -34,11 +34,27 @@ public interface HalAbstractController<C, L> {
|
|||
*/
|
||||
void initialize() throws Exception;
|
||||
|
||||
/**
|
||||
* Will register an device type to be handled by this controller
|
||||
*/
|
||||
void register(HalDeviceConfig deviceConfig);
|
||||
|
||||
/**
|
||||
* Deregisters an device from this controller, the controller
|
||||
* will no longer handle that type of event
|
||||
*/
|
||||
void deregister(HalDeviceConfig deviceConfig);
|
||||
|
||||
/**
|
||||
* @return the number of registered devices.
|
||||
*/
|
||||
int size();
|
||||
|
||||
/**
|
||||
* Set a listener that will receive all reports from the the registered devices
|
||||
*/
|
||||
void setListener(HalDeviceReportListener listener);
|
||||
|
||||
/**
|
||||
* Close any resources associated with this controller.
|
||||
* This method could be called multiple times, first time
|
||||
|
|
|
|||
158
hal-core/src/se/hal/intf/HalAbstractControllerManager.java
Normal file
158
hal-core/src/se/hal/intf/HalAbstractControllerManager.java
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
package se.hal.intf;
|
||||
|
||||
import se.hal.struct.AbstractDevice;
|
||||
import zutil.ClassUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.plugin.PluginManager;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <T> is the device controller class
|
||||
* @param <C> is the device configuration class
|
||||
*/
|
||||
public abstract class HalAbstractControllerManager<T extends HalAbstractController, V extends AbstractDevice, C extends HalDeviceConfig> {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
/** A map of all instantiated controllers **/
|
||||
protected HashMap<Class, T> controllerMap = new HashMap<>();
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Abstract methods
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* Register a device instance on the manager.
|
||||
* The manager will start to track and save reported data for the registered device.
|
||||
*/
|
||||
public abstract void register(V device);
|
||||
|
||||
/**
|
||||
* Deregisters a device from the manager.
|
||||
* Data reported on the device will no longer be saved but already saved data will not be modified.
|
||||
* The Controller that owns the device will be deallocated if it has no more registered devices.
|
||||
*/
|
||||
public abstract void deregister(V device);
|
||||
|
||||
/**
|
||||
* Registers a device configuration class type as usable by the manager
|
||||
*/
|
||||
public abstract void addAvailableDevice(Class<? extends C> deviceConfigClass);
|
||||
|
||||
/**
|
||||
* @return a List of all available devices that can be registered with this manager
|
||||
*/
|
||||
public abstract List<Class<? extends C>> getAvailableDeviceConfigs();
|
||||
|
||||
/**
|
||||
* @return a List of device instances that have been registered on this manager
|
||||
*/
|
||||
public abstract List<V> getRegisteredDevices();
|
||||
|
||||
/**
|
||||
* @return a List of device instances that have reported data but have not yet been registered on the manager
|
||||
*/
|
||||
public abstract List<V> getDetectedDevices();
|
||||
|
||||
/**
|
||||
* Removes all auto detected devices.
|
||||
*/
|
||||
public abstract void clearDetectedDevices();
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Common Logic
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* @return all active instantiated controllers.
|
||||
*/
|
||||
public Collection<T> getControllers() {
|
||||
return controllerMap.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return a singleton controller instance of the given class.
|
||||
* If a instance does not exist yet the a new instance will be allocated
|
||||
* depending on if the controller is ready thorough the {@link HalAutoScannableController#isAvailable()} method.
|
||||
*
|
||||
* @param clazz is the class of the wanted object instance wanted
|
||||
* @return A singleton instance of the input clazz or null if the class is unavailable or not ready to be instantiated.
|
||||
*/
|
||||
protected T getControllerInstance(Class<? extends T> clazz){
|
||||
T controller;
|
||||
|
||||
if (controllerMap.containsKey(clazz)) {
|
||||
controller = controllerMap.get(clazz);
|
||||
} else {
|
||||
try {
|
||||
// Instantiate controller
|
||||
controller = clazz.newInstance();
|
||||
|
||||
if (controller instanceof HalAutoScannableController &&
|
||||
! ((HalAutoScannableController) controller).isAvailable()) {
|
||||
logger.warning("Controller is not ready: " + clazz.getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
logger.info("Instantiating new controller: " + clazz.getName());
|
||||
controller.initialize();
|
||||
|
||||
if (this instanceof HalDeviceReportListener)
|
||||
controller.setListener((HalDeviceReportListener)this);
|
||||
|
||||
controllerMap.put(clazz, controller);
|
||||
} catch (Exception e){
|
||||
logger.log(Level.SEVERE, "Unable to instantiate controller: " + clazz.getName(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will check if a controller no longer has any managed devices,
|
||||
* in that case the controller will be deallocated.
|
||||
*
|
||||
* @param controller is the controller instance.
|
||||
*/
|
||||
protected void removeControllerIfEmpty(HalAbstractController controller){
|
||||
if (controller instanceof HalAutoScannableController)
|
||||
return; // Don't do anything if controller is scannable
|
||||
|
||||
if (controller.size() < 0){
|
||||
// Remove controller as it has no more registered sensors
|
||||
logger.info("Closing controller as it has no more registered devices: " + controller.getClass().getName());
|
||||
controllerMap.remove(controller.getClass());
|
||||
|
||||
controller.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Will instantiate a generic ControllerManager.
|
||||
*
|
||||
* @param pluginManager a PluginManager instance that will be used to find Controller plugins.
|
||||
*/
|
||||
public void initialize(PluginManager pluginManager) {
|
||||
Class[] genericClasses = ClassUtil.getGenericClasses(HalAbstractControllerManager.class);
|
||||
|
||||
if (genericClasses.length >= 1 && genericClasses[0] != null) {
|
||||
for (Iterator<Class<C>> it = pluginManager.getClassIterator(genericClasses[0]); it.hasNext(); ) {
|
||||
addAvailableDevice(it.next());
|
||||
}
|
||||
} else {
|
||||
logger.severe("Unable to retrieve Controller class from generics.");
|
||||
}
|
||||
|
||||
for (Iterator<Class<? extends HalAutoScannableController>> it = pluginManager.getClassIterator(HalAutoScannableController.class); it.hasNext(); ){
|
||||
Class controller = it.next();
|
||||
getControllerInstance(controller); // Instantiate controller
|
||||
}
|
||||
}
|
||||
}
|
||||
21
hal-core/src/se/hal/intf/HalDeviceConfig.java
Normal file
21
hal-core/src/se/hal/intf/HalDeviceConfig.java
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package se.hal.intf;
|
||||
|
||||
/**
|
||||
* Interface representing a generic device configuration data.
|
||||
*/
|
||||
public interface HalDeviceConfig {
|
||||
|
||||
Class<? extends HalAbstractController> getDeviceControllerClass();
|
||||
|
||||
/**
|
||||
* @return the class that should be instantiated and used for data received from this event
|
||||
*/
|
||||
Class<? extends HalDeviceData> getDeviceDataClass();
|
||||
|
||||
/**
|
||||
* This method needs to be implemented.
|
||||
* NOTE: it should not compare data and timestamp, only static or unique data for the event type.
|
||||
*/
|
||||
boolean equals(Object obj);
|
||||
|
||||
}
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
package se.hal.intf;
|
||||
|
||||
import se.hal.struct.AbstractDevice;
|
||||
|
||||
/**
|
||||
* A listener interface that will be called when the
|
||||
* Event or Sensor that it is registered to receives a report
|
||||
*
|
||||
* @param <T> is the device type
|
||||
* @param <C> is the device configuration class
|
||||
* @param <D> is the device data class
|
||||
*/
|
||||
public interface HalDeviceReportListener<T extends AbstractDevice> {
|
||||
public interface HalDeviceReportListener<C extends HalDeviceConfig, D extends HalDeviceData> {
|
||||
|
||||
void receivedReport(T device);
|
||||
void reportReceived(C deviceConfig, D deviceData);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,19 +3,6 @@ package se.hal.intf;
|
|||
/**
|
||||
* Interface representing event type specific configuration data.
|
||||
*/
|
||||
public interface HalEventConfig {
|
||||
|
||||
Class<? extends HalEventController> getEventControllerClass();
|
||||
|
||||
/**
|
||||
* @return the class that should be instantiated and used for data received from this event
|
||||
*/
|
||||
Class<? extends HalEventData> getEventDataClass();
|
||||
|
||||
/**
|
||||
* This method needs to be implemented.
|
||||
* NOTE: it should not compare data and timestamp, only static or unique data for the event type.
|
||||
*/
|
||||
boolean equals(Object obj);
|
||||
public interface HalEventConfig extends HalDeviceConfig {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,25 +5,9 @@ package se.hal.intf;
|
|||
*/
|
||||
public interface HalEventController extends HalAbstractController {
|
||||
|
||||
/**
|
||||
* Will register an event type to be handled by this controller
|
||||
*/
|
||||
void register(HalEventConfig eventConfig);
|
||||
|
||||
/**
|
||||
* Deregisters an event from this controller, the controller
|
||||
* will no longer handle that type of event
|
||||
*/
|
||||
void deregister(HalEventConfig eventConfig);
|
||||
|
||||
/**
|
||||
* @param eventConfig the event configuration to target when sending
|
||||
* @param eventData the data to send
|
||||
*/
|
||||
void send(HalEventConfig eventConfig, HalEventData eventData);
|
||||
|
||||
/**
|
||||
* Set a listener that will receive all reports from the the registered Events
|
||||
*/
|
||||
void setListener(HalEventReportListener listener);
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package se.hal.intf;
|
||||
|
||||
/**
|
||||
* Listener to be called by the {@link HalEventController} to report that a event has been received.
|
||||
*/
|
||||
public interface HalEventReportListener {
|
||||
|
||||
void reportReceived(HalEventConfig e, HalEventData d);
|
||||
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ package se.hal.intf;
|
|||
/**
|
||||
* Interface representing sensor type specific configuration data.
|
||||
*/
|
||||
public interface HalSensorConfig {
|
||||
public interface HalSensorConfig extends HalDeviceConfig {
|
||||
enum AggregationMethod{
|
||||
SUM,
|
||||
AVERAGE
|
||||
|
|
@ -19,21 +19,4 @@ public interface HalSensorConfig {
|
|||
* @return which aggregation method that should be used to aggregate the reported data.
|
||||
*/
|
||||
AggregationMethod getAggregationMethod();
|
||||
|
||||
|
||||
/**
|
||||
* @return the Controller class where SensorData should be registered on
|
||||
*/
|
||||
Class<? extends HalSensorController> getSensorControllerClass();
|
||||
|
||||
/**
|
||||
* @return the class that should be instantiated and used for data received from this sensor
|
||||
*/
|
||||
Class<? extends HalSensorData> getSensorDataClass();
|
||||
|
||||
/**
|
||||
* NOTE: it should only static or unique data for the sensor type.
|
||||
* This method is used to associate reported data with registered sensors
|
||||
*/
|
||||
boolean equals(Object obj);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,19 +5,4 @@ package se.hal.intf;
|
|||
*/
|
||||
public interface HalSensorController extends HalAbstractController {
|
||||
|
||||
/**
|
||||
* Will register a sensor type to be handled by this controller
|
||||
*/
|
||||
void register(HalSensorConfig sensorConfig);
|
||||
|
||||
/**
|
||||
* Deregisters a sensor from this controller, the controller
|
||||
* will no longer handle that type of sensor
|
||||
*/
|
||||
void deregister(HalSensorConfig sensorConfig);
|
||||
|
||||
/**
|
||||
* Set a listener that will receive all reports from the the registered Sensors
|
||||
*/
|
||||
void setListener(HalSensorReportListener listener);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
package se.hal.intf;
|
||||
|
||||
/**
|
||||
* Listener to be called by the {@link HalSensorController} to report that sensor data has been received.
|
||||
*/
|
||||
public interface HalSensorReportListener {
|
||||
|
||||
void reportReceived(HalSensorConfig s, HalSensorData d);
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package se.hal.page;
|
||||
|
||||
import se.hal.ControllerManager;
|
||||
import se.hal.EventControllerManager;
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalWebPage;
|
||||
import se.hal.struct.ClassConfigurationData;
|
||||
|
|
@ -30,7 +30,7 @@ public class EventConfigWebPage extends HalWebPage {
|
|||
super.getRootNav().createSubNav("Settings").createSubNav(this.getId(), "Event Settings").setWeight(200);
|
||||
|
||||
eventConfigurations = new ArrayList<>();
|
||||
for(Class c : ControllerManager.getInstance().getAvailableEvents())
|
||||
for(Class c : EventControllerManager.getInstance().getAvailableDeviceConfigs())
|
||||
eventConfigurations.add(new ClassConfigurationData(c));
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ public class EventConfigWebPage extends HalWebPage {
|
|||
event.setUser(localUser);
|
||||
event.getDeviceConfigurator().setValues(request).applyConfiguration();
|
||||
event.save(db);
|
||||
ControllerManager.getInstance().register(event);
|
||||
EventControllerManager.getInstance().register(event);
|
||||
|
||||
HalAlertManager.getInstance().addAlert(new UserMessage(
|
||||
MessageLevel.SUCCESS, "Successfully created new event: " + event.getName(), MessageTTL.ONE_VIEW));
|
||||
|
|
@ -88,7 +88,7 @@ public class EventConfigWebPage extends HalWebPage {
|
|||
event = Event.getEvent(db, id);
|
||||
if (event != null) {
|
||||
logger.info("Removing event: " + event.getName());
|
||||
ControllerManager.getInstance().deregister(event);
|
||||
EventControllerManager.getInstance().deregister(event);
|
||||
event.delete(db);
|
||||
|
||||
HalAlertManager.getInstance().addAlert(new UserMessage(
|
||||
|
|
@ -101,7 +101,7 @@ public class EventConfigWebPage extends HalWebPage {
|
|||
break;
|
||||
|
||||
case "remove_all_detected_events":
|
||||
ControllerManager.getInstance().clearDetectedEvents();
|
||||
EventControllerManager.getInstance().clearDetectedDevices();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -111,8 +111,8 @@ public class EventConfigWebPage extends HalWebPage {
|
|||
tmpl.set("user", localUser);
|
||||
tmpl.set("localEvents", Event.getLocalEvents(db));
|
||||
tmpl.set("localEventConf", eventConfigurations);
|
||||
tmpl.set("detectedEvents", ControllerManager.getInstance().getDetectedEvents());
|
||||
tmpl.set("availableEvents", ControllerManager.getInstance().getAvailableEvents());
|
||||
tmpl.set("detectedEvents", EventControllerManager.getInstance().getDetectedDevices());
|
||||
tmpl.set("availableEvents", EventControllerManager.getInstance().getAvailableDeviceConfigs());
|
||||
|
||||
return tmpl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package se.hal.page;
|
||||
|
||||
import se.hal.ControllerManager;
|
||||
import se.hal.EventControllerManager;
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalWebPage;
|
||||
import se.hal.struct.Event;
|
||||
|
|
@ -54,7 +54,7 @@ public class EventOverviewWebPage extends HalWebPage {
|
|||
logger.info("Modifying Event(" + id + ") state: " + eventData.toString());
|
||||
Event event = Event.getEvent(db, id);
|
||||
event.setDeviceData(eventData);
|
||||
ControllerManager.getInstance().send(event);
|
||||
EventControllerManager.getInstance().send(event);
|
||||
}
|
||||
|
||||
int id = (ObjectUtil.isEmpty(request.get("id")) ? -1 : Integer.parseInt(request.get("id")));
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
package se.hal.page;
|
||||
|
||||
import se.hal.ControllerManager;
|
||||
import se.hal.HalContext;
|
||||
import se.hal.HalServer;
|
||||
import se.hal.intf.HalWebPage;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.parser.Templator;
|
||||
import zutil.ui.UserMessageManager;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static zutil.ui.UserMessageManager.*;
|
||||
|
||||
|
||||
public class PluginConfigWebPage extends HalWebPage {
|
||||
private static final String TEMPLATE = HalContext.RESOURCE_WEB_ROOT + "/plugin_config.tmpl";
|
||||
|
||||
|
|
@ -39,7 +38,7 @@ public class PluginConfigWebPage extends HalWebPage {
|
|||
|
||||
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
|
||||
tmpl.set("plugins", HalServer.getAllPlugins());
|
||||
tmpl.set("controllers", ControllerManager.getInstance().getControllers());
|
||||
//tmpl.set("controllers", ControllerManager.getInstance().getControllers()); // TODO: Get all controllers
|
||||
return tmpl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package se.hal.page;
|
||||
|
||||
import se.hal.ControllerManager;
|
||||
import se.hal.HalContext;
|
||||
import se.hal.SensorControllerManager;
|
||||
import se.hal.intf.HalWebPage;
|
||||
import se.hal.struct.ClassConfigurationData;
|
||||
import se.hal.struct.Sensor;
|
||||
|
|
@ -18,6 +18,7 @@ import java.util.logging.Logger;
|
|||
|
||||
import static zutil.ui.UserMessageManager.*;
|
||||
|
||||
|
||||
public class SensorConfigWebPage extends HalWebPage {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
private static final String TEMPLATE = HalContext.RESOURCE_WEB_ROOT + "/sensor_config.tmpl";
|
||||
|
|
@ -30,7 +31,7 @@ public class SensorConfigWebPage extends HalWebPage {
|
|||
super.getRootNav().createSubNav("Settings").createSubNav(this.getId(), "Sensor Settings").setWeight(100);
|
||||
|
||||
sensorConfigurations = new ArrayList<>();
|
||||
for(Class c : ControllerManager.getInstance().getAvailableSensors())
|
||||
for(Class c : SensorControllerManager.getInstance().getAvailableDeviceConfigs())
|
||||
sensorConfigurations.add(new ClassConfigurationData(c));
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +62,7 @@ public class SensorConfigWebPage extends HalWebPage {
|
|||
sensor.setUser(localUser);
|
||||
sensor.getDeviceConfigurator().setValues(request).applyConfiguration();
|
||||
sensor.save(db);
|
||||
ControllerManager.getInstance().register(sensor);
|
||||
SensorControllerManager.getInstance().register(sensor);
|
||||
|
||||
HalAlertManager.getInstance().addAlert(new UserMessage(
|
||||
MessageLevel.SUCCESS, "Successfully created new sensor: "+sensor.getName(), MessageTTL.ONE_VIEW));
|
||||
|
|
@ -90,7 +91,7 @@ public class SensorConfigWebPage extends HalWebPage {
|
|||
sensor = Sensor.getSensor(db, id);
|
||||
if(sensor != null) {
|
||||
logger.warning("Removing sensor: " + sensor.getName());
|
||||
ControllerManager.getInstance().deregister(sensor);
|
||||
SensorControllerManager.getInstance().deregister(sensor);
|
||||
sensor.delete(db);
|
||||
|
||||
HalAlertManager.getInstance().addAlert(new UserMessage(
|
||||
|
|
@ -103,7 +104,7 @@ public class SensorConfigWebPage extends HalWebPage {
|
|||
break;
|
||||
|
||||
case "remove_all_detected_sensors":
|
||||
ControllerManager.getInstance().clearDetectedSensors();
|
||||
SensorControllerManager.getInstance().clearDetectedDevices();
|
||||
break;
|
||||
|
||||
// External Users
|
||||
|
|
@ -174,10 +175,10 @@ public class SensorConfigWebPage extends HalWebPage {
|
|||
tmpl.set("user", localUser);
|
||||
tmpl.set("localSensors", Sensor.getLocalSensors(db));
|
||||
tmpl.set("localSensorConf", sensorConfigurations);
|
||||
tmpl.set("detectedSensors", ControllerManager.getInstance().getDetectedSensors());
|
||||
tmpl.set("detectedSensors", SensorControllerManager.getInstance().getDetectedDevices());
|
||||
tmpl.set("extUsers", User.getExternalUsers(db));
|
||||
tmpl.set("extSensor", Sensor.getExternalSensors(db));
|
||||
tmpl.set("availableSensors", ControllerManager.getInstance().getAvailableSensors());
|
||||
tmpl.set("availableSensors", SensorControllerManager.getInstance().getAvailableDeviceConfigs());
|
||||
|
||||
return tmpl;
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class SensorJsonPage extends HalJsonPage {
|
|||
else if (req_ids != null && ArrayUtil.contains(req_ids, ""+sensor.getId())) // id filtering
|
||||
sensors.add(sensor);
|
||||
else if (req_type != null && !req_type.isEmpty() &&
|
||||
sensor.getDeviceConfig().getSensorDataClass().getSimpleName().contains(req_type)) // device type filtering
|
||||
sensor.getDeviceConfig().getDeviceDataClass().getSimpleName().contains(req_type)) // device type filtering
|
||||
sensors.add(sensor);
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ public class SensorJsonPage extends HalJsonPage {
|
|||
deviceNode.set("id", sensor.getId());
|
||||
deviceNode.set("name", sensor.getName());
|
||||
deviceNode.set("user", sensor.getUser().getUsername());
|
||||
deviceNode.set("type", sensor.getDeviceConfig().getSensorDataClass().getSimpleName());
|
||||
deviceNode.set("type", sensor.getDeviceConfig().getDeviceDataClass().getSimpleName());
|
||||
deviceNode.set("x", sensor.getX());
|
||||
deviceNode.set("y", sensor.getY());
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
"name": "Hal-Core",
|
||||
"description": "Plugin contains core logic for running Hal.",
|
||||
"interfaces": [
|
||||
{"se.hal.intf.HalAbstractControllerManager": "se.hal.EventControllerManager"},
|
||||
{"se.hal.intf.HalAbstractControllerManager": "se.hal.SensorControllerManager"},
|
||||
|
||||
{"se.hal.intf.HalDaemon": "se.hal.daemon.SensorDataAggregatorDaemon"},
|
||||
{"se.hal.intf.HalDaemon": "se.hal.daemon.SensorDataCleanupDaemon"},
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package se.hal.struct;
|
||||
|
||||
import se.hal.ControllerManager;
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalAbstractController;
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalDeviceData;
|
||||
import se.hal.intf.HalDeviceReportListener;
|
||||
import zutil.db.DBConnection;
|
||||
|
|
@ -21,11 +21,11 @@ import java.util.logging.Logger;
|
|||
/**
|
||||
* Contains logic and data common to devices (Events and Sensors)
|
||||
*
|
||||
* @param <T> is the device type
|
||||
* @param <V> is the device type
|
||||
* @param <C> is the device configuration class
|
||||
* @param <D> is the device data class
|
||||
*/
|
||||
public abstract class AbstractDevice<T extends AbstractDevice, C,D extends HalDeviceData> extends DBBean {
|
||||
public abstract class AbstractDevice<V extends AbstractDevice,C extends HalDeviceConfig,D extends HalDeviceData> extends DBBean {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
// Sensor specific data
|
||||
|
|
@ -48,7 +48,7 @@ public abstract class AbstractDevice<T extends AbstractDevice, C,D extends HalDe
|
|||
@DBColumn("map_y")
|
||||
private double y;
|
||||
|
||||
protected transient List<HalDeviceReportListener<T>> listeners = new LinkedList<>();
|
||||
protected transient List<HalDeviceReportListener<C,D>> listeners = new LinkedList<>();
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
|
|
@ -59,8 +59,8 @@ public abstract class AbstractDevice<T extends AbstractDevice, C,D extends HalDe
|
|||
C obj = getDeviceConfig();
|
||||
if (obj != null) {
|
||||
Configurator<C> configurator = new Configurator<>(obj);
|
||||
configurator.setPreConfigurationListener(ControllerManager.getInstance());
|
||||
configurator.setPostConfigurationListener(ControllerManager.getInstance());
|
||||
//configurator.setPreConfigurationListener(ControllerManager.getInstance()); // TODO:
|
||||
//configurator.setPostConfigurationListener(ControllerManager.getInstance()); // TODO:
|
||||
return configurator;
|
||||
}
|
||||
return null;
|
||||
|
|
@ -118,7 +118,7 @@ public abstract class AbstractDevice<T extends AbstractDevice, C,D extends HalDe
|
|||
* This method will configure the current DeviceData with the
|
||||
* configuration from the config String.
|
||||
*/
|
||||
private void applyConfig(){
|
||||
private void applyConfig() {
|
||||
if (config != null && !config.isEmpty()) {
|
||||
Configurator<C> configurator = getDeviceConfigurator();
|
||||
configurator.setValues(JSONParser.read(config));
|
||||
|
|
@ -135,11 +135,11 @@ public abstract class AbstractDevice<T extends AbstractDevice, C,D extends HalDe
|
|||
/**
|
||||
* @return the latest known data from the device
|
||||
*/
|
||||
public D getDeviceData(){
|
||||
public D getDeviceData() {
|
||||
return deviceData;
|
||||
}
|
||||
|
||||
public void setDeviceData(D latest){
|
||||
public void setDeviceData(D latest) {
|
||||
this.deviceData = latest;
|
||||
}
|
||||
|
||||
|
|
@ -198,13 +198,13 @@ public abstract class AbstractDevice<T extends AbstractDevice, C,D extends HalDe
|
|||
this.y = y;
|
||||
}
|
||||
|
||||
public void addReportListener(HalDeviceReportListener<T> listener){
|
||||
public void addReportListener(HalDeviceReportListener<C,D> listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
public void removeReportListener(HalDeviceReportListener<T> listener){
|
||||
public void removeReportListener(HalDeviceReportListener<C,D> listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
public List<HalDeviceReportListener<T>> getReportListeners(){
|
||||
public List<HalDeviceReportListener<C,D>> getReportListeners() {
|
||||
return listeners;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,20 @@
|
|||
package se.hal.struct;
|
||||
|
||||
import se.hal.intf.HalDeviceData;
|
||||
import se.hal.intf.HalEventController;
|
||||
import se.hal.intf.HalEventConfig;
|
||||
import se.hal.intf.HalEventData;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.util.DeviceDataSqlResult;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.db.SQLResultHandler;
|
||||
import zutil.db.bean.DBBean;
|
||||
import zutil.db.bean.DBBeanSQLResultHandler;
|
||||
import zutil.db.handler.SimpleSQLResult;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@DBBean.DBTable(value="event", superBean=true)
|
||||
public class Event extends AbstractDevice<Event, HalEventConfig,HalEventData>{
|
||||
public class Event extends AbstractDevice<Event,HalEventConfig,HalEventData> {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
|
||||
|
|
@ -39,13 +32,13 @@ public class Event extends AbstractDevice<Event, HalEventConfig,HalEventData>{
|
|||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getController(){
|
||||
return getDeviceConfig().getEventControllerClass();
|
||||
return (Class<? extends HalEventController>) getDeviceConfig().getDeviceControllerClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HalEventData getLatestDeviceData(DBConnection db) {
|
||||
try {
|
||||
Class deviceDataClass = getDeviceConfig().getEventDataClass();
|
||||
Class deviceDataClass = getDeviceConfig().getDeviceDataClass();
|
||||
if (deviceDataClass == null)
|
||||
throw new ClassNotFoundException("Unknown event data class for: " + getDeviceConfig().getClass());
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
package se.hal.struct;
|
||||
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalDeviceReportListener;
|
||||
import se.hal.intf.HalSensorController;
|
||||
import se.hal.intf.HalAbstractController;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.intf.HalSensorData;
|
||||
import se.hal.util.DeviceDataSqlResult;
|
||||
|
|
@ -20,7 +19,7 @@ import java.util.logging.Logger;
|
|||
|
||||
|
||||
@DBBean.DBTable(value="sensor", superBean=true)
|
||||
public class Sensor extends AbstractDevice<Sensor, HalSensorConfig,HalSensorData>{
|
||||
public class Sensor extends AbstractDevice<Sensor,HalSensorConfig,HalSensorData> {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
private long external_id = -1;
|
||||
|
|
@ -111,14 +110,14 @@ public class Sensor extends AbstractDevice<Sensor, HalSensorConfig,HalSensorData
|
|||
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getController(){
|
||||
return getDeviceConfig().getSensorControllerClass();
|
||||
public Class<? extends HalAbstractController> getController(){
|
||||
return (Class<? extends HalAbstractController>) getDeviceConfig().getDeviceControllerClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HalSensorData getLatestDeviceData(DBConnection db) {
|
||||
try {
|
||||
Class deviceDataClass = getDeviceConfig().getSensorDataClass();
|
||||
Class deviceDataClass = getDeviceConfig().getDeviceDataClass();
|
||||
if (deviceDataClass == null)
|
||||
throw new ClassNotFoundException("Unknown sensor data class for: " + getDeviceConfig().getClass());
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package se.hal.trigger;
|
||||
|
||||
import se.hal.TriggerManager;
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalDeviceData;
|
||||
import se.hal.intf.HalDeviceReportListener;
|
||||
import se.hal.intf.HalTrigger;
|
||||
|
|
@ -14,7 +15,8 @@ import zutil.ui.Configurator.PreConfigurationActionListener;
|
|||
*/
|
||||
public abstract class DeviceTrigger implements HalTrigger,
|
||||
PreConfigurationActionListener,
|
||||
PostConfigurationActionListener, HalDeviceReportListener<AbstractDevice> {
|
||||
PostConfigurationActionListener,
|
||||
HalDeviceReportListener<HalDeviceConfig,HalDeviceData> {
|
||||
|
||||
@Configurator.Configurable("Device ID")
|
||||
protected int deviceId = -1;
|
||||
|
|
@ -42,8 +44,8 @@ public abstract class DeviceTrigger implements HalTrigger,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void receivedReport(AbstractDevice device) {
|
||||
receivedData = device.getDeviceData();
|
||||
public void reportReceived(HalDeviceConfig deviceConfig, HalDeviceData deviceData) {
|
||||
receivedData = deviceData;
|
||||
// Instant trigger evaluation
|
||||
if (triggerOnChange)
|
||||
TriggerManager.getInstance().evaluateAndExecute();
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public class AggregateDataListSqlResult implements SQLResultHandler<ArrayList<Ag
|
|||
list.add(new AggregateData(id, previousTimestampEnd + 1, null /*Float.NaN*/, username));
|
||||
}
|
||||
|
||||
if (sensor.getDeviceConfig().getSensorDataClass() == PowerConsumptionSensorData.class)
|
||||
if (sensor.getDeviceConfig().getDeviceDataClass() == PowerConsumptionSensorData.class)
|
||||
estimatedData = (estimatedData/1000f);
|
||||
list.add(new AggregateData(id, timestampEnd, estimatedData, username)); //add this data point to list
|
||||
|
||||
|
|
|
|||
|
|
@ -13,51 +13,51 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
public class EventControllerManagerTest {
|
||||
|
||||
private ControllerManager manager = new ControllerManager();
|
||||
private EventControllerManager manager = new EventControllerManager();
|
||||
|
||||
|
||||
@Test
|
||||
public void addAvailableEvent(){
|
||||
assertEquals(0, manager.getAvailableEvents().size());
|
||||
public void addAvailableEventDevice(){
|
||||
assertEquals(0, manager.getAvailableDeviceConfigs().size());
|
||||
|
||||
manager.addAvailableEvent(TestEvent1.class);
|
||||
assertEquals(1, manager.getAvailableEvents().size());
|
||||
assertTrue(manager.getAvailableEvents().contains(TestEvent1.class));
|
||||
manager.addAvailableDevice(TestEvent1.class);
|
||||
assertEquals(1, manager.getAvailableDeviceConfigs().size());
|
||||
assertTrue(manager.getAvailableDeviceConfigs().contains(TestEvent1.class));
|
||||
|
||||
manager.addAvailableEvent(TestEvent2.class);
|
||||
assertEquals(2, manager.getAvailableEvents().size());
|
||||
assertTrue(manager.getAvailableEvents().contains(TestEvent1.class));
|
||||
assertTrue(manager.getAvailableEvents().contains(TestEvent2.class));
|
||||
manager.addAvailableDevice(TestEvent2.class);
|
||||
assertEquals(2, manager.getAvailableDeviceConfigs().size());
|
||||
assertTrue(manager.getAvailableDeviceConfigs().contains(TestEvent1.class));
|
||||
assertTrue(manager.getAvailableDeviceConfigs().contains(TestEvent2.class));
|
||||
|
||||
// Add duplicate Event
|
||||
manager.addAvailableEvent(TestEvent1.class);
|
||||
assertEquals("No duplicate check",2, manager.getAvailableEvents().size());
|
||||
manager.addAvailableDevice(TestEvent1.class);
|
||||
assertEquals("No duplicate check",2, manager.getAvailableDeviceConfigs().size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void registerUnavailableEvent(){
|
||||
assertEquals(Collections.EMPTY_LIST, manager.getAvailableEvents());
|
||||
assertEquals(Collections.EMPTY_LIST, manager.getAvailableDeviceConfigs());
|
||||
|
||||
Event Event = new Event();
|
||||
Event.setDeviceConfig(new TestEvent1());
|
||||
manager.register(Event);
|
||||
assertEquals("No Event registered", Collections.EMPTY_LIST, manager.getRegisteredEvents());
|
||||
assertEquals("No Event registered", Collections.EMPTY_LIST, manager.getRegisteredDevices());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void registerOneEvent() {
|
||||
Event Event1 = registerEvent(new TestEvent1());
|
||||
assertEquals(1, manager.getRegisteredEvents().size());
|
||||
assertTrue(manager.getRegisteredEvents().contains(Event1));
|
||||
assertEquals(1, manager.getRegisteredDevices().size());
|
||||
assertTrue(manager.getRegisteredDevices().contains(Event1));
|
||||
}
|
||||
public void registerTwoEvents(){
|
||||
Event Event1 = registerEvent(new TestEvent1());
|
||||
Event Event2 = registerEvent(new TestEvent2());
|
||||
assertEquals(2, manager.getRegisteredEvents().size());
|
||||
assertTrue(manager.getRegisteredEvents().contains(Event1));
|
||||
assertTrue(manager.getRegisteredEvents().contains(Event2));
|
||||
assertEquals(2, manager.getRegisteredDevices().size());
|
||||
assertTrue(manager.getRegisteredDevices().contains(Event1));
|
||||
assertTrue(manager.getRegisteredDevices().contains(Event2));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ public class EventControllerManagerTest {
|
|||
public void deregisterEvent(){
|
||||
Event Event1 = registerEvent(new TestEvent1());
|
||||
manager.deregister(Event1);
|
||||
assertEquals(Collections.EMPTY_LIST, manager.getRegisteredEvents());
|
||||
assertEquals(Collections.EMPTY_LIST, manager.getRegisteredDevices());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ public class EventControllerManagerTest {
|
|||
private Event registerEvent(HalEventConfig config){
|
||||
Event Event = new Event();
|
||||
Event.setDeviceConfig(config);
|
||||
manager.addAvailableEvent(config.getClass());
|
||||
manager.addAvailableDevice(config.getClass());
|
||||
manager.register(Event);
|
||||
return Event;
|
||||
}
|
||||
|
|
@ -84,12 +84,12 @@ public class EventControllerManagerTest {
|
|||
public static class TestEvent1 implements HalEventConfig {
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getEventControllerClass() {
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() {
|
||||
return TestController.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventData> getEventDataClass() {
|
||||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
}
|
||||
|
|
@ -97,12 +97,12 @@ public class EventControllerManagerTest {
|
|||
public static class TestEvent2 implements HalEventConfig {
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getEventControllerClass() {
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() {
|
||||
return TestController.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventData> getEventDataClass() {
|
||||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ public class EventControllerManagerTest {
|
|||
int size;
|
||||
|
||||
@Override
|
||||
public void initialize() throws Exception { }
|
||||
public void initialize() { }
|
||||
|
||||
@Override
|
||||
public void register(HalEventConfig event) {
|
||||
|
|
@ -134,7 +134,7 @@ public class EventControllerManagerTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setListener(HalEventReportListener listener) { }
|
||||
public void setListener(HalDeviceReportListener listener) { }
|
||||
|
||||
@Override
|
||||
public void close() { }
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
package se.hal;
|
||||
|
||||
import org.junit.Test;
|
||||
import se.hal.intf.HalAbstractController;
|
||||
import se.hal.intf.HalDeviceReportListener;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.intf.HalSensorController;
|
||||
import se.hal.intf.HalSensorData;
|
||||
import se.hal.intf.HalSensorReportListener;
|
||||
import se.hal.struct.Sensor;
|
||||
import se.hal.struct.devicedata.HumiditySensorData;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
|
|
@ -16,52 +17,52 @@ import static org.junit.Assert.*;
|
|||
|
||||
public class SensorControllerManagerTest {
|
||||
|
||||
private ControllerManager manager = new ControllerManager();
|
||||
private SensorControllerManager manager = new SensorControllerManager();
|
||||
|
||||
|
||||
@Test
|
||||
public void addAvailableSensor(){
|
||||
assertEquals(Collections.EMPTY_LIST, manager.getAvailableSensors());
|
||||
public void addAvailableDevice(){
|
||||
assertEquals(Collections.EMPTY_LIST, manager.getAvailableDeviceConfigs());
|
||||
|
||||
manager.addAvailableSensor(TestSensor1.class);
|
||||
assertEquals(1, manager.getAvailableSensors().size());
|
||||
assertTrue(manager.getAvailableSensors().contains(TestSensor1.class));
|
||||
manager.addAvailableDevice(TestSensor1.class);
|
||||
assertEquals(1, manager.getAvailableDeviceConfigs().size());
|
||||
assertTrue(manager.getAvailableDeviceConfigs().contains(TestSensor1.class));
|
||||
|
||||
manager.addAvailableSensor(TestSensor2.class);
|
||||
assertEquals(2, manager.getAvailableSensors().size());
|
||||
assertTrue(manager.getAvailableSensors().contains(TestSensor1.class));
|
||||
assertTrue(manager.getAvailableSensors().contains(TestSensor2.class));
|
||||
manager.addAvailableDevice(TestSensor2.class);
|
||||
assertEquals(2, manager.getAvailableDeviceConfigs().size());
|
||||
assertTrue(manager.getAvailableDeviceConfigs().contains(TestSensor1.class));
|
||||
assertTrue(manager.getAvailableDeviceConfigs().contains(TestSensor2.class));
|
||||
|
||||
// Add duplicate sensor
|
||||
manager.addAvailableSensor(TestSensor1.class);
|
||||
assertEquals("No duplicate check",2, manager.getAvailableSensors().size());
|
||||
manager.addAvailableDevice(TestSensor1.class);
|
||||
assertEquals("No duplicate check",2, manager.getAvailableDeviceConfigs().size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void registerUnavailableSensor(){
|
||||
assertEquals(Collections.EMPTY_LIST, manager.getAvailableSensors());
|
||||
assertEquals(Collections.EMPTY_LIST, manager.getAvailableDeviceConfigs());
|
||||
|
||||
Sensor sensor = new Sensor();
|
||||
sensor.setDeviceConfig(new TestSensor1());
|
||||
manager.register(sensor);
|
||||
assertEquals("No Sensor registered", Collections.EMPTY_LIST, manager.getRegisteredSensors());
|
||||
assertEquals("No Sensor registered", Collections.EMPTY_LIST, manager.getRegisteredDevices());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void registerOneSensor() {
|
||||
Sensor sensor1 = registerSensor(new TestSensor1());
|
||||
assertEquals(1, manager.getRegisteredSensors().size());
|
||||
assertTrue(manager.getRegisteredSensors().contains(sensor1));
|
||||
assertEquals(1, manager.getRegisteredDevices().size());
|
||||
assertTrue(manager.getRegisteredDevices().contains(sensor1));
|
||||
}
|
||||
@Test
|
||||
public void registerTwoSensors(){
|
||||
Sensor sensor1 = registerSensor(new TestSensor1());
|
||||
Sensor sensor2 = registerSensor(new TestSensor2());
|
||||
assertEquals(2, manager.getRegisteredSensors().size());
|
||||
assertTrue(manager.getRegisteredSensors().contains(sensor1));
|
||||
assertTrue(manager.getRegisteredSensors().contains(sensor2));
|
||||
assertEquals(2, manager.getRegisteredDevices().size());
|
||||
assertTrue(manager.getRegisteredDevices().contains(sensor1));
|
||||
assertTrue(manager.getRegisteredDevices().contains(sensor2));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -69,7 +70,7 @@ public class SensorControllerManagerTest {
|
|||
public void deregisterSensor(){
|
||||
Sensor sensor1 = registerSensor(new TestSensor1());
|
||||
manager.deregister(sensor1);
|
||||
assertEquals(Collections.EMPTY_LIST, manager.getRegisteredEvents());
|
||||
assertEquals(Collections.EMPTY_LIST, manager.getRegisteredDevices());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -80,7 +81,7 @@ public class SensorControllerManagerTest {
|
|||
private Sensor registerSensor(HalSensorConfig config){
|
||||
Sensor sensor = new Sensor();
|
||||
sensor.setDeviceConfig(config);
|
||||
manager.addAvailableSensor(config.getClass());
|
||||
manager.addAvailableDevice(config.getClass());
|
||||
manager.register(sensor);
|
||||
return sensor;
|
||||
}
|
||||
|
|
@ -99,12 +100,12 @@ public class SensorControllerManagerTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getSensorControllerClass() {
|
||||
public Class<? extends HalAbstractController> getDeviceControllerClass() {
|
||||
return TestController.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorData> getSensorDataClass() {
|
||||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return TemperatureSensorData.class;
|
||||
}
|
||||
}
|
||||
|
|
@ -122,21 +123,21 @@ public class SensorControllerManagerTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getSensorControllerClass() {
|
||||
public Class<? extends HalAbstractController> getDeviceControllerClass() {
|
||||
return TestController.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorData> getSensorDataClass() {
|
||||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return HumiditySensorData.class;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestController implements HalSensorController{
|
||||
public static class TestController implements HalSensorController {
|
||||
int size;
|
||||
|
||||
@Override
|
||||
public void initialize() throws Exception { }
|
||||
public void initialize() { }
|
||||
|
||||
@Override
|
||||
public void register(HalSensorConfig sensor) {
|
||||
|
|
@ -152,7 +153,7 @@ public class SensorControllerManagerTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setListener(HalSensorReportListener listener) { }
|
||||
public void setListener(HalDeviceReportListener listener) { }
|
||||
|
||||
@Override
|
||||
public void close() { }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package se.hal.plugin.dummy;
|
||||
|
||||
import se.hal.EventControllerManager;
|
||||
import se.hal.HalServer;
|
||||
import se.hal.SensorControllerManager;
|
||||
import se.hal.intf.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -10,8 +12,8 @@ import java.util.concurrent.*;
|
|||
|
||||
public class DummyController implements HalSensorController, HalEventController, Runnable, HalDaemon {
|
||||
private List<DummyDevice> registeredDevices = new ArrayList();
|
||||
private HalSensorReportListener sensorListener;
|
||||
private HalEventReportListener eventListener;
|
||||
private HalDeviceReportListener sensorListener;
|
||||
private HalDeviceReportListener eventListener;
|
||||
|
||||
|
||||
public DummyController() {}
|
||||
|
|
@ -45,27 +47,14 @@ public class DummyController implements HalSensorController, HalEventController,
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized void register(HalSensorConfig sensorConfig) {
|
||||
if (sensorConfig instanceof DummyDevice) {
|
||||
registeredDevices.add((DummyDevice) sensorConfig);
|
||||
}
|
||||
public synchronized void register(HalDeviceConfig deviceConfig) {
|
||||
if (deviceConfig instanceof DummyDevice)
|
||||
registeredDevices.add((DummyDevice) deviceConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void register(HalEventConfig eventConfig) {
|
||||
if (eventConfig instanceof DummyDevice) {
|
||||
registeredDevices.add((DummyDevice) eventConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void deregister(HalSensorConfig sensorConfig) {
|
||||
registeredDevices.remove(sensorConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void deregister(HalEventConfig eventConfig) {
|
||||
registeredDevices.remove(eventConfig);
|
||||
public synchronized void deregister(HalDeviceConfig deviceConfig) {
|
||||
registeredDevices.remove(deviceConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -79,10 +68,12 @@ public class DummyController implements HalSensorController, HalEventController,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setListener(HalSensorReportListener listener) { sensorListener = listener; }
|
||||
|
||||
@Override
|
||||
public void setListener(HalEventReportListener listener) { eventListener = listener; }
|
||||
public void setListener(HalDeviceReportListener listener) {
|
||||
if (listener instanceof SensorControllerManager)
|
||||
sensorListener = listener;
|
||||
else if (listener instanceof EventControllerManager)
|
||||
eventListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
|
|
|
|||
|
|
@ -31,12 +31,12 @@ public class DummyHumiditySensor implements DummyDevice, HalSensorConfig {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getSensorControllerClass() {
|
||||
public Class<? extends HalSensorController> getDeviceControllerClass() {
|
||||
return DummyController.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorData> getSensorDataClass() {
|
||||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return HumiditySensorData.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ public class DummySwitchEvent implements DummyDevice, HalEventConfig {
|
|||
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getEventControllerClass() {
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() {
|
||||
return DummyController.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventData> getEventDataClass() {
|
||||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@ public class DummyTemperatureSensor implements DummyDevice, HalSensorConfig {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getSensorControllerClass() {
|
||||
public Class<? extends HalSensorController> getDeviceControllerClass() {
|
||||
return DummyController.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorData> getSensorDataClass() {
|
||||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return TemperatureSensorData.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class HalMqttController implements HalAutoScannableController, MqttSubscr
|
|||
private MqttBroker mqttBroker;
|
||||
|
||||
private HashMap<String, HalMqttDeviceConfig> topics = new HashMap<>();
|
||||
private HalEventReportListener eventListener;
|
||||
private HalDeviceReportListener eventListener;
|
||||
|
||||
// --------------------------
|
||||
// Lifecycle methods
|
||||
|
|
@ -116,18 +116,18 @@ public class HalMqttController implements HalAutoScannableController, MqttSubscr
|
|||
// --------------------------
|
||||
|
||||
@Override
|
||||
public void register(HalEventConfig eventConfig) {
|
||||
if(eventConfig instanceof HalMqttDeviceConfig) {
|
||||
HalMqttDeviceConfig mqttEvent = (HalMqttDeviceConfig) eventConfig;
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof HalMqttDeviceConfig) {
|
||||
HalMqttDeviceConfig mqttEvent = (HalMqttDeviceConfig) deviceConfig;
|
||||
topics.put(mqttEvent.getTopic(), mqttEvent);
|
||||
} else throw new IllegalArgumentException(
|
||||
"Device config is not an instance of " + HalMqttDeviceConfig.class + ": " + eventConfig.getClass());
|
||||
"Device config is not an instance of " + HalMqttDeviceConfig.class + ": " + deviceConfig.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(HalEventConfig eventConfig) {
|
||||
if(eventConfig instanceof HalMqttDeviceConfig) {
|
||||
HalMqttDeviceConfig mqttEvent = (HalMqttDeviceConfig) eventConfig;
|
||||
public void deregister(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof HalMqttDeviceConfig) {
|
||||
HalMqttDeviceConfig mqttEvent = (HalMqttDeviceConfig) deviceConfig;
|
||||
topics.remove(mqttEvent.getTopic());
|
||||
}
|
||||
}
|
||||
|
|
@ -147,7 +147,7 @@ public class HalMqttController implements HalAutoScannableController, MqttSubscr
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setListener(HalEventReportListener listener) {
|
||||
public void setListener(HalDeviceReportListener listener) {
|
||||
eventListener = listener;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,12 +71,12 @@ public class HalMqttDeviceConfig implements HalEventConfig {
|
|||
// --------------------------
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getEventControllerClass() {
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() {
|
||||
return HalMqttController.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventData> getEventDataClass() {
|
||||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return HalMqttDeviceData.class;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class NetScanController implements HalEventController, HalAutoScannableCo
|
|||
private static final String PARAM_IPSCAN = "netscan.ipscan";
|
||||
|
||||
private ScheduledExecutorService executor;
|
||||
private HalEventReportListener listener;
|
||||
private HalDeviceReportListener listener;
|
||||
/** A register and a cache of previous state **/
|
||||
private HashMap<NetworkDevice, AvailabilityEventData> devices = new HashMap<>();
|
||||
|
||||
|
|
@ -97,14 +97,16 @@ public class NetScanController implements HalEventController, HalAutoScannableCo
|
|||
|
||||
|
||||
@Override
|
||||
public void register(HalEventConfig event) {
|
||||
if (event instanceof NetworkDevice)
|
||||
devices.put((NetworkDevice) event, null);
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
if (deviceConfig instanceof NetworkDevice)
|
||||
devices.put((NetworkDevice) deviceConfig, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(HalEventConfig event) {
|
||||
devices.remove(event);
|
||||
public void deregister(HalDeviceConfig deviceConfig) {
|
||||
devices.remove(deviceConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return devices.size();
|
||||
|
|
@ -116,7 +118,7 @@ public class NetScanController implements HalEventController, HalAutoScannableCo
|
|||
|
||||
|
||||
@Override
|
||||
public void setListener(HalEventReportListener listener) {
|
||||
public void setListener(HalDeviceReportListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@ public class NetworkDevice implements HalEventConfig {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getEventControllerClass() {
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() {
|
||||
return NetScanController.class;
|
||||
}
|
||||
@Override
|
||||
public Class<? extends HalEventData> getEventDataClass() {
|
||||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,10 +49,7 @@
|
|||
package se.hal.plugin.nutups;
|
||||
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalAutoScannableController;
|
||||
import se.hal.intf.HalSensorController;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.intf.HalSensorReportListener;
|
||||
import se.hal.intf.*;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.osal.linux.app.NutUPSClient;
|
||||
|
||||
|
|
@ -63,6 +60,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
public class NutUpsController implements HalSensorController, HalAutoScannableController, Runnable{
|
||||
public static Logger logger = LogUtil.getLogger();
|
||||
|
||||
|
|
@ -73,7 +71,7 @@ public class NutUpsController implements HalSensorController, HalAutoScannableCo
|
|||
private HashMap<String, NutUpsDevice> registeredDevices = new HashMap<>();
|
||||
private NutUPSClient client;
|
||||
private ScheduledExecutorService executor;
|
||||
private HalSensorReportListener listener;
|
||||
private HalDeviceReportListener listener;
|
||||
|
||||
|
||||
|
||||
|
|
@ -97,7 +95,7 @@ public class NutUpsController implements HalSensorController, HalAutoScannableCo
|
|||
|
||||
|
||||
@Override
|
||||
public void setListener(HalSensorReportListener listener) {
|
||||
public void setListener(HalDeviceReportListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
|
|
@ -126,16 +124,19 @@ public class NutUpsController implements HalSensorController, HalAutoScannableCo
|
|||
|
||||
|
||||
@Override
|
||||
public void register(HalSensorConfig sensor) {
|
||||
registeredDevices.put(((NutUpsDevice) sensor).getUpsId(), (NutUpsDevice) sensor);
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
if (deviceConfig instanceof NutUpsDevice)
|
||||
registeredDevices.put(((NutUpsDevice) deviceConfig).getUpsId(), (NutUpsDevice) deviceConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(HalSensorConfig sensor) {
|
||||
registeredDevices.remove(((NutUpsDevice) sensor).getUpsId());
|
||||
public void deregister(HalDeviceConfig deviceConfig) {
|
||||
registeredDevices.remove(((NutUpsDevice) deviceConfig).getUpsId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
return registeredDevices.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,11 +102,11 @@ public class NutUpsDevice implements HalSensorConfig{
|
|||
return AggregationMethod.SUM;
|
||||
}
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getSensorControllerClass() {
|
||||
public Class<? extends HalSensorController> getDeviceControllerClass() {
|
||||
return NutUpsController.class;
|
||||
}
|
||||
@Override
|
||||
public Class<? extends HalSensorData> getSensorDataClass() {
|
||||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return PowerConsumptionSensorData.class;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
package se.hal.plugin.nvr;
|
||||
|
||||
import se.hal.intf.HalAbstractControllerManager;
|
||||
import se.hal.plugin.nvr.intf.HalCameraConfig;
|
||||
import se.hal.plugin.nvr.intf.HalCameraController;
|
||||
import se.hal.plugin.nvr.struct.Camera;
|
||||
import se.hal.struct.AbstractDevice;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.plugin.PluginManager;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
public class CameraControllerManager extends HalAbstractControllerManager<HalCameraController, Camera, HalCameraConfig> {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
private static CameraControllerManager instance;
|
||||
|
||||
|
||||
@Override
|
||||
public void register(Camera device) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(Camera device) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends HalCameraConfig>> getAvailableDeviceConfigs() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Camera> getRegisteredDevices() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Camera> getDetectedDevices() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAvailableDevice(Class deviceConfigClass) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearDetectedDevices() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<HalCameraController> getControllers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void initialize(PluginManager pluginManager){
|
||||
super.initialize(pluginManager);
|
||||
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public static CameraControllerManager getInstance(){
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2021 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.hal.plugin.nvr;
|
||||
|
||||
import se.hal.intf.HalAbstractController;
|
||||
import se.hal.plugin.nvr.device.HalCameraConfig;
|
||||
import se.hal.plugin.nvr.device.HalCameraReportListener;
|
||||
|
||||
public interface HalCameraController extends HalAbstractController {
|
||||
|
||||
/**
|
||||
* Will register a camera to be handled by this controller.
|
||||
*/
|
||||
void register(HalCameraConfig cameraConfig);
|
||||
|
||||
/**
|
||||
* Deregisters a camera from this controller, the controller
|
||||
* will no longer handle camera device.
|
||||
*/
|
||||
void deregister(HalCameraConfig cameraConfig);
|
||||
|
||||
/**
|
||||
* Set a listener that will receive all reports from the the registered camera.
|
||||
*/
|
||||
void setListener(HalCameraReportListener listener);
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package se.hal.plugin.nvr.device;
|
||||
|
||||
import se.hal.plugin.nvr.HalCameraController;
|
||||
|
||||
/**
|
||||
* Listener to be called by the {@link HalCameraController} to report that a camera event has been observed.
|
||||
*/
|
||||
public interface HalCameraReportListener {
|
||||
|
||||
}
|
||||
|
|
@ -22,15 +22,10 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.hal.plugin.nvr.device;
|
||||
package se.hal.plugin.nvr.intf;
|
||||
|
||||
import se.hal.plugin.nvr.HalCameraController;
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
|
||||
public interface HalCameraConfig {
|
||||
|
||||
/**
|
||||
* @return the Controller class where CameraData should be registered on
|
||||
*/
|
||||
Class<? extends HalCameraController> getCameraControllerClass();
|
||||
public interface HalCameraConfig extends HalDeviceConfig {
|
||||
|
||||
}
|
||||
|
|
@ -22,8 +22,11 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.hal.plugin.nvr;
|
||||
package se.hal.plugin.nvr.intf;
|
||||
|
||||
public class StreamRecorder {
|
||||
import se.hal.intf.HalAbstractController;
|
||||
|
||||
|
||||
public interface HalCameraController extends HalAbstractController {
|
||||
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.hal.plugin.nvr.device;
|
||||
package se.hal.plugin.nvr.intf;
|
||||
|
||||
import se.hal.intf.HalDeviceData;
|
||||
|
||||
|
|
@ -24,11 +24,11 @@
|
|||
|
||||
package se.hal.plugin.nvr.page;
|
||||
|
||||
import se.hal.ControllerManager;
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalWebPage;
|
||||
import se.hal.page.HalAlertManager;
|
||||
import se.hal.plugin.nvr.device.Camera;
|
||||
import se.hal.plugin.nvr.CameraControllerManager;
|
||||
import se.hal.plugin.nvr.struct.Camera;
|
||||
import se.hal.struct.ClassConfigurationData;
|
||||
import se.hal.struct.User;
|
||||
import zutil.ObjectUtil;
|
||||
|
|
@ -36,7 +36,6 @@ import zutil.db.DBConnection;
|
|||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.parser.Templator;
|
||||
import zutil.ui.UserMessageManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
|
@ -56,7 +55,7 @@ public class CameraConfigWebPage extends HalWebPage {
|
|||
super.getRootNav().createSubNav("Settings").createSubNav(this.getId(), "Camera Settings").setWeight(200);
|
||||
|
||||
cameraConfigurations = new ArrayList<>();
|
||||
for(Class c : ControllerManager.getInstance().getAvailableEvents())
|
||||
for(Class c : CameraControllerManager.getInstance().getAvailableDeviceConfigs())
|
||||
cameraConfigurations.add(new ClassConfigurationData(c));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ package se.hal.plugin.nvr.page;
|
|||
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalWebPage;
|
||||
import se.hal.plugin.nvr.device.Camera;
|
||||
import se.hal.plugin.nvr.struct.Camera;
|
||||
import se.hal.struct.Event;
|
||||
import se.hal.util.DeviceNameComparator;
|
||||
import zutil.ObjectUtil;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
"name": "Hal-NVR",
|
||||
"description": "A Network Video Recorder plugin for recording network streams.",
|
||||
"interfaces": [
|
||||
{"se.hal.intf.HalAbstractControllerManager": "se.hal.plugin.nvr.CameraControllerManager"},
|
||||
|
||||
{"se.hal.intf.HalWebPage": "se.hal.plugin.nvr.page.CameraConfigWebPage"},
|
||||
{"se.hal.intf.HalWebPage": "se.hal.plugin.nvr.page.CameraOverviewWebPage"},
|
||||
{"se.hal.intf.HalWebPage": "se.hal.plugin.nvr.page.MonitorWebPage"}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,9 @@
|
|||
|
||||
package se.hal.plugin.nvr.rtsp;
|
||||
|
||||
import se.hal.plugin.nvr.HalCameraController;
|
||||
import se.hal.plugin.nvr.device.HalCameraConfig;
|
||||
import se.hal.intf.HalDeviceData;
|
||||
import se.hal.plugin.nvr.intf.HalCameraController;
|
||||
import se.hal.plugin.nvr.intf.HalCameraConfig;
|
||||
|
||||
public class RTSPCameraConfig implements HalCameraConfig {
|
||||
|
||||
|
|
@ -38,8 +39,18 @@ public class RTSPCameraConfig implements HalCameraConfig {
|
|||
}
|
||||
|
||||
|
||||
public String getRtspUrl() {
|
||||
return rtspUrl;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<? extends HalCameraController> getCameraControllerClass() {
|
||||
public Class<? extends HalCameraController> getDeviceControllerClass() {
|
||||
return RTSPController.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalDeviceData> getDeviceDataClass() {
|
||||
return null; // TODO:
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package se.hal.plugin.nvr.rtsp;
|
||||
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* A instance of this class will manage a RTSP stream from a specified source.
|
||||
*/
|
||||
public class RTSPCameraRecorder implements Runnable {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
private RTSPCameraConfig camera;
|
||||
|
||||
|
||||
public RTSPCameraRecorder(RTSPCameraConfig camera) {
|
||||
this.camera = camera;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
logger.info("Starting up RTSP Stream recording thread for: " + camera.getRtspUrl());
|
||||
|
||||
try {
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "RTSP Stream recording thread has crashed for: " + camera.getRtspUrl(), e);
|
||||
} finally {
|
||||
logger.info("Shutting down RTSP Stream recording thread for: " + camera.getRtspUrl());
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
camera = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,9 +24,9 @@
|
|||
|
||||
package se.hal.plugin.nvr.rtsp;
|
||||
|
||||
import se.hal.plugin.nvr.HalCameraController;
|
||||
import se.hal.plugin.nvr.device.HalCameraConfig;
|
||||
import se.hal.plugin.nvr.device.HalCameraReportListener;
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalDeviceReportListener;
|
||||
import se.hal.plugin.nvr.intf.HalCameraController;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -40,7 +40,7 @@ public class RTSPController implements HalCameraController {
|
|||
private static final String CONFIG_RECORDING_PATH = "nvr.recording_path";
|
||||
|
||||
private List<RTSPCameraConfig> cameras = new ArrayList<>();
|
||||
private HalCameraReportListener listener;
|
||||
private HalDeviceReportListener listener;
|
||||
|
||||
|
||||
public RTSPController() {}
|
||||
|
|
@ -51,7 +51,7 @@ public class RTSPController implements HalCameraController {
|
|||
// ----------------------------------------------------
|
||||
|
||||
@Override
|
||||
public void initialize() throws Exception {
|
||||
public void initialize() {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -65,14 +65,14 @@ public class RTSPController implements HalCameraController {
|
|||
// ----------------------------------------------------
|
||||
|
||||
@Override
|
||||
public void register(HalCameraConfig cameraConfig) {
|
||||
if (cameraConfig instanceof RTSPCameraConfig)
|
||||
cameras.add((RTSPCameraConfig) cameraConfig);
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
if (deviceConfig instanceof RTSPCameraConfig)
|
||||
cameras.add((RTSPCameraConfig) deviceConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(HalCameraConfig cameraConfig) {
|
||||
cameras.remove(cameraConfig);
|
||||
public void deregister(HalDeviceConfig deviceConfig) {
|
||||
cameras.remove(deviceConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -81,7 +81,7 @@ public class RTSPController implements HalCameraController {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setListener(HalCameraReportListener listener) {
|
||||
public void setListener(HalDeviceReportListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,9 +22,11 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.hal.plugin.nvr.device;
|
||||
package se.hal.plugin.nvr.struct;
|
||||
|
||||
import se.hal.intf.HalAbstractController;
|
||||
import se.hal.plugin.nvr.intf.HalCameraConfig;
|
||||
import se.hal.plugin.nvr.intf.HalCameraData;
|
||||
import se.hal.struct.AbstractDevice;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.db.bean.DBBean;
|
||||
|
|
@ -46,7 +48,7 @@ public class Camera extends AbstractDevice<Camera, HalCameraConfig, HalCameraDat
|
|||
|
||||
@Override
|
||||
public Class<? extends HalAbstractController> getController() {
|
||||
return getDeviceConfig().getCameraControllerClass();
|
||||
return getDeviceConfig().getDeviceControllerClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -13,7 +13,7 @@ public class RPiController implements HalSensorController {
|
|||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
private HashMap<String, RPiSensor> pinToSensorMap = new HashMap<>();
|
||||
private HalSensorReportListener sensorListener;
|
||||
private HalDeviceReportListener sensorListener;
|
||||
|
||||
public RPiController(){
|
||||
|
||||
|
|
@ -25,9 +25,9 @@ public class RPiController implements HalSensorController {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void register(HalSensorConfig sensor) {
|
||||
if(sensor instanceof RPiPowerConsumptionSensor){
|
||||
RPiPowerConsumptionSensor powerConsumptionSensor = (RPiPowerConsumptionSensor) sensor;
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof RPiPowerConsumptionSensor){
|
||||
RPiPowerConsumptionSensor powerConsumptionSensor = (RPiPowerConsumptionSensor) deviceConfig;
|
||||
int gpioPin = powerConsumptionSensor.getGpioPin();
|
||||
if(!pinToSensorMap.containsKey("GPIO_"+gpioPin)){
|
||||
RPiInteruptPulseFlankCounter impulseCounter = new RPiInteruptPulseFlankCounter(gpioPin, this);
|
||||
|
|
@ -35,8 +35,8 @@ public class RPiController implements HalSensorController {
|
|||
}else{
|
||||
logger.warning("Cannot create a RPiPowerConsumptionSensor on GPIO pin " + gpioPin + " since is already is in use by another sensor.");
|
||||
}
|
||||
} else if(sensor instanceof RPiTemperatureSensor){
|
||||
RPiTemperatureSensor temperatureSensor = (RPiTemperatureSensor) sensor;
|
||||
} else if(deviceConfig instanceof RPiTemperatureSensor){
|
||||
RPiTemperatureSensor temperatureSensor = (RPiTemperatureSensor) deviceConfig;
|
||||
String w1Address = temperatureSensor.get1WAddress();
|
||||
if(!pinToSensorMap.containsKey("W1_"+w1Address)){
|
||||
RPiDS18B20 ds12b20 = new RPiDS18B20(w1Address, this);
|
||||
|
|
@ -50,15 +50,15 @@ public class RPiController implements HalSensorController {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void deregister(HalSensorConfig sensor) {
|
||||
if(sensor instanceof RPiPowerConsumptionSensor){
|
||||
RPiPowerConsumptionSensor powerConsumprtionSensor = (RPiPowerConsumptionSensor) sensor;
|
||||
RPiSensor sensorToDeregister = pinToSensorMap.remove("GPIO_"+powerConsumprtionSensor.getGpioPin());
|
||||
public void deregister(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof RPiPowerConsumptionSensor){
|
||||
RPiPowerConsumptionSensor powerConsumptionSensor = (RPiPowerConsumptionSensor) deviceConfig;
|
||||
RPiSensor sensorToDeregister = pinToSensorMap.remove("GPIO_"+powerConsumptionSensor.getGpioPin());
|
||||
if(sensorToDeregister != null){
|
||||
sensorToDeregister.close();
|
||||
}
|
||||
} else if(sensor instanceof RPiTemperatureSensor){
|
||||
RPiTemperatureSensor temperatureSensor = (RPiTemperatureSensor) sensor;
|
||||
} else if(deviceConfig instanceof RPiTemperatureSensor){
|
||||
RPiTemperatureSensor temperatureSensor = (RPiTemperatureSensor) deviceConfig;
|
||||
RPiSensor sensorToDeregister = pinToSensorMap.remove("W1_"+temperatureSensor.get1WAddress());
|
||||
if(sensorToDeregister != null){
|
||||
sensorToDeregister.close();
|
||||
|
|
@ -75,7 +75,7 @@ public class RPiController implements HalSensorController {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setListener(HalSensorReportListener listener) {
|
||||
public void setListener(HalDeviceReportListener listener) {
|
||||
sensorListener = listener;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@ public class RPiPowerConsumptionSensor implements HalSensorConfig {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getSensorControllerClass() {
|
||||
public Class<? extends HalSensorController> getDeviceControllerClass() {
|
||||
return RPiController.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorData> getSensorDataClass() {
|
||||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return PowerConsumptionSensorData.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@ public class RPiTemperatureSensor implements HalSensorConfig {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getSensorControllerClass() {
|
||||
public Class<? extends HalSensorController> getDeviceControllerClass() {
|
||||
return RPiController.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorData> getSensorDataClass() {
|
||||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return TemperatureSensorData.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,8 +61,7 @@ public class TellstickSerialComm implements Runnable,
|
|||
|
||||
protected TellstickParser parser;
|
||||
|
||||
private HalSensorReportListener sensorListener;
|
||||
private HalEventReportListener eventListener;
|
||||
private HalDeviceReportListener deviceListener;
|
||||
private List<TellstickDevice> registeredDevices;
|
||||
|
||||
|
||||
|
|
@ -186,10 +185,8 @@ public class TellstickSerialComm implements Runnable,
|
|||
set.add(data);
|
||||
}
|
||||
private void reportEvent(TellstickDevice tellstickDevice, HalDeviceData deviceData){
|
||||
if (sensorListener != null && tellstickDevice instanceof HalSensorConfig)
|
||||
sensorListener.reportReceived((HalSensorConfig) tellstickDevice, (HalSensorData) deviceData);
|
||||
else if (eventListener != null && tellstickDevice instanceof HalEventConfig)
|
||||
eventListener.reportReceived((HalEventConfig) tellstickDevice, (HalEventData) deviceData);
|
||||
if (deviceListener != null)
|
||||
deviceListener.reportReceived((HalDeviceConfig) tellstickDevice, deviceData);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -225,18 +222,11 @@ public class TellstickSerialComm implements Runnable,
|
|||
// --------------------------
|
||||
|
||||
@Override
|
||||
public void register(HalEventConfig event) {
|
||||
if(event instanceof TellstickDevice)
|
||||
registeredDevices.add((TellstickDevice) event);
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof TellstickDevice)
|
||||
registeredDevices.add((TellstickDevice) deviceConfig);
|
||||
else throw new IllegalArgumentException(
|
||||
"Device config is not an instance of "+TellstickDevice.class+": "+event.getClass());
|
||||
}
|
||||
@Override
|
||||
public void register(HalSensorConfig sensor) {
|
||||
if(sensor instanceof TellstickDevice)
|
||||
registeredDevices.add((TellstickDevice) sensor);
|
||||
else throw new IllegalArgumentException(
|
||||
"Device config is not an instance of "+TellstickDevice.class+": "+sensor.getClass());
|
||||
"Device config is not an instance of " + TellstickDevice.class + ": " + deviceConfig.getClass());
|
||||
}
|
||||
|
||||
public <T> List<T> getRegisteredDevices(Class<T> clazz){
|
||||
|
|
@ -249,12 +239,8 @@ public class TellstickSerialComm implements Runnable,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void deregister(HalEventConfig event) {
|
||||
registeredDevices.remove(event);
|
||||
}
|
||||
@Override
|
||||
public void deregister(HalSensorConfig sensor) {
|
||||
registeredDevices.remove(sensor);
|
||||
public void deregister(HalDeviceConfig deviceConfig) {
|
||||
registeredDevices.remove(deviceConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -263,12 +249,8 @@ public class TellstickSerialComm implements Runnable,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setListener(HalEventReportListener listener) {
|
||||
eventListener = listener;
|
||||
}
|
||||
@Override
|
||||
public void setListener(HalSensorReportListener listener) {
|
||||
sensorListener = listener;
|
||||
public void setListener(HalDeviceReportListener listener) {
|
||||
deviceListener = listener;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -101,11 +101,11 @@ public class NexaSelfLearning implements HalEventConfig,TellstickDevice,Tellstic
|
|||
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getEventControllerClass() {
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() {
|
||||
return TellstickSerialComm.class;
|
||||
}
|
||||
@Override
|
||||
public Class<? extends HalEventData> getEventDataClass() {
|
||||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,11 +81,11 @@ public class NexaSelfLearningDimmer implements HalEventConfig,TellstickDevice {
|
|||
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getEventControllerClass() {
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() {
|
||||
return TellstickSerialComm.class;
|
||||
}
|
||||
@Override
|
||||
public Class<? extends HalEventData> getEventDataClass() {
|
||||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return DimmerEventData.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,12 +73,12 @@ public class Oregon0x1A2D implements HalSensorConfig,TellstickDevice {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getSensorControllerClass() {
|
||||
public Class<? extends HalSensorController> getDeviceControllerClass() {
|
||||
return TellstickSerialComm.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorData> getSensorDataClass() {
|
||||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
if (sensorType != null) {
|
||||
switch (sensorType) {
|
||||
case HUMIDITY:
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class TelstickSerialCommEventTest {
|
|||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalEventConfig> list = new ArrayList<>();
|
||||
tellstick.setListener(new HalEventReportListener() {
|
||||
tellstick.setListener(new HalDeviceReportListener<HalEventConfig,HalEventData>() {
|
||||
@Override
|
||||
public void reportReceived(HalEventConfig e, HalEventData d) {
|
||||
list.add(e);
|
||||
|
|
@ -62,7 +62,7 @@ public class TelstickSerialCommEventTest {
|
|||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalEventConfig> list = new ArrayList<>();
|
||||
tellstick.setListener(new HalEventReportListener() {
|
||||
tellstick.setListener(new HalDeviceReportListener<HalEventConfig,HalEventData>() {
|
||||
@Override
|
||||
public void reportReceived(HalEventConfig e, HalEventData d) {
|
||||
list.add(e);
|
||||
|
|
@ -101,9 +101,9 @@ public class TelstickSerialCommEventTest {
|
|||
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getEventControllerClass() { return null; }
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() { return null; }
|
||||
@Override
|
||||
public Class<? extends HalEventData> getEventDataClass() {
|
||||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class TelstickSerialCommSensorTest {
|
|||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalSensorConfig> list = new ArrayList<>();
|
||||
tellstick.setListener(new HalSensorReportListener() {
|
||||
tellstick.setListener(new HalDeviceReportListener<HalSensorConfig,HalSensorData>() {
|
||||
@Override
|
||||
public void reportReceived(HalSensorConfig e, HalSensorData d) {
|
||||
list.add(e);
|
||||
|
|
@ -47,7 +47,7 @@ public class TelstickSerialCommSensorTest {
|
|||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalSensorConfig> list = new ArrayList<>();
|
||||
tellstick.setListener(new HalSensorReportListener() {
|
||||
tellstick.setListener(new HalDeviceReportListener<HalSensorConfig,HalSensorData>() {
|
||||
@Override
|
||||
public void reportReceived(HalSensorConfig e, HalSensorData d) {
|
||||
list.add(e);
|
||||
|
|
@ -94,9 +94,9 @@ public class TelstickSerialCommSensorTest {
|
|||
@Override
|
||||
public AggregationMethod getAggregationMethod() { return null; }
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getSensorControllerClass() { return null; }
|
||||
public Class<? extends HalSensorController> getDeviceControllerClass() { return null; }
|
||||
@Override
|
||||
public Class<? extends HalSensorData> getSensorDataClass() {
|
||||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ import java.util.logging.Logger;
|
|||
* <p>
|
||||
* Rest documentatiuon for deConz: https://dresden-elektronik.github.io/deconz-rest-doc/
|
||||
*/
|
||||
public class HalDeConzZigbeeController implements HalSensorController, HalEventController, HalAutoScannableController {
|
||||
public class DeConzZigbeeController implements HalSensorController, HalEventController, HalAutoScannableController {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
public static final String CONFIG_ZIGBEE_REST_URL = "zigbee.rest_url";
|
||||
|
|
@ -62,17 +62,12 @@ public class HalDeConzZigbeeController implements HalSensorController, HalEventC
|
|||
|
||||
|
||||
@Override
|
||||
public void setListener(HalEventReportListener listener) {
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(HalEventConfig eventConfig) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(HalEventConfig eventConfig) {
|
||||
public void deregister(HalDeviceConfig deviceConfig) {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -81,19 +76,8 @@ public class HalDeConzZigbeeController implements HalSensorController, HalEventC
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void register(HalSensorConfig sensorConfig) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(HalSensorConfig sensorConfig) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListener(HalSensorReportListener listener) {
|
||||
public void setListener(HalDeviceReportListener listener) {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -19,14 +19,14 @@ public interface DeConzRestConfig {
|
|||
* @param deviceType Name of the client application. (required)
|
||||
* @param username Will be used as username. If not specified a random key will be generated. (optional)
|
||||
*/
|
||||
@WSRequestType(HTTP_POST)
|
||||
@WSRequestType(POST)
|
||||
@WSPath("/api")
|
||||
DataNode getAPIKey(String deviceType, String username);
|
||||
|
||||
/**
|
||||
* Deletes an API key so it can no longer be used.
|
||||
*/
|
||||
@WSRequestType(HTTP_DELETE)
|
||||
@WSRequestType(DELETE)
|
||||
@WSPath("/api/{{requestApiKey}}/config/whitelist/{{apikey2}}")
|
||||
DataNode deleteAPIKey(String requestApiKey, String deleteApiKey);
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ public interface DeConzRestConfig {
|
|||
/**
|
||||
* Returns the current gateway configuration.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/config")
|
||||
void getConfiguration(String requestApiKey);
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ public interface DeConzRestConfig {
|
|||
/**
|
||||
* Returns the full state of the gateway including all its lights, groups, scenes and schedules.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}")
|
||||
void getFullState(String requestApiKey);
|
||||
|
||||
|
|
@ -56,14 +56,14 @@ public interface DeConzRestConfig {
|
|||
/**
|
||||
* Returns the newest software version available. Starts the update if available (only on raspberry pi).
|
||||
*/
|
||||
@WSRequestType(HTTP_POST)
|
||||
@WSRequestType(POST)
|
||||
@WSPath("/api/{{requestApiKey}}/config/update")
|
||||
void updateSoftware(String requestApiKey);
|
||||
|
||||
/**
|
||||
* Starts the update firmware process if newer firmware is available.
|
||||
*/
|
||||
@WSRequestType(HTTP_POST)
|
||||
@WSRequestType(POST)
|
||||
@WSPath("/api/{{requestApiKey}}/config/updatefirmware")
|
||||
void updateFirmware(String requestApiKey);
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ public interface DeConzRestConfig {
|
|||
* @param resetGW Set the network settings of the gateway to factory new. (optional)
|
||||
* @param deleteDB Delete the Database. (optional)
|
||||
*/
|
||||
@WSRequestType(HTTP_POST)
|
||||
@WSRequestType(POST)
|
||||
@WSPath("/api/{{requestApiKey}}/config/reset")
|
||||
void resetGateway(String requestApiKey, boolean resetGW, boolean deleteDB);
|
||||
|
||||
|
|
@ -85,14 +85,14 @@ public interface DeConzRestConfig {
|
|||
* @param oldHash String The Base64 encoded combination of "username:old password". (required)
|
||||
* @param newHash String The Base64 encoded combination of "username:new password". (required)
|
||||
*/
|
||||
@WSRequestType(HTTP_PUT)
|
||||
@WSRequestType(PUT)
|
||||
@WSPath("/api/{{requestApiKey}}/config/password")
|
||||
void setPassword(String requestApiKey, String username, String oldHash, String newHash);
|
||||
|
||||
/**
|
||||
* Resets the username and password to default ("delight","delight"). Only possible within 10 minutes after gateway start.
|
||||
*/
|
||||
@WSRequestType(HTTP_DELETE)
|
||||
@WSRequestType(DELETE)
|
||||
@WSPath("/api/{{requestApiKey}}/config/password")
|
||||
void resetPassword(String requestApiKey);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,21 +19,21 @@ public interface DeConzRestGroups {
|
|||
*
|
||||
* @param name The name of the new group. (required)
|
||||
*/
|
||||
@WSRequestType(HTTP_POST)
|
||||
@WSRequestType(POST)
|
||||
@WSPath("/api/{{requestApiKey}}/groups")
|
||||
void createGroup(String requestApiKey, String name);
|
||||
|
||||
/**
|
||||
* Returns a list of all groups.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/groups")
|
||||
void getGroups(String requestApiKey);
|
||||
|
||||
/**
|
||||
* Returns the full state of a group.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/groups/{{groupId}}")
|
||||
void getGroup(String requestApiKey, int groupId);
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ public interface DeConzRestGroups {
|
|||
* @param lightSequence Specify a sorted list of light ids that can be used in apps. optional
|
||||
* @param multiDeviceIds Append the subsequential light ids of multidevices like the FLS-PP if the app should handle that light differently.
|
||||
*/
|
||||
@WSRequestType(HTTP_PUT)
|
||||
@WSRequestType(PUT)
|
||||
@WSPath("/api/{{requestApiKey}}/groups/{{groupId}}")
|
||||
void setGroup(String requestApiKey, int groupId, String name, List lights, boolean hidden, List lightSequence, List multiDeviceIds);
|
||||
|
||||
|
|
@ -65,14 +65,14 @@ public interface DeConzRestGroups {
|
|||
* @param colorLoopSpeed Specifies the speed of a colorloop. 1 = very fast, 255 = very slow (default: 15). This parameter only has an effect when it is called together with effect colorloop. (optional)
|
||||
* @param transitionTime Transition time in 1/10 seconds between two states. (optional)
|
||||
*/
|
||||
@WSRequestType(HTTP_PUT)
|
||||
@WSRequestType(PUT)
|
||||
@WSPath("/api/{{requestApiKey}}/groups/{{groupId}}/action")
|
||||
void setGroupState(String requestApiKey, int groupId, boolean on, boolean toggle, int bri, int hue, int sat, int ct, List xy, String alert, String effect, int colorLoopSpeed, int transitionTime);
|
||||
|
||||
/**
|
||||
* Deletes a group.
|
||||
*/
|
||||
@WSRequestType(HTTP_DELETE)
|
||||
@WSRequestType(DELETE)
|
||||
@WSPath("/api/{{requestApiKey}}/groups/{{groupId}}")
|
||||
void deleteGroup(String requestApiKey, int groupId);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@ public interface DeConzRestLights {
|
|||
/**
|
||||
* Returns a list of all lights.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/lights")
|
||||
void getLights(String requestApiKey);
|
||||
|
||||
/**
|
||||
* Returns the full state of a light.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/lights/{{lightId}")
|
||||
void getLight(String requestApiKey, int lightId);
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ public interface DeConzRestLights {
|
|||
*
|
||||
* @param name Set the name of the light. (required)
|
||||
*/
|
||||
@WSRequestType(HTTP_PUT)
|
||||
@WSRequestType(PUT)
|
||||
@WSPath("/api/{{requestApiKey}}/lights/{{lightId}")
|
||||
void setLight(String requestApiKey, int lightId, String name);
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ public interface DeConzRestLights {
|
|||
* @param colorLoopSpeed Specifies the speed of a colorloop. 1 = very fast, 255 = very slow (default: 15). This parameter only has an effect when it is called together with effect colorloop. (optional)
|
||||
* @param transitionTime Transition time in 1/10 seconds between two states. (optional)
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/lights/{{lightId}/state")
|
||||
void setLightState(String requestApiKey, int lightId, boolean on, boolean toggle, int bri, int hue, int sat, int ct, List xy, String alert, String effect, int colorLoopSpeed, int transitionTime);
|
||||
|
||||
|
|
@ -61,21 +61,21 @@ public interface DeConzRestLights {
|
|||
*
|
||||
* @param reset If true sends a network leave command to the light device (may not supported by each manufacturer). (optional)
|
||||
*/
|
||||
@WSRequestType(HTTP_PUT)
|
||||
@WSRequestType(PUT)
|
||||
@WSPath("/api/{{requestApiKey}}/lights/{{lightId}")
|
||||
void deleteLight(String requestApiKey, int lightId, boolean reset);
|
||||
|
||||
/**
|
||||
* Remove the light from all groups it is a member of.
|
||||
*/
|
||||
@WSRequestType(HTTP_DELETE)
|
||||
@WSRequestType(DELETE)
|
||||
@WSPath("/api/{{requestApiKey}}/lights/{{lightId}/groups")
|
||||
void deleteGroups(String requestApiKey, int lightId);
|
||||
|
||||
/**
|
||||
* Remove the light from all scenes it is a member of.
|
||||
*/
|
||||
@WSRequestType(HTTP_DELETE)
|
||||
@WSRequestType(DELETE)
|
||||
@WSPath("/api/{{requestApiKey}}/lights/{{lightId}/scenes")
|
||||
void deleteScenes(String requestApiKey, int lightId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,14 +35,14 @@ public interface DeConzRestRules {
|
|||
/**
|
||||
* Returns a list of all rules. If there are no rules in the system then an empty object {} will be returned.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/rules")
|
||||
void getRules(String requestApiKey);
|
||||
|
||||
/**
|
||||
* Returns the rule with the specified id.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/rules/{{ruleId}}")
|
||||
void getRule(String requestApiKey, int ruleId);
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ public interface DeConzRestRules {
|
|||
//@WSPath("/api/{{requestApiKey}}/rules/{{ruleId}}")
|
||||
//void setRule(String requestApiKey, int ruleId, String name, int periodic, String status, List actions, List conditions);
|
||||
|
||||
@WSRequestType(HTTP_DELETE)
|
||||
@WSRequestType(DELETE)
|
||||
@WSPath("/api/{{requestApiKey}}/rules/{{ruleId}}")
|
||||
void deleteRule(String requestApiKey, int ruleId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,21 +17,21 @@ public interface DeConzRestScenes {
|
|||
*
|
||||
* @param name The name of the new scene. (required)
|
||||
*/
|
||||
@WSRequestType(HTTP_POST)
|
||||
@WSRequestType(POST)
|
||||
@WSPath("/api/{{requestApiKey}}/groups/{{group_id}}/scenes")
|
||||
void createScene(String requestApiKey, int groupId, String name);
|
||||
|
||||
/**
|
||||
* Returns a list of all scenes of a group.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/groups/{{group_id}}/scenes")
|
||||
void getScenes(String requestApiKey, int groupId);
|
||||
|
||||
/**
|
||||
* Returns all attributes of a scene.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/groups/{{group_id}}/scenes/{{sceneId}}")
|
||||
void getScene(String requestApiKey, int groupId, int sceneId);
|
||||
|
||||
|
|
@ -40,14 +40,14 @@ public interface DeConzRestScenes {
|
|||
*
|
||||
* @param name Name of the scene. (optional)
|
||||
*/
|
||||
@WSRequestType(HTTP_PUT)
|
||||
@WSRequestType(PUT)
|
||||
@WSPath("/api/{{requestApiKey}}/groups/{{group_id}}/scenes/{{sceneId}}")
|
||||
void getScene(String requestApiKey, int groupId, int sceneId, String name);
|
||||
|
||||
/**
|
||||
* Stores the current group state in the scene. The actual state of each light in the group will become the lights scene state.
|
||||
*/
|
||||
@WSRequestType(HTTP_PUT)
|
||||
@WSRequestType(PUT)
|
||||
@WSPath("/api/{{requestApiKey}}/groups/{{group_id}}/scenes/{{sceneId}}/store")
|
||||
String storeScene(String requestApiKey, int groupId, int sceneId);
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ public interface DeConzRestScenes {
|
|||
* Recalls a scene. The actual state of each light in the group will become the lights scene state stored in each light.
|
||||
* Note: Lights which are not reachable (turned off) won’t be affected!
|
||||
*/
|
||||
@WSRequestType(HTTP_PUT)
|
||||
@WSRequestType(PUT)
|
||||
@WSPath("/api/{{requestApiKey}}/groups/{{group_id}}/scenes/{{sceneId}}/recall")
|
||||
void recallScene(String requestApiKey, int groupId, int sceneId);
|
||||
|
||||
|
|
@ -68,14 +68,14 @@ public interface DeConzRestScenes {
|
|||
* @param xy Set the CIE xy color space coordinates as array [x, y] of real values (0..1). optional
|
||||
* @param transitionTime Transition time in 1/10 seconds between two states. (optional)
|
||||
*/
|
||||
@WSRequestType(HTTP_PUT)
|
||||
@WSRequestType(PUT)
|
||||
@WSPath("/api/{{requestApiKey}}/groups/{{group_id}}/scenes/{{sceneId}}/state/lights/{{lightId}}/state")
|
||||
void setSceneState(String requestApiKey, int groupId, int sceneId, int lightId, int on, int bri, int xy, int transitionTime);
|
||||
|
||||
/**
|
||||
* Deletes a scene.
|
||||
*/
|
||||
@WSRequestType(HTTP_DELETE)
|
||||
@WSRequestType(DELETE)
|
||||
@WSPath("/api/{{requestApiKey}}/groups/{{group_id}}/scenes/{{sceneId}}")
|
||||
void deleteScene(String requestApiKey, int groupId, int sceneId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,14 +34,14 @@ public interface DeConzRestSchedules {
|
|||
/**
|
||||
* Returns a list of all schedules.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/schedules")
|
||||
List getSchedules(String requestApiKey);
|
||||
|
||||
/**
|
||||
* Returns all attributes of a schedule.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/schedules/{{scheduleId}}")
|
||||
List getSchedule(String requestApiKey, int scheduleId);
|
||||
|
||||
|
|
@ -58,14 +58,14 @@ public interface DeConzRestSchedules {
|
|||
* @param autoDelete If true the schedule will be deleted after triggered. Else it will be disabled. Default is true. (optional)
|
||||
* @param time Time when the schedule shall trigger in UTC ISO 8601:2004 format. (required)
|
||||
*/
|
||||
@WSRequestType(HTTP_PUT)
|
||||
@WSRequestType(PUT)
|
||||
@WSPath("/api/{{requestApiKey}}/schedules/{{scheduleId}}")
|
||||
void setSchedule(String requestApiKey, int scheduleId, String name, String description, List command, String status, boolean autoDelete, String time);
|
||||
|
||||
/**
|
||||
* Returns all attributes of a schedule.
|
||||
*/
|
||||
@WSRequestType(HTTP_DELETE)
|
||||
@WSRequestType(DELETE)
|
||||
@WSPath("/api/{{requestApiKey}}/schedules/{{scheduleId}}")
|
||||
void deleteSchedule(String requestApiKey, int scheduleId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,21 +30,21 @@ public interface DeConzRestSensors {
|
|||
* reachable - Bool - default: true
|
||||
* battery - Number (0..100)
|
||||
*/
|
||||
@WSRequestType(HTTP_POST)
|
||||
@WSRequestType(POST)
|
||||
@WSPath("/api/{{requestApiKey}}/sensors")
|
||||
void createSensor(String requestApiKey, int groupId, String name, String modelid, String swversion, String type, String uniqueid, String manufacturername, Map state, Map config);
|
||||
|
||||
/**
|
||||
* Returns a list of all Sensors. If there are no sensors in the system then an empty object {} will be returned.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/sensors")
|
||||
List getSensor(String requestApiKey);
|
||||
|
||||
/**
|
||||
* Returns a list of all Sensors. If there are no sensors in the system then an empty object {} will be returned.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/sensors/{{sensorId}}")
|
||||
void getSensor(String requestApiKey, int sensorId);
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ public interface DeConzRestSensors {
|
|||
* 2 = Two groups mode
|
||||
* 3 = Color temperature mode
|
||||
*/
|
||||
@WSRequestType(HTTP_PUT)
|
||||
@WSRequestType(PUT)
|
||||
@WSPath("/api/{{requestApiKey}}/sensors/{{sensorId}}")
|
||||
void setSensor(String requestApiKey, int sensorId, String name, int mode);
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ public interface DeConzRestSensors {
|
|||
* @param reachable The reachable status of the sensor. (optional)
|
||||
* @param battery The current battery state in percent, only for battery powered devices. (optional)
|
||||
*/
|
||||
@WSRequestType(HTTP_PUT)
|
||||
@WSRequestType(PUT)
|
||||
@WSPath("/api/{{requestApiKey}}/sensors/{{sensorId}}/config")
|
||||
void setSensorConfig(String requestApiKey, int sensorId, boolean on, boolean reachable, int battery);
|
||||
|
||||
|
|
@ -84,14 +84,14 @@ public interface DeConzRestSensors {
|
|||
* CLIPGenericStatus status Number
|
||||
* CLIPHumidity humidity Number
|
||||
*/
|
||||
@WSRequestType(HTTP_PUT)
|
||||
@WSRequestType(PUT)
|
||||
@WSPath("/api/{{requestApiKey}}/sensors/{{sensorId}}/state")
|
||||
void setSensorState(String requestApiKey, String flag);
|
||||
|
||||
/**
|
||||
* Delete a sensor.
|
||||
*/
|
||||
@WSRequestType(HTTP_DELETE)
|
||||
@WSRequestType(DELETE)
|
||||
@WSPath("/api/{{requestApiKey}}/sensors/{{sensorId}}/state")
|
||||
void deleteSensor(String requestApiKey, int sensorId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ public interface DeConzRestTouchlink {
|
|||
* Starts scanning on all channels for devices which are located close to the gateway. The whole scan process will take about 10 seconds.
|
||||
* <p>Note: While scanning is in progress further API requests which require network access aren’t allowed.
|
||||
*/
|
||||
@WSRequestType(HTTP_POST)
|
||||
@WSRequestType(POST)
|
||||
@WSPath("/api/{{requestApiKey}}/touchlink/scan")
|
||||
void startDeviceScan(String requestApiKey);
|
||||
|
||||
/**
|
||||
* Returns the results of a touchlink scan.
|
||||
*/
|
||||
@WSRequestType(HTTP_GET)
|
||||
@WSRequestType(GET)
|
||||
@WSPath("/api/{{requestApiKey}}/touchlink/scan")
|
||||
void getScanResult(String requestApiKey);
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ public interface DeConzRestTouchlink {
|
|||
* Puts a device into identify mode for example a light will blink a few times.
|
||||
* <p>Note: touchlinkId must be one of the indentifiers which are returned in the scan result.
|
||||
*/
|
||||
@WSRequestType(HTTP_POST)
|
||||
@WSRequestType(POST)
|
||||
@WSPath("/api/{{requestApiKey}}/touchlink/{{touchlinkId}}/identify")
|
||||
void identifyDevice(String requestApiKey, int touchlinkId);
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ public interface DeConzRestTouchlink {
|
|||
* Send a reset to factory new request to a device.
|
||||
* <p>Note: touchlinkId must be one of the indentifiers which are returned in the scan result.
|
||||
*/
|
||||
@WSRequestType(HTTP_POST)
|
||||
@WSRequestType(POST)
|
||||
@WSPath("/api/{{requestApiKey}}/touchlink/{{touchlinkId}}/reset")
|
||||
void resetDevice(String requestApiKey, int touchlinkId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import com.zsmartsystems.zigbee.ZigBeeProfileType;
|
|||
import com.zsmartsystems.zigbee.ZigBeeStatus;
|
||||
import com.zsmartsystems.zigbee.app.basic.ZigBeeBasicServerExtension;
|
||||
import com.zsmartsystems.zigbee.app.discovery.ZigBeeDiscoveryExtension;
|
||||
import com.zsmartsystems.zigbee.app.iasclient.ZigBeeIasCieExtension;
|
||||
import com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaUpgradeExtension;
|
||||
import com.zsmartsystems.zigbee.dongle.cc2531.ZigBeeDongleTiCc2531;
|
||||
import com.zsmartsystems.zigbee.dongle.conbee.ZigBeeDongleConBee;
|
||||
|
|
@ -40,8 +39,7 @@ public class HalZigbeeController implements HalSensorController, HalEventControl
|
|||
private ZigBeeDataStore dataStore;
|
||||
protected ZigBeeNetworkManager networkManager;
|
||||
|
||||
private HalSensorReportListener sensorListener;
|
||||
private HalEventReportListener eventListener;
|
||||
private HalDeviceReportListener deviceListener;
|
||||
private List<AbstractDevice> registeredDevices;
|
||||
|
||||
|
||||
|
|
@ -140,21 +138,13 @@ public class HalZigbeeController implements HalSensorController, HalEventControl
|
|||
// --------------------------
|
||||
|
||||
@Override
|
||||
public void register(HalEventConfig event) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void register(HalSensorConfig sensor) {
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(HalEventConfig event) {
|
||||
registeredDevices.remove(event);
|
||||
}
|
||||
@Override
|
||||
public void deregister(HalSensorConfig sensor) {
|
||||
registeredDevices.remove(sensor);
|
||||
public void deregister(HalDeviceConfig deviceConfig) {
|
||||
registeredDevices.remove(deviceConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -168,11 +158,7 @@ public class HalZigbeeController implements HalSensorController, HalEventControl
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setListener(HalEventReportListener listener) {
|
||||
eventListener = listener;
|
||||
}
|
||||
@Override
|
||||
public void setListener(HalSensorReportListener listener) {
|
||||
sensorListener = listener;
|
||||
public void setListener(HalDeviceReportListener listener) {
|
||||
deviceListener = listener;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,8 @@ import org.zwave4j.*;
|
|||
import se.hal.HalContext;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.AbstractDevice;
|
||||
import zutil.log.CompactLogFormatter;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.logging.Logger;
|
||||
|
|
@ -30,8 +28,8 @@ public class HalZWaveController implements HalSensorController, HalEventControll
|
|||
private Options options;
|
||||
private Manager manager;
|
||||
|
||||
private HalSensorReportListener sensorListener;
|
||||
private HalEventReportListener eventListener;
|
||||
private HalDeviceReportListener sensorListener;
|
||||
private HalDeviceReportListener deviceListener;
|
||||
private List<AbstractDevice> registeredDevices;
|
||||
|
||||
|
||||
|
|
@ -303,21 +301,13 @@ public class HalZWaveController implements HalSensorController, HalEventControll
|
|||
// --------------------------
|
||||
|
||||
@Override
|
||||
public void register(HalEventConfig event) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void register(HalSensorConfig sensor) {
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(HalEventConfig event) {
|
||||
registeredDevices.remove(event);
|
||||
}
|
||||
@Override
|
||||
public void deregister(HalSensorConfig sensor) {
|
||||
registeredDevices.remove(sensor);
|
||||
public void deregister(HalDeviceConfig deviceConfig) {
|
||||
registeredDevices.remove(deviceConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -331,13 +321,8 @@ public class HalZWaveController implements HalSensorController, HalEventControll
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setListener(HalEventReportListener listener) {
|
||||
eventListener = listener;
|
||||
public void setListener(HalDeviceReportListener listener) {
|
||||
deviceListener = listener;
|
||||
}
|
||||
@Override
|
||||
public void setListener(HalSensorReportListener listener) {
|
||||
sensorListener = listener;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue