Skip to content

Commit 2b04a9b

Browse files
ewowitheelims
andauthored
Add originID to StateUpdateResult update (#110)
* Add originID to StateUpdateResult update (and add .DS_Store to gitignore) This makes it consistent with other update functions and allow for checking on this in update() * fix: string to variable --------- Co-authored-by: elims <elims@gmx.net>
1 parent abe5b0f commit 2b04a9b

10 files changed

+16
-16
lines changed

lib/framework/APSettingsService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class APSettings
111111
root["subnet_mask"] = settings.subnetMask.toString();
112112
}
113113

114-
static StateUpdateResult update(JsonObject &root, APSettings &settings)
114+
static StateUpdateResult update(JsonObject &root, APSettings &settings, const String &originId)
115115
{
116116
APSettings newSettings = {};
117117
newSettings.provisionMode = root["provision_mode"] | FACTORY_AP_PROVISION_MODE;

lib/framework/FSPersistence.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class FSPersistence
4747
if (error == DeserializationError::Ok && jsonDocument.is<JsonObject>())
4848
{
4949
JsonObject jsonObject = jsonDocument.as<JsonObject>();
50-
_statefulService->updateWithoutPropagation(jsonObject, _stateUpdater);
50+
_statefulService->updateWithoutPropagation(jsonObject, _stateUpdater, _filePath);
5151
settingsFile.close();
5252
return;
5353
}
@@ -135,7 +135,7 @@ class FSPersistence
135135
{
136136
JsonDocument jsonDocument;
137137
JsonObject jsonObject = jsonDocument.as<JsonObject>();
138-
_statefulService->updateWithoutPropagation(jsonObject, _stateUpdater);
138+
_statefulService->updateWithoutPropagation(jsonObject, _stateUpdater, _filePath);
139139
}
140140
};
141141

lib/framework/HttpEndpoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class HttpEndpoint
8484
}
8585

8686
JsonObject jsonObject = json.as<JsonObject>();
87-
StateUpdateResult outcome = _statefulService->updateWithoutPropagation(jsonObject, _stateUpdater);
87+
StateUpdateResult outcome = _statefulService->updateWithoutPropagation(jsonObject, _stateUpdater, _servicePath);
8888

8989
if (outcome == StateUpdateResult::ERROR)
9090
{

lib/framework/MqttSettingsService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class MqttSettings
106106
root["message_interval_ms"] = settings.messageIntervalMs;
107107
}
108108

109-
static StateUpdateResult update(JsonObject &root, MqttSettings &settings)
109+
static StateUpdateResult update(JsonObject &root, MqttSettings &settings, const String &originId)
110110
{
111111
settings.enabled = root["enabled"] | FACTORY_MQTT_ENABLED;
112112
settings.uri = root["uri"] | FACTORY_MQTT_URI;

lib/framework/NTPSettingsService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class NTPSettings
6363
root["tz_format"] = settings.tzFormat;
6464
}
6565

66-
static StateUpdateResult update(JsonObject &root, NTPSettings &settings)
66+
static StateUpdateResult update(JsonObject &root, NTPSettings &settings, const String &originId)
6767
{
6868
settings.enabled = root["enabled"] | FACTORY_NTP_ENABLED;
6969
settings.server = root["server"] | FACTORY_NTP_SERVER;

lib/framework/SecuritySettingsService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class SecuritySettings
7070
}
7171
}
7272

73-
static StateUpdateResult update(JsonObject &root, SecuritySettings &settings)
73+
static StateUpdateResult update(JsonObject &root, SecuritySettings &settings, const String& originID)
7474
{
7575
// secret
7676
settings.jwtSecret = root["jwt_secret"] | SettingValue::format(FACTORY_JWT_SECRET);

lib/framework/StatefulService.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ enum class StateUpdateResult
3131
};
3232

