Use references & flash strings where approperate (#110)

* pass originId as const reference
* store strings for serial logging in flash
* Use string references where approperate.
This commit is contained in:
rjwats
2020-05-21 08:42:21 +01:00
committed by GitHub
parent 4e6823ceec
commit 0e2124062f
16 changed files with 85 additions and 90 deletions

View File

@ -28,10 +28,10 @@ LightStateService::LightStateService(AsyncWebServer* server,
_mqttClient->onConnect(std::bind(&LightStateService::registerConfig, this));
// configure update handler for when the light settings change
_lightMqttSettingsService->addUpdateHandler([&](String originId) { registerConfig(); }, false);
_lightMqttSettingsService->addUpdateHandler([&](const String& originId) { registerConfig(); }, false);
// configure settings service update handler to update LED state
addUpdateHandler([&](String originId) { onConfigUpdated(); }, false);
addUpdateHandler([&](const String& originId) { onConfigUpdated(); }, false);
}
void LightStateService::begin() {
@ -48,14 +48,14 @@ void LightStateService::registerConfig() {
return;
}
String configTopic;
String setTopic;
String stateTopic;
String subTopic;
String pubTopic;
DynamicJsonDocument doc(256);
_lightMqttSettingsService->read([&](LightMqttSettings& settings) {
configTopic = settings.mqttPath + "/config";
setTopic = settings.mqttPath + "/set";
stateTopic = settings.mqttPath + "/state";
subTopic = settings.mqttPath + "/set";
pubTopic = settings.mqttPath + "/state";
doc["~"] = settings.mqttPath;
doc["name"] = settings.name;
doc["unique_id"] = settings.uniqueId;
@ -69,5 +69,5 @@ void LightStateService::registerConfig() {
serializeJson(doc, payload);
_mqttClient->publish(configTopic.c_str(), 0, false, payload.c_str());
_mqttPubSub.configureTopics(stateTopic, setTopic);
_mqttPubSub.configureTopics(pubTopic, subTopic);
}