Cleanup unecessary struct

This commit is contained in:
Michael Bisbjerg 2024-05-15 21:32:08 +02:00
parent f9467ceaf1
commit 1dd9c6754c

View File

@ -12,15 +12,11 @@ private:
unsigned long _lastLoopCheck = 0; unsigned long _lastLoopCheck = 0;
struct bool _settingEnabled : 1; // Enable the usermod
{ bool _mqttPublish : 1; // Publish mqtt values
bool settingEnabled : 1; // Enable the usermod bool _mqttPublishAlways : 1; // Publish always, regardless if there is a change
bool mqttPublish : 1; // Publish mqtt values bool _mqttHomeAssistant : 1; // Enable Home Assistant docs
bool mqttPublishAlways : 1; // Publish always, regardless if there is a change bool _initDone : 1; // Initialization is done
bool mqttHomeAssistant : 1; // Enable Home Assistant docs
bool initDone : 1; // Initialization is done
unsigned : 3;
} _stateFlags;
// Settings. Some of these are stored in a different format than they're user settings - so we don't have to convert at runtime // Settings. Some of these are stored in a different format than they're user settings - so we don't have to convert at runtime
uint8_t _i2cAddress = AHT10_ADDRESS_0X38; uint8_t _i2cAddress = AHT10_ADDRESS_0X38;
@ -68,7 +64,7 @@ private:
void mqttInitialize() void mqttInitialize()
{ {
// This is a generic "setup mqtt" function, So we must abort if we're not to do mqtt // This is a generic "setup mqtt" function, So we must abort if we're not to do mqtt
if (!WLED_MQTT_CONNECTED || !_stateFlags.mqttPublish || !_stateFlags.mqttHomeAssistant) if (!WLED_MQTT_CONNECTED || !_mqttPublish || !_mqttHomeAssistant)
return; return;
char topic[128]; char topic[128];
@ -83,7 +79,7 @@ private:
{ {
// Check if MQTT Connected, otherwise it will crash the 8266 // Check if MQTT Connected, otherwise it will crash the 8266
// Only report if the change is larger than the required diff // Only report if the change is larger than the required diff
if (WLED_MQTT_CONNECTED && _stateFlags.mqttPublish && (_stateFlags.mqttPublishAlways || fabsf(lastState - state) > minChange)) if (WLED_MQTT_CONNECTED && _mqttPublish && (_mqttPublishAlways || fabsf(lastState - state) > minChange))
{ {
char subuf[128]; char subuf[128];
snprintf_P(subuf, 127, PSTR("%s/%s"), mqttDeviceTopic, (const char *)topic); snprintf_P(subuf, 127, PSTR("%s/%s"), mqttDeviceTopic, (const char *)topic);
@ -135,7 +131,7 @@ public:
{ {
// if usermod is disabled or called during strip updating just exit // if usermod is disabled or called during strip updating just exit
// NOTE: on very long strips strip.isUpdating() may always return true so update accordingly // NOTE: on very long strips strip.isUpdating() may always return true so update accordingly
if (!_stateFlags.settingEnabled || strip.isUpdating()) if (!_settingEnabled || strip.isUpdating())
return; return;
// do your magic here // do your magic here
@ -237,15 +233,15 @@ public:
void addToConfig(JsonObject &root) void addToConfig(JsonObject &root)
{ {
JsonObject top = root.createNestedObject(FPSTR(_name)); JsonObject top = root.createNestedObject(FPSTR(_name));
top[F("Enabled")] = _stateFlags.settingEnabled; top[F("Enabled")] = _settingEnabled;
top[F("I2CAddress")] = static_cast<uint8_t>(_i2cAddress); top[F("I2CAddress")] = static_cast<uint8_t>(_i2cAddress);
top[F("SensorType")] = _ahtType; top[F("SensorType")] = _ahtType;
top[F("CheckInterval")] = _checkInterval / 1000; top[F("CheckInterval")] = _checkInterval / 1000;
top[F("Decimals")] = log10f(_decimalFactor); top[F("Decimals")] = log10f(_decimalFactor);
#ifndef WLED_DISABLE_MQTT #ifndef WLED_DISABLE_MQTT
top[F("MqttPublish")] = _stateFlags.mqttPublish; top[F("MqttPublish")] = _mqttPublish;
top[F("MqttPublishAlways")] = _stateFlags.mqttPublishAlways; top[F("MqttPublishAlways")] = _mqttPublishAlways;
top[F("MqttHomeAssistantDiscovery")] = _stateFlags.mqttHomeAssistant; top[F("MqttHomeAssistantDiscovery")] = _mqttHomeAssistant;
#endif #endif
DEBUG_PRINTLN(F("AHT10 config saved.")); DEBUG_PRINTLN(F("AHT10 config saved."));
@ -265,7 +261,7 @@ public:
bool tmpBool = false; bool tmpBool = false;
configComplete &= getJsonValue(top[F("Enabled")], tmpBool); configComplete &= getJsonValue(top[F("Enabled")], tmpBool);
if (configComplete) if (configComplete)
_stateFlags.settingEnabled = tmpBool; _settingEnabled = tmpBool;
configComplete &= getJsonValue(top[F("I2CAddress")], _i2cAddress); configComplete &= getJsonValue(top[F("I2CAddress")], _i2cAddress);
configComplete &= getJsonValue(top[F("CheckInterval")], _checkInterval); configComplete &= getJsonValue(top[F("CheckInterval")], _checkInterval);
@ -302,18 +298,18 @@ public:
#ifndef WLED_DISABLE_MQTT #ifndef WLED_DISABLE_MQTT
configComplete &= getJsonValue(top[F("MqttPublish")], tmpBool); configComplete &= getJsonValue(top[F("MqttPublish")], tmpBool);
if (configComplete) if (configComplete)
_stateFlags.mqttPublish = tmpBool; _mqttPublish = tmpBool;
configComplete &= getJsonValue(top[F("MqttPublishAlways")], tmpBool); configComplete &= getJsonValue(top[F("MqttPublishAlways")], tmpBool);
if (configComplete) if (configComplete)
_stateFlags.mqttPublishAlways = tmpBool; _mqttPublishAlways = tmpBool;
configComplete &= getJsonValue(top[F("MqttHomeAssistantDiscovery")], tmpBool); configComplete &= getJsonValue(top[F("MqttHomeAssistantDiscovery")], tmpBool);
if (configComplete) if (configComplete)
_stateFlags.mqttHomeAssistant = tmpBool; _mqttHomeAssistant = tmpBool;
#endif #endif
if (_stateFlags.initDone) if (_initDone)
{ {
// Reloading config // Reloading config
initializeAht(); initializeAht();
@ -323,7 +319,7 @@ public:
#endif #endif
} }
_stateFlags.initDone = true; _initDone = true;
return configComplete; return configComplete;
} }
}; };