Skip to content

Commit 9448ba8

Browse files
BrentIOclaude
andcommitted
refactor: collapse _otaNonForcedPendingRequest into _otaPendingRequest
Both forced and HA-triggered updates now share _otaPendingRequest. otaFirmware_checkPending() dispatches on _otaPendingDoc.size() == 0 to distinguish the two paths rather than needing a second flag. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8edf4c9 commit 9448ba8

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

Controller/Controller.ino

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ WiFiClientSecure _otaHttpsClient; /* TLS client used when the manifest URL
112112
String _otaManifestUrl; /* Set when setup_OtaFirmware() succeeds; empty otherwise */
113113
bool _otaUpdateInProcess = false;
114114
bool _otaPendingRequest = false;
115-
bool _otaNonForcedPendingRequest = false;
116115
bool _otaCheckFailed = false; /* Set by onError during checkForUpdate(); reset before each check */
117116
int _otaCheckErrorCode = 0; /* Error code captured by onError during checkForUpdate() */
118117
JsonDocument _otaPendingDoc;
@@ -977,14 +976,6 @@ void loop() {
977976

978977
otaFirmware_checkPending();
979978

980-
if(_otaNonForcedPendingRequest && !_otaUpdateInProcess){
981-
_otaNonForcedPendingRequest = false;
982-
_otaUpdateInProcess = true;
983-
_otaCurrentPartition[0] = '\0';
984-
otaFirmware.execOTA();
985-
_otaUpdateInProcess = false;
986-
}
987-
988979
oled.loop();
989980
authToken.loop();
990981
frontPanel.loop();
@@ -3704,8 +3695,9 @@ void setup_OtaFirmware(){
37043695

37053696

37063697
/**
3707-
* Executes a pending forced OTA update using execOTA(JsonDocument&), matching
3708-
* the HW-Reg implementation exactly. onComplete handles the reboot on success.
3698+
* Executes a pending OTA update. If _otaPendingDoc is empty the update was
3699+
* triggered from HA via MQTT (non-forced); otherwise it is a forced update
3700+
* with a specific document from the HTTP API.
37093701
*/
37103702
void otaFirmware_checkPending(){
37113703

@@ -3714,6 +3706,14 @@ void otaFirmware_checkPending(){
37143706
}
37153707

37163708
_otaUpdateInProcess = true;
3709+
_otaCurrentPartition[0] = '\0';
3710+
3711+
if(_otaPendingDoc.size() == 0){
3712+
_otaPendingRequest = false;
3713+
otaFirmware.execOTA();
3714+
_otaUpdateInProcess = false;
3715+
return;
3716+
}
37173717

37183718
otaFirmware.setApplicationName(_otaPendingDoc["application_name"]);
37193719

@@ -3729,8 +3729,6 @@ void otaFirmware_checkPending(){
37293729
}
37303730
}
37313731

3732-
_otaCurrentPartition[0] = '\0';
3733-
37343732
otaFirmware.onProgress([](const char* partition, size_t written, size_t total){
37353733
_otaUpdateInProcess = true;
37363734
if(strcmp(partition, _otaCurrentPartition) != 0){
@@ -4384,7 +4382,7 @@ void eventHandler_mqttMessageReceived(char* topic, byte* pl, unsigned int length
43844382
mqttClient.publish(topic, buffer);
43854383

43864384
if(!_otaManifestUrl.isEmpty()){
4387-
_otaNonForcedPendingRequest = true;
4385+
_otaPendingRequest = true;
43884386
}
43894387
return;
43904388
}

0 commit comments

Comments
 (0)