Merge branch 'pr114'

This commit is contained in:
Thomas Basler 2022-09-05 20:10:08 +02:00
commit 83ca402306
8 changed files with 53 additions and 3 deletions

View File

@ -4,7 +4,7 @@
#include <Arduino.h>
#define CONFIG_FILENAME "/config.bin"
#define CONFIG_VERSION 0x00011400 // 0.1.20 // make sure to clean all after change
#define CONFIG_VERSION 0x00011500 // 0.1.21 // make sure to clean all after change
#define WIFI_MAX_SSID_STRLEN 31
#define WIFI_MAX_PASSWORD_STRLEN 64
@ -76,6 +76,8 @@ struct CONFIG_T {
char Mqtt_RootCaCert[MQTT_MAX_ROOT_CA_CERT_STRLEN + 1];
char Mqtt_Hostname[MQTT_MAX_HOSTNAME_STRLEN + 1];
bool Mqtt_Hass_Expire;
};
class ConfigurationClass {

View File

@ -72,6 +72,7 @@
#define DTU_PA_LEVEL 0
#define MQTT_HASS_ENABLED false
#define MQTT_HASS_EXPIRE true
#define MQTT_HASS_RETAIN true
#define MQTT_HASS_TOPIC "homeassistant/"
#define MQTT_HASS_INDIVIDUALPANELS false

View File

@ -53,6 +53,7 @@ void ConfigurationClass::init()
config.Dtu_PaLevel = DTU_PA_LEVEL;
config.Mqtt_Hass_Enabled = MQTT_HASS_ENABLED;
config.Mqtt_Hass_Expire = MQTT_HASS_EXPIRE;
config.Mqtt_Hass_Retain = MQTT_HASS_RETAIN;
strlcpy(config.Mqtt_Hass_Topic, MQTT_HASS_TOPIC, sizeof(config.Mqtt_Hass_Topic));
config.Mqtt_Hass_IndividualPanels = MQTT_HASS_INDIVIDUALPANELS;
@ -151,6 +152,10 @@ void ConfigurationClass::migrate()
strlcpy(config.Mqtt_Hostname, config.Mqtt_Hostname_Short, sizeof(config.Mqtt_Hostname_Short));
}
if (config.Cfg_Version < 0x00011500) {
config.Mqtt_Hass_Expire = MQTT_HASS_EXPIRE;
}
config.Cfg_Version = CONFIG_VERSION;
write();
}

View File

