Add command templates for publishing complex messages
This commit is contained in:
parent
64cb5a329f
commit
a429137485
@ -25,4 +25,4 @@ if missing_config_fields:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
app.run(debug=False, host='0.0.0.0', port=4000)
|
app.run(debug=True, host='0.0.0.0', port=4000)
|
||||||
|
|||||||
@ -166,7 +166,12 @@ function init(brokerUri) {
|
|||||||
this.onchange()
|
this.onchange()
|
||||||
var topic = this.getAttribute('data-pub-topic');
|
var topic = this.getAttribute('data-pub-topic');
|
||||||
var retain = Boolean(this.getAttribute('data-retain'));
|
var retain = Boolean(this.getAttribute('data-retain'));
|
||||||
publish(topic, this.value, retain);
|
commandTemplate = this.getAttribute('data-command-template');
|
||||||
|
var value = this.value;
|
||||||
|
if (commandTemplate) {
|
||||||
|
value = commandTemplate.replace("%VALUE%", value);
|
||||||
|
}
|
||||||
|
publish(topic, value, retain);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -92,7 +92,8 @@ def slider_widget(label,
|
|||||||
min_val=0,
|
min_val=0,
|
||||||
max_val=255,
|
max_val=255,
|
||||||
step=1,
|
step=1,
|
||||||
retain=False):
|
retain=False,
|
||||||
|
command_template=None):
|
||||||
id_ = make_id()
|
id_ = make_id()
|
||||||
sub_topic = sub_topic or topic
|
sub_topic = sub_topic or topic
|
||||||
template = '''
|
template = '''
|
||||||
@ -103,6 +104,7 @@ def slider_widget(label,
|
|||||||
data-pub-topic="{{topic}}"
|
data-pub-topic="{{topic}}"
|
||||||
data-retain="{{retain | string | lower}}"
|
data-retain="{{retain | string | lower}}"
|
||||||
{% if value_path %} data-value-path="{{value_path}}" {% endif %}
|
{% if value_path %} data-value-path="{{value_path}}" {% endif %}
|
||||||
|
{% if command_template %} data-command-template="{{command_template}}" {% endif %}
|
||||||
min="{{min_val}}" type="range" max="{{max_val}}" step="{{step}}"
|
min="{{min_val}}" type="range" max="{{max_val}}" step="{{step}}"
|
||||||
value="{{min_val}}"/>
|
value="{{min_val}}"/>
|
||||||
<span id="{{id_}}-textual" class="slider-value">-</span>
|
<span id="{{id_}}-textual" class="slider-value">-</span>
|
||||||
@ -121,6 +123,7 @@ def slider_widget(label,
|
|||||||
topic=topic,
|
topic=topic,
|
||||||
unit=unit,
|
unit=unit,
|
||||||
retain=retain,
|
retain=retain,
|
||||||
|
command_template=command_template,
|
||||||
id_=id_)
|
id_=id_)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user