Removed generics from device listener and updated some js libs

This commit is contained in:
Ziver Koc 2021-07-02 00:06:26 +02:00
parent 53d471c0aa
commit 94bfbbd664
18 changed files with 707 additions and 689 deletions

View file

@ -1,23 +1,11 @@
/* ======================================================================== /**
* bootstrap-switch - v3.3.2 * bootstrap-switch - Turn checkboxes and radio buttons into toggle switches.
* http://www.bootstrap-switch.org *
* ======================================================================== * @version v3.3.4
* Copyright 2012-2013 Mattia Larentis * @homepage https://bttstrp.github.io/bootstrap-switch
* * @author Mattia Larentis <mattia@larentis.eu> (http://larentis.eu)
* ======================================================================== * @license Apache-2.0
* Licensed under the Apache License, Version 2.0 (the "License"); */
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================================
*/
.bootstrap-switch { .bootstrap-switch {
display: inline-block; display: inline-block;
@ -25,7 +13,7 @@
cursor: pointer; cursor: pointer;
border-radius: 4px; border-radius: 4px;
border: 1px solid; border: 1px solid;
border-color: #cccccc; border-color: #ccc;
position: relative; position: relative;
text-align: left; text-align: left;
overflow: hidden; overflow: hidden;
@ -54,8 +42,8 @@
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
cursor: pointer; cursor: pointer;
display: inline-block !important; display: table-cell;
height: 100%; vertical-align: middle;
padding: 6px 12px; padding: 6px 12px;
font-size: 14px; font-size: 14px;
line-height: 20px; line-height: 20px;
@ -100,8 +88,11 @@
margin-top: -1px; margin-top: -1px;
margin-bottom: -1px; margin-bottom: -1px;
z-index: 100; z-index: 100;
color: #333333; color: #333;
background: #ffffff; background: #fff;
}
.bootstrap-switch span::before {
content: "\200b";
} }
.bootstrap-switch .bootstrap-switch-handle-on { .bootstrap-switch .bootstrap-switch-handle-on {
border-bottom-left-radius: 3px; border-bottom-left-radius: 3px;
@ -120,6 +111,7 @@
z-index: -1; z-index: -1;
opacity: 0; opacity: 0;
filter: alpha(opacity=0); filter: alpha(opacity=0);
visibility: hidden;
} }
.bootstrap-switch.bootstrap-switch-mini .bootstrap-switch-handle-on, .bootstrap-switch.bootstrap-switch-mini .bootstrap-switch-handle-on,
.bootstrap-switch.bootstrap-switch-mini .bootstrap-switch-handle-off, .bootstrap-switch.bootstrap-switch-mini .bootstrap-switch-handle-off,

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -3,7 +3,7 @@
// -------------------------------------------------------- // --------------------------------------------------------
$(function(){ $(function(){
$(".toggle-switch").bootstrapSwitch(); $(".toggle-switch").bootstrapSwitch({inverse: true});
$(".timestamp").relTimestamp(); $(".timestamp").relTimestamp();
}); });

View file

