mirror of
https://github.com/lumapu/ahoy.git
synced 2025-04-29 10:16:21 +02:00
0.5.108
* fix: no MQTT `total` sensor for autodiscover if only one inverter was found #805 * fix: MQTT `total` renamed to `device_name` + `_TOTOL` for better visibility #805
This commit is contained in:
parent
e567d13eb4
commit
115f3978cd
2 changed files with 24 additions and 9 deletions
|
@ -3,7 +3,10 @@
|
|||
(starting from release version `0.5.66`)
|
||||
|
||||
## 0.5.108
|
||||
* merge: PR SPI pins configureable (ESP32) #807
|
||||
* merge: PR SPI pins configureable (ESP32) #807, #806
|
||||
* merge: PR MI serial outputs #809
|
||||
* fix: no MQTT `total` sensor for autodiscover if only one inverter was found #805
|
||||
* fix: MQTT `total` renamed to `device_name` + `_TOTOL` for better visibility #805
|
||||
|
||||
## 0.5.107
|
||||
* fix: show save message
|
||||
|
|
|
@ -38,6 +38,7 @@ typedef struct {
|
|||
bool running;
|
||||
uint8_t lastIvId;
|
||||
uint8_t sub;
|
||||
uint8_t foundIvCnt;
|
||||
} discovery_t;
|
||||
|
||||
template<class HMSYSTEM>
|
||||
|
@ -224,6 +225,7 @@ class PubMqtt {
|
|||
mDiscovery.running = true;
|
||||
mDiscovery.lastIvId = 0;
|
||||
mDiscovery.sub = 0;
|
||||
mDiscovery.foundIvCnt = 0;
|
||||
}
|
||||
|
||||
void setPowerLimitAck(Inverter<> *iv) {
|
||||
|
@ -350,14 +352,16 @@ class PubMqtt {
|
|||
uint8_t fldTotal[4] = {FLD_PAC, FLD_YT, FLD_YD, FLD_PDC};
|
||||
const char* unitTotal[4] = {"W", "kWh", "Wh", "W"};
|
||||
|
||||
String node_mac = WiFi.macAddress().substring(12,14)+ WiFi.macAddress().substring(15,17);
|
||||
String node_id = "AHOY_DTU_" + node_mac;
|
||||
String node_id = String(mDevName) + "_TOTAL";
|
||||
bool total = (mDiscovery.lastIvId == MAX_NUM_INVERTERS);
|
||||
|
||||
Inverter<> *iv = mSys->getInverterByPos(mDiscovery.lastIvId);
|
||||
record_t<> *rec;
|
||||
if (NULL != iv)
|
||||
if (NULL != iv) {
|
||||
rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
||||
if(0 == mDiscovery.sub)
|
||||
mDiscovery.foundIvCnt++;
|
||||
}
|
||||
|
||||
if ((NULL != iv) || total) {
|
||||
if (!total) {
|
||||
|
@ -420,18 +424,26 @@ class PubMqtt {
|
|||
|
||||
if(++mDiscovery.sub == ((!total) ? (rec->length) : 4)) {
|
||||
mDiscovery.sub = 0;
|
||||
if(++mDiscovery.lastIvId == (MAX_NUM_INVERTERS + 1))
|
||||
mDiscovery.running = false;
|
||||
checkDiscoveryEnd();
|
||||
}
|
||||
} else {
|
||||
mDiscovery.sub = 0;
|
||||
if(++mDiscovery.lastIvId == (MAX_NUM_INVERTERS + 1))
|
||||
mDiscovery.running = false;
|
||||
checkDiscoveryEnd();
|
||||
}
|
||||
|
||||
yield();
|
||||
}
|
||||
|
||||
void checkDiscoveryEnd(void) {
|
||||
if(++mDiscovery.lastIvId == MAX_NUM_INVERTERS) {
|
||||
// check if only one inverter was found, then don't create 'total' sensor
|
||||
DPRINTLN(DBG_INFO, "found: " + String(mDiscovery.foundIvCnt));
|
||||
if(mDiscovery.foundIvCnt == 1)
|
||||
mDiscovery.running = false;
|
||||
} else if(mDiscovery.lastIvId == (MAX_NUM_INVERTERS + 1))
|
||||
mDiscovery.running = false;
|
||||
}
|
||||
|
||||
const char *getFieldDeviceClass(uint8_t fieldId) {
|
||||
uint8_t pos = 0;
|
||||
for (; pos < DEVICE_CLS_ASSIGN_LIST_LEN; pos++) {
|
||||
|
|
Loading…
Add table
Reference in a new issue