2
0

fix(configurator): use internalModel as filter type

This commit is contained in:
Pierre CLEMENT
2018-02-19 21:10:27 +01:00
parent f4d54d714b
commit 03af0b8c06
5 changed files with 30 additions and 24 deletions

View File

@@ -25,6 +25,7 @@ export class GatewayMessage {
| MessageData.GatewayMessageReadAckReportWeatherData
| MessageData.GatewayMessageDefaultSubdeviceData
| any;
timestamp: number;
constructor(raw: GatewayRawMessage) {
Object.assign(this, raw);
@@ -34,6 +35,7 @@ export class GatewayMessage {
if (raw.data) {
this.data = JSON.parse(raw.data) || raw.data;
}
this.timestamp = +new Date;
}
isHeartbeat(): boolean {

View File

@@ -20,7 +20,9 @@ export abstract class GatewaySubdevice extends events.EventEmitter {
}
handleMessage(msg: GatewayMessage): void {
this.voltage = (<GatewayMessageDefaultSubdeviceData> msg.data).voltage;
if ((<GatewayMessageDefaultSubdeviceData> msg.data).voltage) {
this.voltage = (<GatewayMessageDefaultSubdeviceData> msg.data).voltage;
}
this.message = msg;
}
@@ -31,8 +33,8 @@ export abstract class GatewaySubdevice extends events.EventEmitter {
abstract get internalModel(): string;
toJSON() {
let json:any = {};
for(let prop of Object.keys(this)) {
let json: any = {};
for (let prop of Object.keys(this)) {
json[prop] = this[prop];
}
delete json._events;

View File

@@ -25,13 +25,12 @@
var configNodeID = $('#node-input-gateway').val();
if (configNodeID) {
var configNode = RED.nodes.node(configNodeID);
console.log(model, configNode);
if(configNode) {
$('#node-input-sid').empty();
for (key in configNode.deviceList) {
var device = configNode.deviceList[key];
if (device.type === model) {
$('#node-input-sid').append('<option value="' + device.sid + '">' + device.desc + ' - ' + device.sid + '</option>');
for (sid in configNode.deviceList) {
var device = configNode.deviceList[sid];
if (device.internalModel === model) {
$('#node-input-sid').append('<option value="' + sid + '">' + device.desc + ' - ' + sid + '</option>');
}
}
if(node.sid) {

View File

@@ -4,13 +4,13 @@
<%# ---------------------------------- Magnet ---------------------------------- %>
<%- include('./GatewaySubdevice', {
type: "magnet",
label: "contact",
label: "magnet",
icon: "door-icon",
filterType: "magnet",
filterType: "mi.magnet",
docTitle: "The Xiaomi contact",
incomingSample: `{
cmd: "read_ack"
model: "sensor_magnet.aq2"
model: "magnet"
sid: "158d000112fb5d"
short_id: 50301
data: {
@@ -24,10 +24,10 @@
<%# ---------------------------------- Motion ---------------------------------- %>
<%- include('./GatewaySubdevice', {
type: "motion",
type: "mi.motion",
label: "motion",
icon: "motion-icon",
filterType: "motion",
filterType: "mi.motion",
docTitle: "The Xiaomi body motion",
incomingSample: `{
cmd: "read_ack"
@@ -44,10 +44,10 @@
<%# ---------------------------------- Sensor HT ---------------------------------- %>
<%- include('./GatewaySubdevice', {
type: "ht",
label: "sensor HT",
type: "mi.weather",
label: "weather",
icon: "thermometer-icon",
filterType: "sensor_ht",
filterType: "mi.weather",
docTitle: "The Xiaomi Humidity & Temperature",
incomingSample: `{
cmd: "read_ack"
@@ -67,10 +67,10 @@
<%# ---------------------------------- Switch ---------------------------------- %>
<%- include('./GatewaySubdevice', {
type: "switch",
type: "mi.switch",
label: "switch",
icon: "mi-switch",
filterType: "switch",
filterType: "mi.switch",
docTitle: "The Xiaomi Switch",
incomingSample: `{
cmd: "report"

View File

@@ -33,7 +33,7 @@
$('<label/>',{for:"node-config-input-sid-"+i, style:"margin-left: 3px; width: 15px;vertical-align:middle"}).appendTo(row);
var sid = $('<input/>',{id:"node-config-input-sid-"+i,type:"text", placeholder:"SID", style:"width:auto;vertical-align:top"}).appendTo(row);
sid.typedInput({
default: 'weather',
default: 'mi.weather',
types: Object.keys(devicesConfig).map(function(type) {
var cleanType = devicesConfig[type];
cleanType.value = type;
@@ -67,14 +67,17 @@
});
var subdevices = gateway && Object.keys(gateway.subdevices).map(function(sid) { return gateway.subdevices[sid]; });
subdevices && subdevices.sort(function(a, b) { return a.internalModel > b.internalModel; }).forEach(function(device) {
console.log(device);
if(!devicesConfig[device.internalModel] || !device.sid) {
return;
}
if(node.deviceList[device.sid]) {
device.name = node.deviceList[device.sid].name;
}
$("#node-config-input-subdevices").editableList('addItem', device);
$("#node-config-input-subdevices").editableList('addItem', {
sid: device.sid,
internalModel: device.internalModel,
name: device.name
});
});
var listHeight = $("#node-config-input-subdevices").editableList('items').size() * 51 + 50;
$("#node-config-input-subdevices").editableList('height', listHeight);
@@ -84,7 +87,7 @@
var device = node.deviceList[sid];
$("#node-config-input-subdevices").editableList('addItem', {
sid: sid,
type: device.internalModel,
internalModel: device.internalModel,
name: device.name
});
});
@@ -100,8 +103,8 @@
var deviceElement = $(elt);
var sid = deviceElement.find("#node-config-input-sid-"+i).val();
var desc = deviceElement.find("#node-config-input-desc-"+i).val();
var model = deviceElement.find("#node-config-input-sid-"+i).typedInput('type');
node.deviceList[sid] = {type: model, name: desc};
var internalModel = deviceElement.find("#node-config-input-sid-"+i).typedInput('type');
node.deviceList[sid] = {internalModel: internalModel, name: desc};
});
}
});