2017-07-02 17:21:47 +02:00
< script type = "text/javascript" >
RED . nodes . registerType ( 'xiaomi-switch' , {
category : 'xiaomi' ,
color : '#3FADB5' ,
defaults : {
gateway : { value : "" , type : "xiaomi-configurator" },
name : { value : "" },
sid : { value : "" , required : true },
outmsg : { value : "{{click}}" },
outmsgdbcl : { value : "{{double_click}}" },
output : { value : "0" }
},
inputs : 1 ,
2018-01-03 12:12:45 +01:00
outputs : 1 ,
2017-07-02 17:21:47 +02:00
paletteLabel : "switch" ,
2018-01-03 15:36:23 +01:00
icon : "mi-switch.png" ,
2017-07-02 17:21:47 +02:00
label : function () {
return this . name || "xiaomi-switch" ;
},
oneditprepare : function () {
var node = this ;
2017-12-31 20:59:38 +01:00
if ( node . sid ) {
$ ( '#node-input-sid' ). val ( node . sid );
}
function changeGateway ( model ) {
var configNodeID = $ ( '#node-input-gateway' ). val ();
if ( configNodeID ) {
var configNode = RED . nodes . node ( configNodeID );
if ( configNode ) {
$ ( '#node-input-sid' ). empty ();
for ( key in configNode . deviceList ) {
var device = configNode . deviceList [ key ];
if ( device . model === model ) {
$ ( '#node-input-sid' ). append ( '<option value="' + device . sid + '">' + device . desc + '</option>' );
}
}
if ( node . sid ) {
$ ( '#node-input-sid option[value="' + node . sid + '"]' ). prop ( 'selected' , true );
}
}
}
}
$ ( "#node-input-sid" ). change ( function () {
if ( ! this . name ) {
$ ( "#node-input-name" ). val ( $ ( '#node-input-sid option:selected' ). text ());
}
});
$ ( "#node-input-gateway" ). change ( function () {
2018-01-01 01:55:59 +01:00
changeGateway ( "switch" );
2017-12-31 20:59:38 +01:00
});
2017-07-02 17:21:47 +02:00
$ ( ".node-input-msg" ). hide ();
$ ( "#node-input-output" ). val ( node . output );
},
oneditsave : function () {
var node = this ;
node . sid = $ ( "#node-input-sid" ). val ();
}
});
</ script >
< script type = "text/x-red" data-template-name = "xiaomi-switch" >
< div class = "form-row" >
< label for = "node-input-gateway" >< i class = "icon-tag" >< /i> Gateway</label>
< input type = "text" id = "node-input-gateway" placeholder = "xiaomi gateway" >
< /div>
< div class = "form-row" >
< label for = "node-input-name" >< i class = "icon-tag" >< /i> Name</label>
< input type = "text" id = "node-input-name" placeholder = "Name" >
< /div>
< div class = "form-row" >
< label for = "node-input-sid" >< i class = "icon-tag" >< /i> Device</label>
< select id = "node-input-sid" placeholder = "xiaomi gateway" >< /select>
< /div>
</ script >
2017-07-03 22:41:43 +02:00
< script type = "text/x-red" data-help-name = "xiaomi-switch" >
< p > The Xiaomi Switch node < /p>
< h3 > Inputs < /h3>
< dl class = "message-properties" >
< dt > payload
< span class = "property-type" > json < /span>
< /dt>
2017-12-31 20:09:56 +01:00
< dd > Gateway < code > switch < /code> and <code>sensor_switch.aq2</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
2017-07-03 22:41:43 +02:00
< /dl>
< h3 > Outputs < /h3>
< ol class = "node-ports" >
2018-01-03 12:12:45 +01:00
< dl class = "message-properties" >
< dt > payload < span class = "property-type" > object < /span></dt>
< dd > Data from gateway , see below . < /dd>
< /dl>
2017-07-03 22:41:43 +02:00
< /ol>
2018-01-03 12:12:45 +01:00
< h4 > Details < /h4>
< p > The incoming message is processed if the < code > sid < /code> matches the configured value for this device.</p>
2017-07-03 22:41:43 +02:00
< p > Sample message :< /p>
2018-01-03 12:12:45 +01:00
< p >< pre > {
cmd : "report"
model : "switch"
sid : "158d000128b124"
short_id : 56773
data : {
status : "click" ,
batteryLevel : 23
}
} < /pre></p>
2017-07-02 17:21:47 +02:00
</ script >