mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-14 15:54:47 +00:00
Various changes after testing new HA features
This commit is contained in:
parent
f214af3595
commit
71e0f13f0e
@ -154,7 +154,7 @@ struct DomoticzConfig {
|
||||
|
||||
struct HomeAssistantConfig {
|
||||
uint8_t tag; // Just to find out if we have this config already. Can be removed in v2.3
|
||||
char discoveryTopic[64];
|
||||
char discoveryPrefix[64];
|
||||
char discoveryHostname[64];
|
||||
char discoveryNameTag[16];
|
||||
}; // 145
|
||||
|
||||
@ -348,14 +348,14 @@ bool AmsConfiguration::getHomeAssistantConfig(HomeAssistantConfig& config) {
|
||||
bool AmsConfiguration::setHomeAssistantConfig(HomeAssistantConfig& config) {
|
||||
HomeAssistantConfig existing;
|
||||
if(getHomeAssistantConfig(existing)) {
|
||||
mqttChanged |= strcmp(config.discoveryTopic, existing.discoveryTopic) != 0;
|
||||
mqttChanged |= strcmp(config.discoveryPrefix, existing.discoveryPrefix) != 0;
|
||||
mqttChanged |= strcmp(config.discoveryHostname, existing.discoveryHostname) != 0;
|
||||
mqttChanged |= strcmp(config.discoveryNameTag, existing.discoveryNameTag) != 0;
|
||||
} else {
|
||||
mqttChanged = true;
|
||||
}
|
||||
|
||||
stripNonAscii((uint8_t*) config.discoveryTopic, 64);
|
||||
stripNonAscii((uint8_t*) config.discoveryPrefix, 64);
|
||||
stripNonAscii((uint8_t*) config.discoveryHostname, 64);
|
||||
stripNonAscii((uint8_t*) config.discoveryNameTag, 16);
|
||||
|
||||
@ -368,7 +368,7 @@ bool AmsConfiguration::setHomeAssistantConfig(HomeAssistantConfig& config) {
|
||||
|
||||
void AmsConfiguration::clearHomeAssistantConfig(HomeAssistantConfig& config) {
|
||||
config.tag = 0xA7;
|
||||
strcpy(config.discoveryTopic, "");
|
||||
strcpy(config.discoveryPrefix, "");
|
||||
strcpy(config.discoveryHostname, "");
|
||||
strcpy(config.discoveryNameTag, "");
|
||||
}
|
||||
|
||||
@ -35,16 +35,20 @@ public:
|
||||
deviceUid = hostname; // Maybe configurable in the future?
|
||||
|
||||
if(strlen(config.discoveryHostname) > 0) {
|
||||
snprintf_P(buf, 128, PSTR("http://%s.local/"), config.discoveryHostname);
|
||||
String deviceUrl = String(buf);
|
||||
if(strncmp_P(config.discoveryHostname, PSTR("http"), 4) == 0) {
|
||||
deviceUrl = String(config.discoveryHostname);
|
||||
} else {
|
||||
snprintf_P(buf, 128, PSTR("http://%s/"), config.discoveryHostname);
|
||||
deviceUrl = String(buf);
|
||||
}
|
||||
} else {
|
||||
snprintf_P(buf, 128, PSTR("http://%s.local/"), hostname);
|
||||
String deviceUrl = String(buf);
|
||||
deviceUrl = String(buf);
|
||||
}
|
||||
|
||||
if(strlen(config.discoveryTopic) > 0) {
|
||||
discoveryTopic = String(config.discoveryTopic);
|
||||
if(!discoveryTopic.endsWith("/")) discoveryTopic += "/";
|
||||
if(strlen(config.discoveryPrefix) > 0) {
|
||||
snprintf_P(buf, 128, PSTR("%s/sensor/"), config.discoveryPrefix);
|
||||
discoveryTopic = String(buf);
|
||||
} else {
|
||||
discoveryTopic = "homeassistant/sensor/";
|
||||
}
|
||||
|
||||
@ -323,7 +323,7 @@ void HomeAssistantMqttHandler::publishSensor(const HomeAssistantSensor& sensor)
|
||||
deviceModel.c_str(),
|
||||
VERSION,
|
||||
manufacturer.c_str(),
|
||||
sensorNamePostFix.c_str(),
|
||||
deviceUrl.c_str(),
|
||||
strlen_P(sensor.stacl) > 0 ? ", \"stat_cla\" :" : "",
|
||||
strlen_P(sensor.stacl) > 0 ? (char *) FPSTR(sensor.stacl) : ""
|
||||
);
|
||||
|
||||
18
lib/SvelteUi/app/dist/index.js
vendored
18
lib/SvelteUi/app/dist/index.js
vendored
File diff suppressed because one or more lines are too long
@ -540,8 +540,8 @@
|
||||
<a href="{wiki('MQTT-configuration#home-assistant')}" target="_blank" class="float-right"><HelpIcon/></a>
|
||||
<input type="hidden" name="h" value="true"/>
|
||||
<div class="my-1">
|
||||
Discovery topic<br/>
|
||||
<input name="ht" bind:value={configuration.h.t} type="text" class="in-s" placeholder="homeassistant/sensor"/>
|
||||
Discovery topic prefix<br/>
|
||||
<input name="ht" bind:value={configuration.h.t} type="text" class="in-s" placeholder="homeassistant"/>
|
||||
</div>
|
||||
<div class="my-1">
|
||||
Hostname for URL<br/>
|
||||
|
||||
@ -28,9 +28,6 @@
|
||||
},{
|
||||
name: 'GPIO',
|
||||
key: 'ig'
|
||||
},{
|
||||
name: 'Domoticz',
|
||||
key: 'id'
|
||||
},{
|
||||
name: 'NTP',
|
||||
key: 'in'
|
||||
|
||||
@ -953,7 +953,7 @@ void AmsWebServer::configurationJson() {
|
||||
);
|
||||
server.sendContent(buf);
|
||||
snprintf_P(buf, BufferSize, CONF_HA_JSON,
|
||||
haconf.discoveryTopic,
|
||||
haconf.discoveryPrefix,
|
||||
haconf.discoveryHostname,
|
||||
haconf.discoveryNameTag
|
||||
);
|
||||
@ -1291,7 +1291,7 @@ void AmsWebServer::handleSave() {
|
||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf(PSTR("Received Home-Assistant config"));
|
||||
HomeAssistantConfig haconf;
|
||||
config->getHomeAssistantConfig(haconf);
|
||||
strcpy(haconf.discoveryTopic, server.arg(F("ht")).c_str());
|
||||
strcpy(haconf.discoveryPrefix, server.arg(F("ht")).c_str());
|
||||
strcpy(haconf.discoveryHostname, server.arg(F("hh")).c_str());
|
||||
strcpy(haconf.discoveryNameTag, server.arg(F("hn")).c_str());
|
||||
config->setHomeAssistantConfig(haconf);
|
||||
@ -1888,7 +1888,6 @@ void AmsWebServer::configFileDownload() {
|
||||
bool includeWeb = server.hasArg(F("ie")) && server.arg(F("ie")) == F("true");
|
||||
bool includeMeter = server.hasArg(F("it")) && server.arg(F("it")) == F("true");
|
||||
bool includeGpio = server.hasArg(F("ig")) && server.arg(F("ig")) == F("true");
|
||||
bool includeDomo = server.hasArg(F("id")) && server.arg(F("id")) == F("true");
|
||||
bool includeNtp = server.hasArg(F("in")) && server.arg(F("in")) == F("true");
|
||||
bool includeEntsoe = server.hasArg(F("is")) && server.arg(F("is")) == F("true");
|
||||
bool includeThresholds = server.hasArg(F("ih")) && server.arg(F("ih")) == F("true");
|
||||
@ -1934,6 +1933,22 @@ void AmsWebServer::configFileDownload() {
|
||||
if(includeSecrets) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("mqttPassword %s\n"), mqtt.password));
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("mqttPayloadFormat %d\n"), mqtt.payloadFormat));
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("mqttSsl %d\n"), mqtt.ssl ? 1 : 0));
|
||||
|
||||
if(mqtt.payloadFormat == 3) {
|
||||
DomoticzConfig domo;
|
||||
config->getDomoticzConfig(domo);
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzElidx %d\n"), domo.elidx));
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzVl1idx %d\n"), domo.vl1idx));
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzVl2idx %d\n"), domo.vl2idx));
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzVl3idx %d\n"), domo.vl3idx));
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzCl1idx %d\n"), domo.cl1idx));
|
||||
} else if(mqtt.payloadFormat == 4) {
|
||||
HomeAssistantConfig haconf;
|
||||
config->getHomeAssistantConfig(haconf);
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("homeAssistantDiscoveryPrefix %s\n"), haconf.discoveryPrefix));
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("homeAssistantDiscoveryHostname %s\n"), haconf.discoveryHostname));
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("homeAssistantDiscoveryNameTag %s\n"), haconf.discoveryNameTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1998,16 +2013,6 @@ void AmsWebServer::configFileDownload() {
|
||||
if(gpio.vccPin != 0xFF && gpio.vccResistorVcc != 0) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioVccResistorVcc %d\n"), gpio.vccResistorVcc));
|
||||
}
|
||||
|
||||
if(includeDomo) {
|
||||
DomoticzConfig domo;
|
||||
config->getDomoticzConfig(domo);
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzElidx %d\n"), domo.elidx));
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzVl1idx %d\n"), domo.vl1idx));
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzVl2idx %d\n"), domo.vl2idx));
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzVl3idx %d\n"), domo.vl3idx));
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzCl1idx %d\n"), domo.cl1idx));
|
||||
}
|
||||
|
||||
if(includeNtp) {
|
||||
NtpConfig ntp;
|
||||
config->getNtpConfig(ntp);
|
||||
|
||||
@ -1497,6 +1497,7 @@ void configFileParse() {
|
||||
bool lMeter = false;
|
||||
bool lGpio = false;
|
||||
bool lDomo = false;
|
||||
bool lHa = false;
|
||||
bool lNtp = false;
|
||||
bool lEntsoe = false;
|
||||
bool lEac = false;
|
||||
@ -1510,6 +1511,7 @@ void configFileParse() {
|
||||
MeterConfig meter;
|
||||
GpioConfig gpio;
|
||||
DomoticzConfig domo;
|
||||
HomeAssistantConfig haconf;
|
||||
NtpConfig ntp;
|
||||
EntsoeConfig entsoe;
|
||||
EnergyAccountingConfig eac;
|
||||
@ -1679,6 +1681,15 @@ void configFileParse() {
|
||||
} else if(strncmp_P(buf, PSTR("domoticzCl1idx "), 15) == 0) {
|
||||
if(!lDomo) { config.getDomoticzConfig(domo); lDomo = true; };
|
||||
domo.cl1idx = String(buf+15).toInt();
|
||||
} else if(strncmp_P(buf, PSTR("homeAssistantDiscoveryPrefix "), 28) == 0) {
|
||||
if(!lHa) { config.getHomeAssistantConfig(haconf); lHa = true; };
|
||||
strcpy(haconf.discoveryPrefix, buf+28);
|
||||
} else if(strncmp_P(buf, PSTR("homeAssistantDiscoveryHostname "), 30) == 0) {
|
||||
if(!lHa) { config.getHomeAssistantConfig(haconf); lHa = true; };
|
||||
strcpy(haconf.discoveryHostname, buf+30);
|
||||
} else if(strncmp_P(buf, PSTR("homeAssistantDiscoveryNameTag "), 29) == 0) {
|
||||
if(!lHa) { config.getHomeAssistantConfig(haconf); lHa = true; };
|
||||
strcpy(haconf.discoveryNameTag, buf+29);
|
||||
} else if(strncmp_P(buf, PSTR("ntpEnable "), 10) == 0) {
|
||||
if(!lNtp) { config.getNtpConfig(ntp); lNtp = true; };
|
||||
ntp.enable = String(buf+10).toInt() == 1;
|
||||
@ -1902,6 +1913,7 @@ void configFileParse() {
|
||||
if(lMeter) config.setMeterConfig(meter);
|
||||
if(lGpio) config.setGpioConfig(gpio);
|
||||
if(lDomo) config.setDomoticzConfig(domo);
|
||||
if(lHa) config.setHomeAssistantConfig(haconf);
|
||||
if(lNtp) config.setNtpConfig(ntp);
|
||||
if(lEntsoe) config.setEntsoeConfig(entsoe);
|
||||
if(lEac) config.setEnergyAccountingConfig(eac);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user