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
* http://www.bootstrap-switch.org
* ========================================================================
* Copyright 2012-2013 Mattia Larentis
*
* ========================================================================
* 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 - Turn checkboxes and radio buttons into toggle switches.
*
* @version v3.3.4
* @homepage https://bttstrp.github.io/bootstrap-switch
* @author Mattia Larentis <mattia@larentis.eu> (http://larentis.eu)
* @license Apache-2.0
*/
.bootstrap-switch {
display: inline-block;
@ -25,7 +13,7 @@
cursor: pointer;
border-radius: 4px;
border: 1px solid;
border-color: #cccccc;
border-color: #ccc;
position: relative;
text-align: left;
overflow: hidden;
@ -54,8 +42,8 @@
-moz-box-sizing: border-box;
box-sizing: border-box;
cursor: pointer;
display: inline-block !important;
height: 100%;
display: table-cell;
vertical-align: middle;
padding: 6px 12px;
font-size: 14px;
line-height: 20px;
@ -100,8 +88,11 @@
margin-top: -1px;
margin-bottom: -1px;
z-index: 100;
color: #333333;
background: #ffffff;
color: #333;
background: #fff;
}
.bootstrap-switch span::before {
content: "\200b";
}
.bootstrap-switch .bootstrap-switch-handle-on {
border-bottom-left-radius: 3px;
@ -120,6 +111,7 @@
z-index: -1;
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-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(){
$(".toggle-switch").bootstrapSwitch();
$(".toggle-switch").bootstrapSwitch({inverse: true});
$(".timestamp").relTimestamp();
});

View file

@ -2,7 +2,7 @@
<div class="col-md-12">
<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">
<table class="table table-hover table-condensed">
@ -24,7 +24,7 @@
<div class="btn-toolbar pull-right">
<input class="toggle-switch" type="checkbox" name="enabled"
data-size="mini" data-on-color="danger"
data-size="mini"
{{#.isEnabled()}}checked{{/.isEnabled()}} >
</div>
</form>

View file

@ -148,7 +148,6 @@
</div>
</div> <!-- /Panel -->
</div>
<div class="col-md-12 vertical-space"></div>
<div class="col-md-12">
<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
*/
public class EventControllerManager extends HalAbstractControllerManager<HalEventController,Event,HalEventConfig>
implements HalDeviceReportListener<HalEventConfig,HalEventData> {
implements HalDeviceReportListener {
private static final Logger logger = LogUtil.getLogger();
private static EventControllerManager instance;
@ -131,7 +131,10 @@ public class EventControllerManager extends HalAbstractControllerManager<HalEven
* Called by Controllers to report received Event data
*/
@Override
public void reportReceived(HalEventConfig eventConfig, HalEventData eventData) {
public void reportReceived(HalDeviceConfig eventConfig, HalDeviceData eventData) {
if (!(eventConfig instanceof HalEventConfig && eventData instanceof HalEventData))
return;
try {
DBConnection db = HalContext.getDB();
Event event = HalDeviceUtil.findDevice(eventConfig, registeredEvents);
@ -153,11 +156,11 @@ public class EventControllerManager extends HalAbstractControllerManager<HalEven
event = new Event();
detectedEvents.add(event);
}
event.setDeviceConfig(eventConfig);
event.setDeviceConfig((HalEventConfig) eventConfig);
}
event.setDeviceData(eventData);
event.setDeviceData((HalEventData) eventData);
// call listeners
for (HalDeviceReportListener<HalEventConfig,HalEventData> listener : event.getReportListeners())
for (HalDeviceReportListener listener : event.getReportListeners())
listener.reportReceived(event.getDeviceConfig(), eventData);
}catch (SQLException e){

View file

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

View file

@ -19,7 +19,9 @@ public abstract class HalAbstractControllerManager<T extends HalAbstractControll
private static final Logger logger = LogUtil.getLogger();
/** 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 **/
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
synchronized (this) {
if (controllerMap == null) {
synchronized (autostartProcessed) {
if (!autostartProcessed) {
for (Iterator<Class<? extends HalAutostartController>> it = pluginManager.getClassIterator(HalAutostartController.class); it.hasNext(); ) {
Class controller = it.next();
logger.fine("Autostarting controller: " + controller.getName());
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")
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;
}
public void addReportListener(HalDeviceReportListener<C,D> listener) {
listeners.add(listener);
public void addReportListener(HalDeviceReportListener listener) {
deviceListeners.add(listener);
}
public void removeReportListener(HalDeviceReportListener<C,D> listener) {
listeners.remove(listener);
public void removeReportListener(HalDeviceReportListener listener) {
deviceListeners.remove(listener);
}
public List<HalDeviceReportListener<C,D>> getReportListeners() {
return listeners;
public List<HalDeviceReportListener> getReportListeners() {
return deviceListeners;
}
}

View file

@ -4,11 +4,8 @@ package se.hal.intf;
/**
* A listener interface that will be called when the
* 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,
PreConfigurationActionListener,
PostConfigurationActionListener,
HalDeviceReportListener<HalDeviceConfig,HalDeviceData> {
HalDeviceReportListener {
@Configurator.Configurable("Trigger only on change")
protected boolean triggerOnChange = true;

View file

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

View file

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

View file

@ -35,7 +35,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* Controller that will connect to a Zigbee USB coordinator.
*/
public class HalZigbeeController implements HalSensorController,
HalEventController,
@ -254,7 +254,7 @@ public class HalZigbeeController implements HalSensorController,
if (config != null) {
registerCluster(endpoint, config);
} 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
public void writeNode(ZigBeeNodeDao node) {
logger.fine("[Node: " + node.getIeeeAddress() + "] Storing Zigbee Node in DB: " +
"IeeAddr: " + node.getIeeeAddress() + ", " +
logger.fine("[Node: " + node.getIeeeAddress() + "]: Storing Zigbee Node in DB: " +
"NetAddr: " + node.getNetworkAddress() + ", " +
"binding: " + node.getBindingTable() + ", " +
"description: " + node.getNodeDescriptor() + ", " +
@ -66,7 +65,7 @@ public class ZigBeeDataStore implements ZigBeeNetworkDataStore {
@Override
public void removeNode(IeeeAddress address) {
logger.fine("[Node: " + address + "] Removing Node from DB.");
logger.fine("[Node: " + address + "]: Removing Node from DB.");
devices.remove(address);
}

View file

@ -29,6 +29,9 @@ import com.zsmartsystems.zigbee.ZigBeeNetworkManager;
import com.zsmartsystems.zigbee.ZigBeeNode;
import com.zsmartsystems.zigbee.zcl.ZclAttribute;
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.LogUtil;
@ -46,6 +49,12 @@ public class HalZigbeeControllerTest {
HalZigbeeController controller = new HalZigbeeController();
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);
handleConsoleInput("h", in, controller.networkManager);