refactor: simplify task configuration and registration

This commit is contained in:
Yurii committed 2026-11-29 11:27:13 +03:00
1 parent d19f6aaa52
commit 4004927ecd
9 files changed
+38 -55

No files matched your search

+13 -11
View File
@@ -963,16 +963,18 @@ void initSensors() {
pollDhtSensorsTask.setInterval(1000)
.setEnabledWhen([] {
return canRunSensors() &&
(Sensors::getAmountByType(Sensors::Type::DHT11, true) ||
Sensors::getAmountByType(Sensors::Type::DHT22, true));
return canRunSensors() && (
Sensors::getAmountByType(Sensors::Type::DHT11, true) ||
Sensors::getAmountByType(Sensors::Type::DHT22, true)
);
});
sensorsTaskManager.addTask(pollDhtSensorsTask);
maintainDallasSensorsTask.setEnabledWhen([] {
return canRunSensors() &&
(!dallasInstances.empty() ||
Sensors::getAmountByType(Sensors::Type::DALLAS_TEMP, true));
return canRunSensors() && (
!dallasInstances.empty() ||
Sensors::getAmountByType(Sensors::Type::DALLAS_TEMP, true)
);
})
.resume(15000);
sensorsTaskManager.addTask(maintainDallasSensorsTask);
@@ -985,9 +987,10 @@ void initSensors() {
#if USE_BLE
scanBleSensorsTask.setEnabledWhen([] {
return canRunSensors() &&
(NimBLEDevice::isInitialized() ||
Sensors::getAmountByType(Sensors::Type::BLUETOOTH, true));
return canRunSensors() && (
NimBLEDevice::isInitialized() ||
Sensors::getAmountByType(Sensors::Type::BLUETOOTH, true)
);
})
.onDone([](const Task&, uint32_t) {
if (scanBleSensorsTask.interval() != 1000) {
@@ -998,8 +1001,7 @@ void initSensors() {
sensorsTaskManager.addTask(scanBleSensorsTask);
#endif
updateSensorsTask.setInterval(1000)
.setEnabledWhen(canRunSensors);
updateSensorsTask.setInterval(1000).setEnabledWhen(canRunSensors);
sensorsTaskManager.addTask(updateSensorsTask);