forked from anerdins/node-red-contrib-nibepi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fan.html
executable file
·93 lines (89 loc) · 3.55 KB
/
fan.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<script type="text/javascript">
RED.nodes.registerType('nibe-fan',{
category: 'input',
color: '#e32222',
defaults: {
server: {value:"", type:"nibe-config"},
name: {value:""},
system: {value:"s1"},
adjust: {value:"0"},
},
inputs:1,
outputs:2,
inputLabels: ["Update"],
outputLabels: ["Fan","Data"],
icon: "inject.svg",
label: function() {
return this.name||"NibePi Fan";
},
oneditprepare: function() {
$.getJSON('/config', function(data) {
let system = $("#node-input-system").val();
$("#node-input-adjust").val(data.home[`adjust_${system}`]);
$('#node-input-system').change(() => {
system = $("#node-input-system").val();
$("#node-input-adjust").val(data.home[`adjust_${system}`]);
});
})
},
oneditsave: function() {
let node = this;
$.getJSON('/config', function(data) {
let system = $("#node-input-system").val();
if(data.home['adjust_'+system]===undefined) data.home['adjust_'+system] = 1;
data.home['adjust_'+system] = $("#node-input-adjust").val();
let out = {data:node,config:data};
$.ajax({
contentType: 'application/json',
data: JSON.stringify(out),
dataType: 'json',
success: function(data){
app.log("device control succeeded");
},
error: function(){
app.log("Device control failed");
},
processData: false,
type: 'POST',
url: "config/"+node.id
});
})
}
});
</script>
<script type="text/x-red" data-template-name="nibe-fan">
<div class="form-row">
<label for="node-input-system"><i class="icon-bookmark"></i> System</label>
<select id="node-input-system">
<option value="s1">System 1</option>
<option value="s2">System 2</option>
<!-- <option value="s3">System 3</option> -->
<!-- <option value="s4">System 4</option> -->
<!-- <option value="s5">System 5</option> -->
<!-- <option value="s6">System 6</option> -->
<!-- <option value="s7">System 7</option> -->
<!-- <option value="s8">System 8</option> -->
</select>
</div>
<div class="form-row">
<label for="node-input-adjust"><i class="icon-bookmark"></i> Curve Adjust</label>
<select id="node-input-adjust">
<option value="2">+2</option>
<option value="1.5">+1.5</option>
<option value="1">+1</option>
<option value="0.5">+0.5</option>
<option value="0">0</option>
<option value="-0.5">-0.5</option>
<option value="-1">-1</option>
<option value="-1.5">-1.5</option>
<option value="-2">-2</option>
</select>
</div>
<div class="form-row">
<label for="node-input-server"><i class="icon-tag"></i> Server</label>
<input type="text" id="node-input-server" placeholder="Server">
</div>
</script>
<script type="text/x-red" data-help-name="nibe-fan">
<p>Fan node for NibePi</p>
</script>