@ -2,7 +2,7 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="panel panel-default drop-shadow"> <div class="panel panel-default drop-shadow">
<div class="panel-heading">Detected Plugins</div> <div class="panel-heading">Plugin Administration</div>
<div class="panel-body"> <div class="panel-body">
<table class="table table-hover table-condensed"> <table class="table table-hover table-condensed">
@ -24,7 +24,7 @@
<div class="btn-toolbar pull-right"> <div class="btn-toolbar pull-right">
<input class="toggle-switch" type="checkbox" name="enabled" <input class="toggle-switch" type="checkbox" name="enabled"
data-size="mini" data-on-color="danger" data-size="mini"
{{#.isEnabled()}}checked{{/.isEnabled()}} > {{#.isEnabled()}}checked{{/.isEnabled()}} >
</div> </div>
</form> </form>

View file

@ -148,7 +148,6 @@
</div> </div>
</div> <!-- /Panel --> </div> <!-- /Panel -->
</div> </div>
<div class="col-md-12 vertical-space"></div>
<div class="col-md-12"> <div class="col-md-12">
<div class="panel panel-default drop-shadow"> <div class="panel panel-default drop-shadow">

View file

@ -20,7 +20,7 @@ import java.util.logging.Logger;
* This class manages all SensorController and EventController objects * This class manages all SensorController and EventController objects
*/ */
public class EventControllerManager extends HalAbstractControllerManager<HalEventController,Event,HalEventConfig> public class EventControllerManager extends HalAbstractControllerManager<HalEventController,Event,HalEventConfig>
implements HalDeviceReportListener<HalEventConfig,HalEventData> { implements HalDeviceReportListener {
private static final Logger logger = LogUtil.getLogger(); private static final Logger logger = LogUtil.getLogger();
private static EventControllerManager instance; private static EventControllerManager instance;
@ -131,7 +131,10 @@ public class EventControllerManager extends HalAbstractControllerManager<HalEven
* Called by Controllers to report received Event data * Called by Controllers to report received Event data
*/ */
@Override @Override
public void reportReceived(HalEventConfig eventConfig, HalEventData eventData) { public void reportReceived(HalDeviceConfig eventConfig, HalDeviceData eventData) {
if (!(eventConfig instanceof HalEventConfig && eventData instanceof HalEventData))
return;
try { try {
DBConnection db = HalContext.getDB(); DBConnection db = HalContext.getDB();
Event event = HalDeviceUtil.findDevice(eventConfig, registeredEvents); Event event = HalDeviceUtil.findDevice(eventConfig, registeredEvents);
@ -153,11 +156,11 @@ public class EventControllerManager extends HalAbstractControllerManager<HalEven
event = new Event(); event = new Event();
detectedEvents.add(event); detectedEvents.add(event);
} }
event.setDeviceConfig(eventConfig); event.setDeviceConfig((HalEventConfig) eventConfig);
} }
event.setDeviceData(eventData); event.setDeviceData((HalEventData) eventData);
// call listeners // call listeners
for (HalDeviceReportListener<HalEventConfig,HalEventData> listener : event.getReportListeners()) for (HalDeviceReportListener listener : event.getReportListeners())
listener.reportReceived(event.getDeviceConfig(), eventData); listener.reportReceived(event.getDeviceConfig(), eventData);
}catch (SQLException e){ }catch (SQLException e){

View file

@ -19,7 +19,7 @@ import java.util.logging.Logger;
* This class manages all SensorController and EventController objects * This class manages all SensorController and EventController objects
*/ */
public class SensorControllerManager extends HalAbstractControllerManager<HalAbstractController, Sensor, HalSensorConfig> public class SensorControllerManager extends HalAbstractControllerManager<HalAbstractController, Sensor, HalSensorConfig>
implements HalDeviceReportListener<HalSensorConfig, HalSensorData> { implements HalDeviceReportListener {
private static final Logger logger = LogUtil.getLogger(); private static final Logger logger = LogUtil.getLogger();
private static SensorControllerManager instance; private static SensorControllerManager instance;
@ -133,7 +133,10 @@ public class SensorControllerManager extends HalAbstractControllerManager<HalAbs
* Called by Controllers to report received Sensor data * Called by Controllers to report received Sensor data
*/ */
@Override @Override
public void reportReceived(HalSensorConfig sensorConfig, HalSensorData sensorData) { public void reportReceived(HalDeviceConfig sensorConfig, HalDeviceData sensorData) {
if (!(sensorConfig instanceof HalSensorConfig && sensorData instanceof HalSensorData))
return;
try{ try{
DBConnection db = HalContext.getDB(); DBConnection db = HalContext.getDB();
Sensor sensor = HalDeviceUtil.findDevice(sensorConfig, registeredSensors); Sensor sensor = HalDeviceUtil.findDevice(sensorConfig, registeredSensors);
@ -155,11 +158,11 @@ public class SensorControllerManager extends HalAbstractControllerManager<HalAbs
sensor = new Sensor(); sensor = new Sensor();
detectedSensors.add(sensor); detectedSensors.add(sensor);
} }
sensor.setDeviceConfig(sensorConfig); sensor.setDeviceConfig((HalSensorConfig) sensorConfig);
} }
sensor.setDeviceData(sensorData); sensor.setDeviceData((HalSensorData) sensorData);
// call listeners // call listeners
for (HalDeviceReportListener<HalSensorConfig,HalSensorData> listener : sensor.getReportListeners()) for (HalDeviceReportListener listener : sensor.getReportListeners())
listener.reportReceived(sensorConfig, sensorData); listener.reportReceived(sensorConfig, sensorData);
} catch (SQLException e){ } catch (SQLException e){

View file

@ -19,7 +19,9 @@ public abstract class HalAbstractControllerManager<T extends HalAbstractControll
private static final Logger logger = LogUtil.getLogger(); private static final Logger logger = LogUtil.getLogger();
/** A map of all instantiated controllers **/ /** A map of all instantiated controllers **/
protected static Map<Class, HalAbstractController> controllerMap = new ConcurrentHashMap<>();; protected static Map<Class, HalAbstractController> controllerMap = new ConcurrentHashMap<>();
/** Internal variable indicating if autostart controllers have been processed **/
private Boolean autostartProcessed = false;
/** All available sensor plugins **/ /** All available sensor plugins **/
protected List<Class<? extends C>> availableDeviceConfigs = new ArrayList<>(); protected List<Class<? extends C>> availableDeviceConfigs = new ArrayList<>();
@ -41,12 +43,14 @@ public abstract class HalAbstractControllerManager<T extends HalAbstractControll
// Instantiate autostart controllers, but only the first time // Instantiate autostart controllers, but only the first time
synchronized (this) { synchronized (autostartProcessed) {
if (controllerMap == null) { if (!autostartProcessed) {
for (Iterator<Class<? extends HalAutostartController>> it = pluginManager.getClassIterator(HalAutostartController.class); it.hasNext(); ) { for (Iterator<Class<? extends HalAutostartController>> it = pluginManager.getClassIterator(HalAutostartController.class); it.hasNext(); ) {
Class controller = it.next(); Class controller = it.next();
logger.fine("Autostarting controller: " + controller.getName());
getControllerInstance(controller); // Instantiate controller getControllerInstance(controller); // Instantiate controller
} }
autostartProcessed = true;
} }
} }
} }

View file

@ -46,7 +46,7 @@ public abstract class HalAbstractDevice<V extends HalAbstractDevice, C extends H
@DBColumn("map_y") @DBColumn("map_y")
private double y; private double y;
protected transient List<HalDeviceReportListener<C,D>> listeners = new LinkedList<>(); protected transient List<HalDeviceReportListener> deviceListeners = new LinkedList<>();
// ---------------------------------------------------- // ----------------------------------------------------
@ -200,13 +200,13 @@ public abstract class HalAbstractDevice<V extends HalAbstractDevice, C extends H
this.y = y; this.y = y;
} }
public void addReportListener(HalDeviceReportListener<C,D> listener) { public void addReportListener(HalDeviceReportListener listener) {
listeners.add(listener); deviceListeners.add(listener);
} }
public void removeReportListener(HalDeviceReportListener<C,D> listener) { public void removeReportListener(HalDeviceReportListener listener) {
listeners.remove(listener); deviceListeners.remove(listener);
} }
public List<HalDeviceReportListener<C,D>> getReportListeners() { public List<HalDeviceReportListener> getReportListeners() {
return listeners; return deviceListeners;
} }
} }