@ -116,7 +116,9 @@ void MqttHassPublishingClass::publishField(std::shared_ptr<InverterAbstract> inv
root[F("unit_of_meas")] = inv->Statistics()->getChannelFieldUnit(channel, fieldType.fieldId);
root[F("uniq_id")] = String(serial) + "_ch" + String(channel) + "_" + fieldName;
root[F("dev")] = deviceObj;
if (Configuration.get().Mqtt_Hass_Expire) {
root[F("exp_aft")] = Hoymiles.getNumInverters() * Configuration.get().Mqtt_PublishInterval * 2;
}
if (devCls != 0) {
root[F("dev_cla")] = devCls;
}

View File

@ -43,6 +43,7 @@ void WebApiMqttClass::onMqttStatus(AsyncWebServerRequest* request)
root[F("mqtt_lwt_topic")] = String(config.Mqtt_Topic) + config.Mqtt_LwtTopic;
root[F("mqtt_publish_interval")] = config.Mqtt_PublishInterval;
root[F("mqtt_hass_enabled")] = config.Mqtt_Hass_Enabled;
root[F("mqtt_hass_expire")] = config.Mqtt_Hass_Expire;
root[F("mqtt_hass_retain")] = config.Mqtt_Hass_Retain;
root[F("mqtt_hass_topic")] = config.Mqtt_Hass_Topic;
root[F("mqtt_hass_individualpanels")] = config.Mqtt_Hass_IndividualPanels;
@ -71,6 +72,7 @@ void WebApiMqttClass::onMqttAdminGet(AsyncWebServerRequest* request)
root[F("mqtt_lwt_offline")] = config.Mqtt_LwtValue_Offline;
root[F("mqtt_publish_interval")] = config.Mqtt_PublishInterval;
root[F("mqtt_hass_enabled")] = config.Mqtt_Hass_Enabled;
root[F("mqtt_hass_expire")] = config.Mqtt_Hass_Expire;
root[F("mqtt_hass_retain")] = config.Mqtt_Hass_Retain;
root[F("mqtt_hass_topic")] = config.Mqtt_Hass_Topic;
root[F("mqtt_hass_individualpanels")] = config.Mqtt_Hass_IndividualPanels;
@ -111,7 +113,23 @@ void WebApiMqttClass::onMqttAdminPost(AsyncWebServerRequest* request)
return;
}
if (!(root.containsKey("mqtt_enabled") && root.containsKey("mqtt_hostname") && root.containsKey("mqtt_port") && root.containsKey("mqtt_username") && root.containsKey("mqtt_password") && root.containsKey("mqtt_topic") && root.containsKey("mqtt_retain") && root.containsKey("mqtt_tls") && root.containsKey("mqtt_lwt_topic") && root.containsKey("mqtt_lwt_online") && root.containsKey("mqtt_lwt_offline") && root.containsKey("mqtt_publish_interval") && root.containsKey("mqtt_hass_enabled") && root.containsKey("mqtt_hass_retain") && root.containsKey("mqtt_hass_topic") && root.containsKey("mqtt_hass_individualpanels"))) {
if (!(root.containsKey("mqtt_enabled")
&& root.containsKey("mqtt_hostname")
&& root.containsKey("mqtt_port")
&& root.containsKey("mqtt_username")
&& root.containsKey("mqtt_password")
&& root.containsKey("mqtt_topic")
&& root.containsKey("mqtt_retain")
&& root.containsKey("mqtt_tls")
&& root.containsKey("mqtt_lwt_topic")
&& root.containsKey("mqtt_lwt_online")
&& root.containsKey("mqtt_lwt_offline")
&& root.containsKey("mqtt_publish_interval")
&& root.containsKey("mqtt_hass_enabled")
&& root.containsKey("mqtt_hass_expire")
&& root.containsKey("mqtt_hass_retain")
&& root.containsKey("mqtt_hass_topic")
&& root.containsKey("mqtt_hass_individualpanels"))) {
retMsg[F("message")] = F("Values are missing!");
response->setLength();
request->send(response);
@ -233,6 +251,7 @@ void WebApiMqttClass::onMqttAdminPost(AsyncWebServerRequest* request)
strcpy(config.Mqtt_LwtValue_Offline, root[F("mqtt_lwt_offline")].as<String>().c_str());
config.Mqtt_PublishInterval = root[F("mqtt_publish_interval")].as<uint32_t>();
config.Mqtt_Hass_Enabled = root[F("mqtt_hass_enabled")].as<bool>();
config.Mqtt_Hass_Expire = root[F("mqtt_hass_expire")].as<bool>();
config.Mqtt_Hass_Retain = root[F("mqtt_hass_retain")].as<bool>();
config.Mqtt_Hass_IndividualPanels = root[F("mqtt_hass_individualpanels")].as<bool>();
strcpy(config.Mqtt_Hass_Topic, root[F("mqtt_hass_topic")].as<String>().c_str());

View File

@ -195,6 +195,16 @@
</div>
</div>
<div class="row mb-3">
<label class="col-sm-2 form-check-label" for="inputHassExpire">Enable Expiration</label>
<div class="col-sm-10">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="inputHassExpire"
v-model="mqttConfigList.mqtt_hass_expire" />
</div>
</div>
</div>
<div class="row mb-3">
<label class="col-sm-2 form-check-label" for="inputIndividualPanels">Individual
Panels:</label>
@ -241,6 +251,7 @@ export default defineComponent({
mqtt_lwt_online: "",
mqtt_lwt_offline: "",
mqtt_hass_enabled: false,
mqtt_hass_expire: false,
mqtt_hass_retain: false,
mqtt_hass_topic: "",
mqtt_hass_individualpanels: false

View File

@ -107,6 +107,16 @@
<span v-else>disabled</span>
</td>
</tr>
<tr>
<th>Expire</th>
<td class="badge" :class="{
'bg-danger': !mqttDataList.mqtt_hass_expire,
'bg-success': mqttDataList.mqtt_hass_expire,
}">
<span v-if="mqttDataList.mqtt_hass_expire">enabled</span>
<span v-else>disabled</span>
</td>
</tr>
<tr>
<th>Individual Panels</th>
<td class="badge" :class="{

Binary file not shown.