/
myhome-energy.html
161 lines (157 loc) · 9.22 KB
/
myhome-energy.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<script type="text/javascript">
RED.nodes.registerType('myhome-energy',{
category: 'Bticino MyHome',
color: '#a6bbcf',
defaults: {
name: { value: '', required: true },
meterid: { value: '', required: true, validate: RED.validators.number() },
metertype: { value: 'meter', required: true},
meterscope: { value: 'instant', required: true},
topic: { value: '', required: true},
gateway: { type: 'myhome-gateway', required: true },
skipevents: { value: true, required: false},
enablecache: { value: true, required: false},
output2_name: { value: '', required: false},
output2_type: { value: 'metered_Power', required: false}
},
inputs: 1,
inputLabels: function () {
let metertype_isDateRange = (['hour','day','month'].indexOf(this.meterscope) >= 0);
return this._((metertype_isDateRange) ? 'mh-energy.config.inputlabel-daterange' : 'mh-energy.config.inputlabel-any');
},
outputs: 2,
outputLabels: function (index) {
if (index === 0) {
return 'payload';
} else if (index === 1) {
let outputTypeDescr;
let powerUnit = (this.meterscope === 'instant') ? '' : 'h';
if (this.output2_type === 'metered_Power') {
outputTypeDescr = this._('mh-energy.config.secondary-output-content-pwr', {'h':powerUnit});
} else if (this.output2_type === 'metered_Power_asText') {
outputTypeDescr = this._('mh-energy.config.secondary-output-content-pwr-txt', {'h':powerUnit});
} else if (this.output2_type === 'metered_Info') {
outputTypeDescr = this._('mh-energy.config.secondary-output-content-pwr-info');
}
return 'payload' + ((this.output2_name === '') ? '' : ('.' + this.output2_name)) + " = " + outputTypeDescr;
}
},
icon: 'font-awesome/fa-bolt',
paletteLabel: 'MH Energy',
label: function() {
// Return the label itself
return this.name || 'MH Energy';
},
oneditprepare: function() {
let scope = this;
$('#node-input-topic').on('change', function() {
let topicName = $(this).val();
let topicInfo = scope._('mh-energy.config.topic-info' , {'topicName': (topicName) ? topicName : 'topic'});
$('#node-info-topic').prop('title' , topicInfo);
});
$('#node-input-meterscope').on('change', function() {
let curScope = $('#node-input-meterscope').val();
let powerUnit = (curScope === 'instant') ? '' : 'h';
$('#node-input-output2_type option[value="metered_Power"]').text(scope._('mh-energy.config.secondary-output-content-pwr', {'h':powerUnit}));
$('#node-input-output2_type option[value="metered_Power_asText"]').text(scope._('mh-energy.config.secondary-output-content-pwr-txt', {'h':powerUnit}));
});
$('#node-myhome_energy-outputcache-button').on('click', function() {
function doInject(node, customMsg) {
$.ajax({
url: "inject/" + node.id,
type: "POST",
data: JSON.stringify(customMsg||{}),
contentType: "application/json; charset=utf-8",
success: function (resp) {
RED.notify(node._('mh-energy.config.enablecache-outputlog-ok'), {type: 'success'});
},
error: function (jqXHR, textStatus, errorThrown) {
RED.notify(node._('mh-energy.config.enablecache-outputlog-error') + ' ['+ errorThrown +'] ' + textStatus, {type: 'warning'});
}
});
}
let msg = {'__user_inject_props__':'DEBUG_SENDCACHE'};
doInject(scope , msg)
});
}
});
</script>
<script type="text/x-red" data-template-name="myhome-energy">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]mh-energy.config.name-placeholder"/>
</div>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-terminal"></i> <span data-i18n="common.topic"></span></label>
<input type="text" id="node-input-topic" data-i18n="[placeholder]mh-energy.config.topic-placeholder"/>
<i id="node-info-topic" class="fa fa-info-circle" title=""></i>
</div>
<div class="form-row">
<label for="node-input-gateway"><i class="fa fa-server"></i> <span data-i18n="common.gateway"></span></label>
<input type="text" id="node-input-gateway"/>
</div>
<div style="border-top-style: solid ;border-width: 1px; border-color: #CCCCCC; height: 10px;"></div>
<div class="form-row">
<label for="node-input-meterid"><i class="fa fa-bolt"></i> <span data-i18n="mh-energy.config.meterid"></span></label>
<div style="display: inline-block; position: relative; width: 70%; height: 20px;">
<select id="node-input-metertype" style="width:220px">
<option value="meter" data-i18n="mh-energy.config.meter-type-meter">[Power management meter]</option>
<option value="actuator" data-i18n="mh-energy.config.meter-type-actuator">[Power management actuator]</option>
</select>
<div style="position: absolute; left: 228px; right: 0px; top:0px;">
<input type="text" id="node-input-meterid" style="width:100%" placeholder="ID [1-255]"/>
</div>
</div>
<i class="fa fa-info-circle" data-i18n="[title]mh-energy.config.meter-type-info"></i>
</div>
<div class="form-row">
<label for="node-input-meterscope"><i class="fa fa-tachometer"></i> <span data-i18n="mh-energy.config.meterscope"></span></label>
<select id="node-input-meterscope" style="width:70%">
<option value="instant" data-i18n="mh-energy.config.meterscope-instant">[Current power]</option>
<option value="day_uptonow" data-i18n="mh-energy.config.meterscope-dayuptonow">[Daily consumption (today)]</option>
<option value="day" data-i18n="mh-energy.config.meterscope-day">[Daily consumption (time range)]</option>
<option value="hour" data-i18n="mh-energy.config.meterscope-hour">[Hourly consumption (time range)]</option>
<option value="month_uptonow" data-i18n="mh-energy.config.meterscope-monthuptonow">[Monthly consumption (current month)]</option>
<option value="month" data-i18n="mh-energy.config.meterscope-month">[Monthly consumption (time range)]</option>
<option value="sincebegin" data-i18n="mh-energy.config.meterscope-sincebegin">[Full consumption since begin]</option>
</select>
</div>
<div class="form-row">
<label for="node-input-skipevents"><i class="fa fa-ban"></i> <span data-i18n="common.option-skipevents"></span></label>
<label for="node-input-skipevents" style="width:70%">
<input type="checkbox" id="node-input-skipevents" style="display:inline-block; margin-left:0px; width:22px; vertical-align:baseline;"/><span data-i18n="common.option-skipevents-checkbox"></span>
<i class="fa fa-info-circle" data-i18n="[title]common.option-skipevents-info"></i>
</label>
</div>
<div class="form-row">
<label for="node-input-enablecache"><i class="fa fa-retweet"></i> <span data-i18n="mh-energy.config.enablecache"></span></label>
<label for="node-input-enablecache" style="width:70%">
<input type="checkbox" id="node-input-enablecache" style="display:inline-block; margin-left:0px; width:22px; vertical-align:baseline;"/><span data-i18n="mh-energy.config.enablecache-checkbox"></span>
<i class="fa fa-info-circle" data-i18n="[title]mh-energy.config.enablecache-info"></i>
<button type="button" class="red-ui-button red-ui-button-small" style="margin-top: 0px; margin-right: unset; float: right;" id="node-myhome_energy-outputcache-button">
<span data-i18n="mh-energy.config.enablecache-outputlog"></span>
</button>
</label>
</div>
<div class="form-tips form-row" style="max-width:none; background:#EFEFEF">
<i class="fa fa-sign-out"></i> <b><span data-i18n="common.secondary-output-title"></span></b>
<br>
<p style="max-width:450px" data-i18n="common.secondary-output-intro"></p>
<div class="form-row">
<label for="node-input-output2_name" style="width:130px; margin-left:15px"><i class="fa fa-tags"></i> <span data-i18n="common.secondary-output-name"></span></label>
<input type="text" id="node-input-output2_name" data-i18n="[placeholder]common.secondary-output-name-placeholder" style="width:55%"/>
<label for="node-input-output2_name" style="width:15px">
<i class="fa fa-info-circle" data-i18n="[title]common.secondary-output-name-info"></i>
</label>
</div>
<div class="form-row">
<label for="node-input-output2_type" style="width:130px; margin-left:15px"><i class="fa fa-check-square-o"></i> <span data-i18n="common.secondary-output-content"></span></label>
<select id="node-input-output2_type" style="width:60%">
<!-- Select values are set in onEditPrepare because part of them are dynamix and i18n-options does not work -->
<option value="metered_Power">[.metered_Power (number in W)]</option>
<option value="metered_Power_asText">[.metered_Power (text in kW)]</option>
<option value="metered_Info" data-i18n="mh-energy.config.secondary-output-content-pwr-info">[.metered_Info (array of metered details)]</option>
</select>
</div>
</div>
</script>