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

View File

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

View File

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

View File

@@ -4,13 +4,13 @@
<%# ---------------------------------- Magnet ---------------------------------- %> <%# ---------------------------------- Magnet ---------------------------------- %>
<%- include('./GatewaySubdevice', { <%- include('./GatewaySubdevice', {
type: "magnet", type: "magnet",
label: "contact", label: "magnet",
icon: "door-icon", icon: "door-icon",
filterType: "magnet", filterType: "mi.magnet",
docTitle: "The Xiaomi contact", docTitle: "The Xiaomi contact",
incomingSample: `{ incomingSample: `{
cmd: "read_ack" cmd: "read_ack"
model: "sensor_magnet.aq2" model: "magnet"
sid: "158d000112fb5d" sid: "158d000112fb5d"
short_id: 50301 short_id: 50301
data: { data: {
@@ -24,10 +24,10 @@
<%# ---------------------------------- Motion ---------------------------------- %> <%# ---------------------------------- Motion ---------------------------------- %>
<%- include('./GatewaySubdevice', { <%- include('./GatewaySubdevice', {
type: "motion", type: "mi.motion",
label: "motion", label: "motion",
icon: "motion-icon", icon: "motion-icon",
filterType: "motion", filterType: "mi.motion",
docTitle: "The Xiaomi body motion", docTitle: "The Xiaomi body motion",
incomingSample: `{ incomingSample: `{
cmd: "read_ack" cmd: "read_ack"
@@ -44,10 +44,10 @@
<%# ---------------------------------- Sensor HT ---------------------------------- %> <%# ---------------------------------- Sensor HT ---------------------------------- %>
<%- include('./GatewaySubdevice', { <%- include('./GatewaySubdevice', {
type: "ht", type: "mi.weather",
label: "sensor HT", label: "weather",
icon: "thermometer-icon", icon: "thermometer-icon",
filterType: "sensor_ht", filterType: "mi.weather",
docTitle: "The Xiaomi Humidity & Temperature", docTitle: "The Xiaomi Humidity & Temperature",
incomingSample: `{ incomingSample: `{
cmd: "read_ack" cmd: "read_ack"
@@ -67,10 +67,10 @@
<%# ---------------------------------- Switch ---------------------------------- %> <%# ---------------------------------- Switch ---------------------------------- %>
<%- include('./GatewaySubdevice', { <%- include('./GatewaySubdevice', {
type: "switch", type: "mi.switch",
label: "switch", label: "switch",
icon: "mi-switch", icon: "mi-switch",
filterType: "switch", filterType: "mi.switch",
docTitle: "The Xiaomi Switch", docTitle: "The Xiaomi Switch",
incomingSample: `{ incomingSample: `{
cmd: "report" 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); $('<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); var sid = $('<input/>',{id:"node-config-input-sid-"+i,type:"text", placeholder:"SID", style:"width:auto;vertical-align:top"}).appendTo(row);
sid.typedInput({ sid.typedInput({
default: 'weather', default: 'mi.weather',
types: Object.keys(devicesConfig).map(function(type) { types: Object.keys(devicesConfig).map(function(type) {
var cleanType = devicesConfig[type]; var cleanType = devicesConfig[type];
cleanType.value = type; cleanType.value = type;
@@ -67,14 +67,17 @@
}); });
var subdevices = gateway && Object.keys(gateway.subdevices).map(function(sid) { return gateway.subdevices[sid]; }); 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) { subdevices && subdevices.sort(function(a, b) { return a.internalModel > b.internalModel; }).forEach(function(device) {
console.log(device);
if(!devicesConfig[device.internalModel] || !device.sid) { if(!devicesConfig[device.internalModel] || !device.sid) {
return; return;
} }
if(node.deviceList[device.sid]) { if(node.deviceList[device.sid]) {
device.name = node.deviceList[device.sid].name; 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; var listHeight = $("#node-config-input-subdevices").editableList('items').size() * 51 + 50;
$("#node-config-input-subdevices").editableList('height', listHeight); $("#node-config-input-subdevices").editableList('height', listHeight);
@@ -84,7 +87,7 @@
var device = node.deviceList[sid]; var device = node.deviceList[sid];
$("#node-config-input-subdevices").editableList('addItem', { $("#node-config-input-subdevices").editableList('addItem', {
sid: sid, sid: sid,
type: device.internalModel, internalModel: device.internalModel,
name: device.name name: device.name
}); });
}); });
@@ -100,8 +103,8 @@
var deviceElement = $(elt); var deviceElement = $(elt);
var sid = deviceElement.find("#node-config-input-sid-"+i).val(); var sid = deviceElement.find("#node-config-input-sid-"+i).val();
var desc = deviceElement.find("#node-config-input-desc-"+i).val(); var desc = deviceElement.find("#node-config-input-desc-"+i).val();
var model = deviceElement.find("#node-config-input-sid-"+i).typedInput('type'); var internalModel = deviceElement.find("#node-config-input-sid-"+i).typedInput('type');
node.deviceList[sid] = {type: model, name: desc}; node.deviceList[sid] = {internalModel: internalModel, name: desc};
}); });
} }
}); });