View file

@ -4,11 +4,8 @@ package se.hal.intf;
/** /**
* A listener interface that will be called when the * A listener interface that will be called when the
* Event or Sensor that it is registered to receives a report * Event or Sensor that it is registered to receives a report
*
* @param <C> is the device configuration class
* @param <D> is the device data class
*/ */
public interface HalDeviceReportListener<C extends HalDeviceConfig, D extends HalDeviceData> { public interface HalDeviceReportListener {
void reportReceived(C deviceConfig, D deviceData); void reportReceived(HalDeviceConfig deviceConfig, HalDeviceData deviceData);
} }

View file

@ -12,7 +12,7 @@ import zutil.ui.conf.Configurator.PreConfigurationActionListener;
public abstract class DeviceTrigger implements HalTrigger, public abstract class DeviceTrigger implements HalTrigger,
PreConfigurationActionListener, PreConfigurationActionListener,
PostConfigurationActionListener, PostConfigurationActionListener,
HalDeviceReportListener<HalDeviceConfig,HalDeviceData> { HalDeviceReportListener {
@Configurator.Configurable("Trigger only on change") @Configurator.Configurable("Trigger only on change")
protected boolean triggerOnChange = true; protected boolean triggerOnChange = true;

View file

@ -2,9 +2,7 @@ package se.hal.plugin.tellstick;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import se.hal.intf.HalDeviceReportListener; import se.hal.intf.*;
import se.hal.intf.HalEventConfig;
import se.hal.intf.HalEventData;
import se.hal.plugin.tellstick.test.TestEventDevice; import se.hal.plugin.tellstick.test.TestEventDevice;
import se.hal.plugin.tellstick.test.TestProtocol; import se.hal.plugin.tellstick.test.TestProtocol;
@ -47,10 +45,10 @@ public class TellstickSerialCommEventTest {
// Setup // Setup
TellstickSerialComm tellstick = new TellstickSerialComm(); TellstickSerialComm tellstick = new TellstickSerialComm();
final ArrayList<HalEventConfig> list = new ArrayList<>(); final ArrayList<HalEventConfig> list = new ArrayList<>();
tellstick.setListener(new HalDeviceReportListener<HalEventConfig,HalEventData>() { tellstick.addListener(new HalDeviceReportListener() {
@Override @Override
public void reportReceived(HalEventConfig e, HalEventData d) { public void reportReceived(HalDeviceConfig e, HalDeviceData d) {
list.add(e); list.add((HalEventConfig) e);
} }
}); });
// Execution // Execution
@ -65,10 +63,10 @@ public class TellstickSerialCommEventTest {
// Setup // Setup
TellstickSerialComm tellstick = new TellstickSerialComm(); TellstickSerialComm tellstick = new TellstickSerialComm();
final ArrayList<HalEventConfig> list = new ArrayList<>(); final ArrayList<HalEventConfig> list = new ArrayList<>();
tellstick.setListener(new HalDeviceReportListener<HalEventConfig,HalEventData>() { tellstick.addListener(new HalDeviceReportListener() {
@Override @Override
public void reportReceived(HalEventConfig e, HalEventData d) { public void reportReceived(HalDeviceConfig e, HalDeviceData d) {
list.add(e); list.add((HalEventConfig) e);
} }
}); });
// Execution // Execution

View file

@ -2,9 +2,7 @@ package se.hal.plugin.tellstick;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import se.hal.intf.HalDeviceReportListener; import se.hal.intf.*;
import se.hal.intf.HalSensorConfig;
import se.hal.intf.HalSensorData;
import se.hal.plugin.tellstick.test.TestProtocol; import se.hal.plugin.tellstick.test.TestProtocol;
import se.hal.plugin.tellstick.test.TestSensorDevice; import se.hal.plugin.tellstick.test.TestSensorDevice;
@ -32,10 +30,10 @@ public class TellstickSerialCommSensorTest {
// Setup // Setup
TellstickSerialComm tellstick = new TellstickSerialComm(); TellstickSerialComm tellstick = new TellstickSerialComm();
final ArrayList<HalSensorConfig> list = new ArrayList<>(); final ArrayList<HalSensorConfig> list = new ArrayList<>();
tellstick.setListener(new HalDeviceReportListener<HalSensorConfig,HalSensorData>() { tellstick.addListener(new HalDeviceReportListener() {
@Override @Override
public void reportReceived(HalSensorConfig e, HalSensorData d) { public void reportReceived(HalDeviceConfig e, HalDeviceData d) {
list.add(e); list.add((HalSensorConfig) e);
} }
}); });
// Execution // Execution
@ -50,10 +48,10 @@ public class TellstickSerialCommSensorTest {
// Setup // Setup
TellstickSerialComm tellstick = new TellstickSerialComm(); TellstickSerialComm tellstick = new TellstickSerialComm();
final ArrayList<HalSensorConfig> list = new ArrayList<>(); final ArrayList<HalSensorConfig> list = new ArrayList<>();
tellstick.setListener(new HalDeviceReportListener<HalSensorConfig,HalSensorData>() { tellstick.addListener(new HalDeviceReportListener() {
@Override @Override
public void reportReceived(HalSensorConfig e, HalSensorData d) { public void reportReceived(HalDeviceConfig e, HalDeviceData d) {
list.add(e); list.add((HalSensorConfig) e);
} }
}); });
// Execution // Execution

View file

@ -35,7 +35,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
* * Controller that will connect to a Zigbee USB coordinator.
*/ */
public class HalZigbeeController implements HalSensorController, public class HalZigbeeController implements HalSensorController,
HalEventController, HalEventController,
@ -254,7 +254,7 @@ public class HalZigbeeController implements HalSensorController,
if (config != null) { if (config != null) {
registerCluster(endpoint, config); registerCluster(endpoint, config);
} else { } else {
logger.finest("[Node: " + endpoint.getIeeeAddress() + "] Cluster ID '" + inputClusterId + "' is not supported."); logger.finest("[Node: " + endpoint.getIeeeAddress() + ", Endpoint: " + endpoint.getEndpointId() + "] Cluster ID '" + inputClusterId + "' is not supported.");
} }
} }
} }

View file

@ -52,8 +52,7 @@ public class ZigBeeDataStore implements ZigBeeNetworkDataStore {
@Override @Override
public void writeNode(ZigBeeNodeDao node) { public void writeNode(ZigBeeNodeDao node) {
logger.fine("[Node: " + node.getIeeeAddress() + "] Storing Zigbee Node in DB: " + logger.fine("[Node: " + node.getIeeeAddress() + "]: Storing Zigbee Node in DB: " +
"IeeAddr: " + node.getIeeeAddress() + ", " +
"NetAddr: " + node.getNetworkAddress() + ", " + "NetAddr: " + node.getNetworkAddress() + ", " +
"binding: " + node.getBindingTable() + ", " + "binding: " + node.getBindingTable() + ", " +
"description: " + node.getNodeDescriptor() + ", " + "description: " + node.getNodeDescriptor() + ", " +
@ -66,7 +65,7 @@ public class ZigBeeDataStore implements ZigBeeNetworkDataStore {
@Override @Override
public void removeNode(IeeeAddress address) { public void removeNode(IeeeAddress address) {
logger.fine("[Node: " + address + "] Removing Node from DB."); logger.fine("[Node: " + address + "]: Removing Node from DB.");
devices.remove(address); devices.remove(address);
} }

View file

@ -29,6 +29,9 @@ import com.zsmartsystems.zigbee.ZigBeeNetworkManager;
import com.zsmartsystems.zigbee.ZigBeeNode; import com.zsmartsystems.zigbee.ZigBeeNode;
import com.zsmartsystems.zigbee.zcl.ZclAttribute; import com.zsmartsystems.zigbee.zcl.ZclAttribute;
import com.zsmartsystems.zigbee.zcl.ZclCluster; import com.zsmartsystems.zigbee.zcl.ZclCluster;
import se.hal.intf.HalDeviceConfig;
import se.hal.intf.HalDeviceData;
import se.hal.intf.HalDeviceReportListener;
import zutil.log.CompactLogFormatter; import zutil.log.CompactLogFormatter;
import zutil.log.LogUtil; import zutil.log.LogUtil;
@ -46,6 +49,12 @@ public class HalZigbeeControllerTest {
HalZigbeeController controller = new HalZigbeeController(); HalZigbeeController controller = new HalZigbeeController();
controller.initialize("COM5", HalZigbeeController.ZIGBEE_DONGLE_CC2531); controller.initialize("COM5", HalZigbeeController.ZIGBEE_DONGLE_CC2531);
controller.addListener(new HalDeviceReportListener() {
@Override
public void reportReceived(HalDeviceConfig deviceConfig, HalDeviceData deviceData) {
System.out.println("Device reported: " + deviceConfig + " , " + deviceData);
}
});
Scanner in = new Scanner(System.in); Scanner in = new Scanner(System.in);
handleConsoleInput("h", in, controller.networkManager); handleConsoleInput("h", in, controller.networkManager);