node-red-contrib-clowire
Version:
clowire for node-red
193 lines (171 loc) • 7.46 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('clowire config', {
category: 'config',
defaults: {
host: { value: "localhost", required: true },
port: { value: 8666, required: true, validate: RED.validators.number() },
},
label: function () {
return this.host + ":" + this.port;
}
});
</script>
<script type="text/html" data-template-name="clowire config">
<div class="form-row">
<label for="node-config-input-host"><i class="fa fa-bookmark"></i> Host</label>
<input type="text" id="node-config-input-host">
</div>
<div class="form-row">
<label for="node-config-input-port"><i class="fa fa-bookmark"></i> Port</label>
<input type="text" id="node-config-input-port">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('climate board', {
category: 'clowire',
defaults: {
name: { value: "" },
server: { value: "", type: "clowire config", required: true },
entity_id: { value: "" },
uid: { value: "", required: true },
address: { value: "", required: true },
devtype: { value: "clowire", required: true },
},
color: "#3FADB5",
inputs: 1,
outputs: 1,
icon: "arrow-in.svg",
label: function () {
return this.name || this.uid + '/' + this.entity_id;
},
oneditprepare: function () {
let n = this
n.data = {}
$("#node-input-devtype").change(function () {
if(n.data.data)
handleFn($(this).val())
})
function handleFn(val) {
/* if (val === 'switch') {
n.typeList = ['switch', 'light']
}
else {
} */
n.typeList = ['climate']
handleSelectData(n.data, n)
}
function handleSelectData(data, n, type) {
data = data.data
$('#node-input-entity_id').html('')
if (data.homeAssistant) {
let states = data.homeAssistant.states
for (let state in states) {
if (n.typeList.indexOf(states[state].entity_id.split('.')[0]) === -1)
continue
let $row = $(`<option value="${states[state].entity_id}">${states[state].attributes.friendly_name}/${states[state].entity_id}</option>`)
if (states[state].entity_id === self.entity_id)
$row = $(`<option value="${states[state].entity_id}" selected = "selected">${states[state].attributes.friendly_name}/${states[state].entity_id}</option>`)
$('#node-input-entity_id').append($row)
}
}
}
$.getJSON('GetHaDevList', function (data) {
n.data = data
handleFn(n.devtype)
})
},
});
</script>
<script type="text/html" data-template-name="climate board">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-server"><i class="fa fa-tag"></i>TCP服务</label>
<input type="text" id="node-input-server" >
</div>
<div class="form-row">
<label for="node-input-uid"><i class="fa fa-tag"></i> 面板地址</label>
<input type="text" id="node-input-uid" >
</div>
<div class="form-row">
<label for="node-input-devtype"><i class="fa fa-tag"></i> 设备类型</label>
<select id="node-input-devtype" style="width:125px !important">
<option value="clowire">克伦威尔</option>
</select>
</div>
<div class="form-row">
<label for="node-input-entity_id"><i class="fa fa-tag"></i> entity_id</label>
<select id="node-input-entity_id" style="width:70%">
</select>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('switch board', {
category: 'clowire',
defaults: {
name: { value: "" },
server: { value: "", type: "clowire config", required: true },
entity_id: { value: "" },
uid: { value: "", required: true },
address: { value: "", required: true },
devtype: { value: "clowire", required: true },
},
color: "#87A980",
inputs: 1,
outputs: 1,
icon: "Redis.svg",
label: function () {
return this.name || this.uid + '/' + this.address + '/' + this.entity_id;
},
oneditprepare: function () {
let self = this
$.getJSON('GetHaDevList', function (data) {
data = data.data
if (data.homeAssistant) {
let states = data.homeAssistant.states
for (let state in states) {
if (['switch', 'light'].indexOf(states[state].entity_id.split('.')[0]) === -1)
continue
let $row = $(`<option value="${states[state].entity_id}">${states[state].attributes.friendly_name}/${states[state].entity_id}</option>`)
if (states[state].entity_id === self.entity_id)
$row = $(`<option value="${states[state].entity_id}" selected = "selected">${states[state].attributes.friendly_name}/${states[state].entity_id}</option>`)
$('#node-input-entity_id').append($row)
}
}
})
},
});
</script>
<script type="text/html" data-template-name="switch board">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-server"><i class="fa fa-tag"></i>TCP服务</label>
<input type="text" id="node-input-server" >
</div>
<div class="form-row">
<label for="node-input-uid"><i class="fa fa-tag"></i> 面板地址</label>
<input type="text" id="node-input-uid" >
</div>
<div class="form-row">
<label for="node-input-address"><i class="fa fa-tag"></i> 按钮地址</label>
<input type="text" id="node-input-address" >
</div>
<div class="form-row">
<label for="node-input-devtype"><i class="fa fa-tag"></i> 设备类型</label>
<select id="node-input-devtype" style="width:125px !important">
<option value="clowire">克伦威尔</option>
<option value="hasskit">hasskit</option>
<option value="alive">奥莱维</option>
</select>
</div>
<div class="form-row" >
<label for="node-input-entity_id" ><i class="fa fa-tag"></i> entity_id</label>
<select id="node-input-entity_id" style="width:70%">
</select>
</div>
</script>