Skip MQTT allocation when disabled (#10411)

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
Clive Blackledge
2026-05-07 11:51:55 -05:00
committed by GitHub
co-authored by GitHub Ben Meadors
parent 784e3748e2
commit 4553d1e0b1
2 changed files with 15 additions and 0 deletions
+3
View File
@@ -409,6 +409,9 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length)
void mqttInit()
{
if (!moduleConfig.mqtt.enabled)
return;
new MQTT();
}
+12
View File
@@ -800,6 +800,17 @@ void test_disabled(void)
TEST_ASSERT_FALSE(mqtt->isEnabled());
}
void test_mqttInitSkipsAllocationWhenDisabled(void)
{
delete unitTest;
mqtt = unitTest = NULL;
moduleConfig.mqtt.enabled = false;
mqttInit();
TEST_ASSERT_NULL(mqtt);
}
// Subscriptions contain the moduleConfig.mqtt.root prefix.
void test_customMqttRoot(void)
{
@@ -912,6 +923,7 @@ void setup()
RUN_TEST(test_usingCustomServer);
RUN_TEST(test_enabled);
RUN_TEST(test_disabled);
RUN_TEST(test_mqttInitSkipsAllocationWhenDisabled);
RUN_TEST(test_customMqttRoot);
RUN_TEST(test_configEmptyIsValid);
RUN_TEST(test_configEnabledEmptyIsValid);