smart-nodes
Version:
266 lines (247 loc) • 10.3 kB
HTML
<script type="text/javascript">
RED.nodes.registerType("smart_hysteresis", {
category: "Smart Nodes",
paletteLabel: "Hysteresis",
color: "#E2D96E",
defaults: {
name: { value: "" },
mode: { value: "HYSTERESIS" }, // HYSTERESIS | MIN_MAX
setpoint: { value: 10 },
hysteresis: { value: 1 },
min: { value: 10 },
max: { value: 20 },
out_higher: { value: '{"topic": ""}' },
out_higher_type: { value: 'json' },
out_lower: { value: '{"topic": ""}' },
out_lower_type: { value: 'json' },
send_only_change: { value: true },
outputs: { value: 1 },
save_state: { value: false },
resend_on_start: { value: false }
},
inputs: 1,
outputs: 2,
icon: "font-awesome/fa-arrows-v",
label: function ()
{
return this.name || this.comparator || "Hysteresis";
},
outputLabels: function (index)
{
return this.outputs == 1 ? "" : ["Höher", "Niedriger"][index];
},
oneditprepare: function ()
{
let node = this;
$("#node-input-mode")
.css("max-width", "70%")
.typedInput({
types: [{
value: "mode",
default: "HYSTERESIS",
options: [
{ value: "HYSTERESIS", label: node._("hysteresis.ui.hysteresis") },
{ value: "MIN_MAX", label: node._("hysteresis.ui.min_max") }
],
}],
});
$("#node-input-mode").on("change", function ()
{
if (this.value == "HYSTERESIS")
{
$(".hysteresis-row").show();
$(".min-max-row").hide();
}
else
{
$(".hysteresis-row").hide();
$(".min-max-row").show();
}
});
$("#node-input-mode").trigger("change");
$("#node-input-setpoint")
.css("max-width", "70%")
.typedInput({
type: "num",
types: ["num"]
});
$("#node-input-hysteresis")
.css("max-width", "70%")
.typedInput({
type: "num",
types: ["num"]
});
$("#node-input-min")
.css("max-width", "70%")
.typedInput({
type: "num",
types: ["num"]
});
$("#node-input-max")
.css("max-width", "70%")
.typedInput({
type: "num",
types: ["num"]
});
$("#node-input-out_higher")
.css("max-width", "70%")
.typedInput({
type: "json",
types: ["json",
{
value: "NOTHING",
label: node._("hysteresis.ui.send_nothing"),
icon: "fa fa-times",
hasValue: false,
}, {
value: "ORIGINAL",
label: node._("hysteresis.ui.original_message"),
icon: "fa fa-arrow-right",
hasValue: false,
}
],
typeField: "#node-input-out_higher_type"
});
$("#node-input-out_lower")
.css("max-width", "70%")
.typedInput({
type: "json",
types: ["json",
{
value: "NOTHING",
label: node._("hysteresis.ui.send_nothing"),
icon: "fa fa-times",
hasValue: false,
}, {
value: "ORIGINAL",
label: node._("hysteresis.ui.original_message"),
icon: "fa fa-arrow-right",
hasValue: false,
}
],
typeField: "#node-input-out_lower_type"
});
$("#node-input-send_only_change")
.css("max-width", "70%")
.typedInput({
type: "bool",
types: [{
value: "send_only_change",
options: [
{ value: "true", label: node._("hysteresis.ui.send_only_change") },
{ value: "false", label: node._("hysteresis.ui.always") },
]
}]
});
$("#node-input-outputs")
.css("max-width", "70%")
.typedInput({
type: "num",
types: [{
value: "outputs",
options: [
{ value: "1", label: node._("hysteresis.ui.common_output") },
{ value: "2", label: node._("hysteresis.ui.separate_output") },
]
}]
});
$("#node-input-save_state").on("change", ev =>
{
if (ev.target.checked)
$("#resend_on_start_row").show();
else
$("#resend_on_start_row").hide();
});
$("#node-input-save_state").trigger("change");
// Backward compatibility
if (this.out_higher_type == "null")
{
this.out_higher_type = "NOTHING";
$("#node-input-out_higher_type").val("NOTHING");
}
if (this.out_lower_type == "null")
{
this.out_lower_type = "NOTHING";
$("#node-input-out_lower_type").val("NOTHING");
}
if (this.out_higher_type == "original")
{
this.out_higher_type = "ORIGINAL";
$("#node-input-out_higher_type").val("ORIGINAL");
}
if (this.out_lower_type == "original")
{
this.out_lower_type = "ORIGINAL";
$("#node-input-out_lower_type").val("ORIGINAL");
}
},
oneditsave: function ()
{
let node = this;
this.setpoint = parseFloat(this.setpoint ?? 10);
this.hysteresis = parseFloat(this.hysteresis ?? 1);
this.min = parseFloat(this.min ?? 10);
this.max = parseFloat(this.max ?? 20);
}
});
</script>
<script type="text/html" data-template-name="smart_hysteresis">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="hysteresis.ui.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]hysteresis.ui.name" />
</div>
<div class="form-row">
<label for="node-input-mode"><i class="fa fa-arrow-right"></i> <span data-i18n="hysteresis.ui.mode"></span></label>
<input id="node-input-mode"/>
</div>
<div class="form-row hysteresis-row">
<label for="node-input-setpoint"><i class="fa fa-sign-out"></i> <span data-i18n="hysteresis.ui.setpoint"></span></label>
<input id="node-input-setpoint" />
</div>
<div class="form-row hysteresis-row">
<label for="node-input-hysteresis"><i class="fa fa-sort"></i> <span data-i18n="hysteresis.ui.hysteresis"></span></label>
<input id="node-input-hysteresis" />
</div>
<div class="form-row min-max-row">
<label for="node-input-min"><i class="fa fa-angle-down"></i> <span data-i18n="hysteresis.ui.min"></span></label>
<input id="node-input-min" />
</div>
<div class="form-row min-max-row">
<label for="node-input-max"><i class="fa fa-angle-up"></i> <span data-i18n="hysteresis.ui.max"></span></label>
<input id="node-input-max" />
</div>
<hr/>
<h4 style="margin: 0.5rem 0;" data-i18n="hysteresis.ui.output_messages"></h4>
<div class="form-row">
<label for="node-input-out_higher"><i class="fa fa-arrow-up"></i> <span data-i18n="hysteresis.ui.over"></span></label>
<input type="text" id="node-input-out_higher"/>
<input type="hidden" id="node-input-out_higher_type">
</div>
<div class="form-row">
<label for="node-input-out_lower"><i class="fa fa-arrow-down"></i> <span data-i18n="hysteresis.ui.under"></span></label>
<input type="text" id="node-input-out_lower" />
<input type="hidden" id="node-input-out_lower_type">
</div>
<div class="form-row">
<label for="node-input-send_only_change"><i class="fa fa-repeat"></i> <span data-i18n="hysteresis.ui.send"></span></label>
<input id="node-input-send_only_change" />
</div>
<div class="form-row">
<label for="node-input-outputs"><i class="fa fa-hashtag"></i> <span data-i18n="hysteresis.ui.outputs"></span></label>
<input id="node-input-outputs" />
</div>
<div class="form-row">
<div><strong data-i18n="hysteresis.ui.note"></strong></div>
<div data-i18n="[html]hysteresis.ui.note_text"></div>
</div>
<hr/>
<h4 style="margin: 0.5rem 0;" data-i18n="hysteresis.ui.system_start"></h4>
<div class="form-row">
<input type="checkbox" id="node-input-save_state" style="width: 20px;" />
<label for="node-input-save_state" style="width: calc(100% - 30px);" data-i18n="hysteresis.ui.save_state"></label>
</div>
<div class="form-row" id="resend_on_start_row">
<input type="checkbox" id="node-input-resend_on_start" style="width: 20px;" />
<label for="node-input-resend_on_start" style="width: calc(100% - 30px);" data-i18n="hysteresis.ui.send_after_start"></label>
</div>
</script>