activate / deactivate
This commit is contained in:
parent
143782ce4f
commit
6fa9f1c7bc
@ -11,6 +11,7 @@ var lastTagID = '';
|
|||||||
var timeOutForHoldingLastTagID = null;
|
var timeOutForHoldingLastTagID = null;
|
||||||
const timeOutForHoldingLastTagIDInMillis = Conf.rfid.timeout;
|
const timeOutForHoldingLastTagIDInMillis = Conf.rfid.timeout;
|
||||||
var currentActionState = 0;
|
var currentActionState = 0;
|
||||||
|
var deviceList = null;
|
||||||
|
|
||||||
|
|
||||||
Helper.each(Conf.items, function(item) {
|
Helper.each(Conf.items, function(item) {
|
||||||
@ -201,13 +202,11 @@ function doActionOnRFIDCallback(key) {
|
|||||||
switch(currentActionState) {
|
switch(currentActionState) {
|
||||||
case 0:
|
case 0:
|
||||||
// deactivate alarm system
|
// deactivate alarm system
|
||||||
Log.log( 'deactivate alarm system' );
|
deactivateAlarmSystem(key);
|
||||||
deactivateAlarmSystem();
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
// activate alarm system
|
// activate alarm system
|
||||||
Log.log( 'activate alarm system' );
|
activateAlarmSystem(key);
|
||||||
activateAlarmSystem();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// nothing to do
|
// nothing to do
|
||||||
@ -215,14 +214,41 @@ function doActionOnRFIDCallback(key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* private */
|
/* private */
|
||||||
function activateAlarmSystem() {
|
function isKnownCard(uuid, callbackIfSo) {
|
||||||
msg = '{type:"set_alarm_system_state", data:{state:"F111"}}';
|
if(Helper.isDefinedAndNotNull(deviceList)) {
|
||||||
send(msg);
|
var filterResultDevices = deviceList.filter(function(entry) { return entry.details.uuid === uuid; });
|
||||||
|
Log.inspect('check for ' + uuid + ' in ' + filterResultDevices.length + ' devices', filterResultDevices);
|
||||||
|
if(Helper.isDefinedAndNotNull(filterResultDevices) && filterResultDevices.length > 0) {
|
||||||
|
callbackIfSo();
|
||||||
|
} else {
|
||||||
|
Log.debug('No device for ' + uuid)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.debug('No devices');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* private */
|
/* private */
|
||||||
function deactivateAlarmSystem() {
|
function activateAlarmSystem(key) {
|
||||||
msg = '{type:"set_alarm_system_state", data:{state:"F222"}}';
|
isKnownCard(key, function() {
|
||||||
|
Log.log( 'activate alarm system' );
|
||||||
|
msg = '{type:"set_alarm_system_state", data:{state:"F111"}}';
|
||||||
|
send(msg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/* private */
|
||||||
|
function deactivateAlarmSystem(key) {
|
||||||
|
isKnownCard(key, function() {
|
||||||
|
Log.log( 'deactivate alarm system' );
|
||||||
|
msg = '{type:"set_alarm_system_state", data:{state:"F222"}}';
|
||||||
|
send(msg);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchDeviceList() {
|
||||||
|
msg = '{type:"get_device_list"}';
|
||||||
send(msg);
|
send(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +266,7 @@ var openWebSocket = function() {
|
|||||||
|
|
||||||
ws.on('open', function() {
|
ws.on('open', function() {
|
||||||
Log.log('ws open');
|
Log.log('ws open');
|
||||||
ws.send(Date.now().toString(), {mask: true});
|
fetchDeviceList();
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.on('close', function() {
|
ws.on('close', function() {
|
||||||
@ -248,10 +274,22 @@ var openWebSocket = function() {
|
|||||||
openWebSocket();
|
openWebSocket();
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.on('message', function incoming(data, flags) {
|
ws.on('message', function incoming(rawData, flags) {
|
||||||
// flags.binary will be set if a binary data is received.
|
// flags.binary will be set if a binary data is received.
|
||||||
// flags.masked will be set if the data was masked.
|
// flags.masked will be set if the data was masked.
|
||||||
Log.inspect('data', data);
|
const obj = JSON.parse(rawData);
|
||||||
|
const type = obj.data.type;
|
||||||
|
const data = obj.data.data;
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case 'get_device_list':
|
||||||
|
const devices = data.result.filter(function(entry) { return entry.category.name === 'rfid_card' });
|
||||||
|
deviceList = devices;
|
||||||
|
Log.inspect('Devices', deviceList);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
openWebSocket();
|
openWebSocket();
|
||||||
Loading…
x
Reference in New Issue
Block a user