Skip to content

Commit

Permalink
Use custom delimiters in autoconfig template, remove braces partial hack
Browse files Browse the repository at this point in the history
  • Loading branch information
floatplane committed Feb 19, 2024
1 parent f67414b commit 12ac286
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 44 deletions.
11 changes: 0 additions & 11 deletions src/lang/en-us/templates/partials/braces.hpp

This file was deleted.

1 change: 0 additions & 1 deletion src/lang/en-us/templates/templates.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "templates/partials/braces.hpp"
#include "templates/partials/footer.hpp"
#include "templates/partials/header.hpp"
#include "templates/views/autoconfig.hpp"
Expand Down
59 changes: 30 additions & 29 deletions src/lang/en-us/templates/views/autoconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@
namespace views {

const char* autoConfigTemplate PROGMEM = R"====(
{{=<% %>=}}
{
"name": "{{name}}",
"unique_id": "{{unique_id}}",
"name": "<% name %>",
"unique_id": "<% unique_id %>",
"modes": [
"heat_cool",
"cool",
"dry",
{{#supportHeatMode}}
<%#supportHeatMode%>
"heat",
{{/supportHeatMode}}
<%/supportHeatMode%>
"fan_only",
"off"
],
"mode_cmd_t": "{{mode_cmd_t}}",
"mode_stat_t": "{{mode_stat_t}}",
"mode_stat_tpl": "{{>lbrace}}{{>lbrace}} value_json.mode if (value_json is defined and value_json.mode is defined and value_json.mode|length) else 'off' {{>rbraces}}",
"temp_cmd_t": "{{temp_cmd_t}}",
"temp_stat_t": "{{temp_stat_t}}",
"avty_t": "{{avty_t}}",
"mode_cmd_t": "<% mode_cmd_t %>",
"mode_stat_t": "<% mode_stat_t %>",
"mode_stat_tpl": "{{ value_json.mode if (value_json is defined and value_json.mode is defined and value_json.mode|length) else 'off' }}",
"temp_cmd_t": "<% temp_cmd_t %>",
"temp_stat_t": "<% temp_stat_t %>",
"avty_t": "<% avty_t %>",
"pl_not_avail": "offline",
"pl_avail": "online",
"temp_stat_tpl": "{{#tempStatTpl}}{% if (value_json is defined and value_json.{{fieldName}} is defined) %}{% if (value_json.{{fieldName}}|int >= {{minTemp}} and value_json.temperature|int <= {{maxTemp}}) %}{{>lbrace}}{{>lbrace}} value_json.{{fieldName}} {{>rbraces}}{% elif (value_json.{{fieldName}}|int < {{minTemp}}) %}{{minTemp}}{% elif (value_json.{{fieldName}}|int > {{maxTemp}}) %}{{maxTemp}}{% endif %}{% else %}{{defaultTemp}}{% endif %}{{/tempStatTpl}}",
"curr_temp_t": "{{curr_temp_t}}",
"curr_temp_tpl": "{{#currTempTpl}}{{>lbrace}}{{>lbrace}} value_json.{{fieldName}} if (value_json is defined and value_json.{{fieldName}} is defined and value_json.{{fieldName}}|int > {{minTemp}}) {{>rbraces}}{{/currTempTpl}}",
"min_temp": {{min_temp}},
"max_temp": {{max_temp}},
"temp_stat_tpl": "<%#tempStatTpl%>{% if (value_json is defined and value_json.<% fieldName %> is defined) %}{% if (value_json.<% fieldName %>|int >= <% minTemp %> and value_json.temperature|int <= <% maxTemp %>) %}{{ value_json.<% fieldName %> }}{% elif (value_json.<% fieldName %>|int < <% minTemp %>) %}<% minTemp %>{% elif (value_json.<% fieldName %>|int > <% maxTemp %>) %}<% maxTemp %>{% endif %}{% else %}<% defaultTemp %>{% endif %}<%/tempStatTpl%>",
"curr_temp_t": "<% curr_temp_t %>",
"curr_temp_tpl": "<%#currTempTpl%>{{ value_json.<% fieldName %> if (value_json is defined and value_json.<% fieldName %> is defined and value_json.<% fieldName %>|int > <% minTemp %>) }}<%/currTempTpl%>",
"min_temp": <% min_temp %>,
"max_temp": <% max_temp %>,
"temp_step": "1",
"temperature_unit": "F",
"fan_modes": [
Expand All @@ -40,9 +41,9 @@ const char* autoConfigTemplate PROGMEM = R"====(
"3",
"4"
],
"fan_mode_cmd_t": "{{fan_mode_cmd_t}}",
"fan_mode_stat_t": "{{fan_mode_stat_t}}",
"fan_mode_stat_tpl": "{{>lbrace}}{{>lbrace}} value_json.fan if (value_json is defined and value_json.fan is defined and value_json.fan|length) else 'AUTO' {{>rbraces}}",
"fan_mode_cmd_t": "<% fan_mode_cmd_t %>",
"fan_mode_stat_t": "<% fan_mode_stat_t %>",
"fan_mode_stat_tpl": "{{ value_json.fan if (value_json is defined and value_json.fan is defined and value_json.fan|length) else 'AUTO' }}",
"swing_modes": [
"AUTO",
"1",
Expand All @@ -52,21 +53,21 @@ const char* autoConfigTemplate PROGMEM = R"====(
"5",
"SWING"
],
"swing_mode_cmd_t": "{{swing_mode_cmd_t}}",
"swing_mode_stat_t": "{{swing_mode_stat_t}}",
"swing_mode_stat_tpl": "{{>lbrace}}{{>lbrace}} value_json.vane if (value_json is defined and value_json.vane is defined and value_json.vane|length) else 'AUTO' {{>rbraces}}",
"action_topic": "{{action_topic}}",
"action_template": "{{>lbrace}}{{>lbrace}} value_json.action if (value_json is defined and value_json.action is defined and value_json.action|length) else 'idle' {{>rbraces}}",
"swing_mode_cmd_t": "<% swing_mode_cmd_t %>",
"swing_mode_stat_t": "<% swing_mode_stat_t %>",
"swing_mode_stat_tpl": "{{ value_json.vane if (value_json is defined and value_json.vane is defined and value_json.vane|length) else 'AUTO' }}",
"action_topic": "<% action_topic %>",
"action_template": "{{ value_json.action if (value_json is defined and value_json.action is defined and value_json.action|length) else 'idle' }}",
"device": {
"ids": "{{friendlyName}}",
"name": "{{friendlyName}}",
"sw": "Mitsubishi2MQTT {{buildDate}} ({{commitHash}})",
"ids": "<% friendlyName %>",
"name": "<% friendlyName %>",
"sw": "Mitsubishi2MQTT <% buildDate %> (<% commitHash %>)",
"mdl": "HVAC MITSUBISHI",
"mf": "MITSUBISHI ELECTRIC",
"configuration_url": "http://{{localIP}}"
"configuration_url": "http://<% localIP %>"
},
"json_attr_t": "{{json_attr_t}}",
"json_attr_tpl": "{{>lbrace}}{{>lbrace}} {'compressorFrequency': value_json.compressorFrequency if (value_json is defined and value_json.compressorFrequency is defined) else '-1' } | tojson {{>rbraces}}"
"json_attr_t": "<% json_attr_t %>",
"json_attr_tpl": "{{ {'compressorFrequency': value_json.compressorFrequency if (value_json is defined and value_json.compressorFrequency is defined) else '-1' } | tojson }}"
}
)====";
}; // namespace views
4 changes: 1 addition & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1844,9 +1844,7 @@ void sendHomeAssistantConfig() {
// For now, only compressorFrequency
haConfig[F("json_attr_t")] = config.mqtt.ha_state_topic();

String mqttOutput =
Ministache(views::autoConfigTemplate)
.render(haConfig, {{"lbrace", partials::lbrace}, {"rbraces", partials::rbraces}});
String mqttOutput = Ministache(views::autoConfigTemplate).render(haConfig);

mqtt_client.beginPublish(ha_config_topic.c_str(), mqttOutput.length(), true);
mqtt_client.print(mqttOutput);
Expand Down

0 comments on commit 12ac286

Please sign in to comment.