3333
template <typename T>
34-
using JsonStateUpdater = std::function<StateUpdateResult(JsonObject &root, T &settings)>;
34+
using JsonStateUpdater = std::function<StateUpdateResult(JsonObject &root, T &settings, const String &originId)>;
3535

3636
template <typename T>
3737
using JsonStateReader = std::function<void(T &settings, JsonObject &root)>;
@@ -133,7 +133,7 @@ class StatefulService
133133
return result;
134134
}
135135

136-
StateUpdateResult updateWithoutPropagation(std::function<StateUpdateResult(T &)> stateUpdater)
136+
StateUpdateResult updateWithoutPropagation(std::function<StateUpdateResult(T &)> stateUpdater, const String &originId)
137137
{
138138
beginTransaction();
139139
StateUpdateResult result = stateUpdater(_state);
@@ -144,7 +144,7 @@ class StatefulService
144144
StateUpdateResult update(JsonObject &jsonObject, JsonStateUpdater<T> stateUpdater, const String &originId)
145145
{
146146
beginTransaction();
147-
StateUpdateResult result = stateUpdater(jsonObject, _state);
147+
StateUpdateResult result = stateUpdater(jsonObject, _state, originId);
148148
endTransaction();
149149
callHookHandlers(originId, result);
150150
if (result == StateUpdateResult::CHANGED)
@@ -154,10 +154,10 @@ class StatefulService
154154
return result;
155155
}
156156

157-
StateUpdateResult updateWithoutPropagation(JsonObject &jsonObject, JsonStateUpdater<T> stateUpdater)
157+
StateUpdateResult updateWithoutPropagation(JsonObject &jsonObject, JsonStateUpdater<T> stateUpdater, const String &originId)
158158
{
159159
beginTransaction();
160-
StateUpdateResult result = stateUpdater(jsonObject, _state);
160+
StateUpdateResult result = stateUpdater(jsonObject, _state, originId);
161161
endTransaction();
162162
return result;
163163
}

lib/framework/WiFiSettingsService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class WiFiSettings
114114
ESP_LOGV(SVK_TAG, "WiFi Settings read");
115115
}
116116

117-
static StateUpdateResult update(JsonObject &root, WiFiSettings &settings)
117+
static StateUpdateResult update(JsonObject &root, WiFiSettings &settings, const String &originId)
118118
{
119119
settings.hostname = root["hostname"] | SettingValue::format(FACTORY_WIFI_HOSTNAME);
120120
settings.staConnectionMode = root["connection_mode"] | 1;

src/LightMqttSettingsService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class LightMqttSettings
4646
root["status_topic"] = settings.stateTopic;
4747
}
4848

49-
static StateUpdateResult update(JsonObject &root, LightMqttSettings &settings)
49+
static StateUpdateResult update(JsonObject &root, LightMqttSettings &settings, const String& originID)
5050
{
5151
settings.mqttPath = root["mqtt_path"] | SettingValue::format("homeassistant/light/#{unique_id}");
5252
settings.name = root["name"] | SettingValue::format("light-#{unique_id}");

src/LightStateService.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class LightState
4242
root["led_on"] = settings.ledOn;
4343
}
4444

45-
static StateUpdateResult update(JsonObject &root, LightState &lightState)
45+
static StateUpdateResult update(JsonObject &root, LightState &lightState, const String& originID)
4646
{
4747
boolean newState = root["led_on"] | DEFAULT_LED_STATE;
4848
if (lightState.ledOn != newState)
@@ -58,7 +58,7 @@ class LightState
5858
root["state"] = settings.ledOn ? ON_STATE : OFF_STATE;
5959
}
6060

61-
static StateUpdateResult homeAssistUpdate(JsonObject &root, LightState &lightState)
61+
static StateUpdateResult homeAssistUpdate(JsonObject &root, LightState &lightState, const String& originID)
6262
{
6363
String state = root["state"];
6464
// parse new led state

0 commit comments

Comments
 (0)