Made sending triggers array optional when changing settings

This commit is contained in:
Mark van Renswoude 2018-01-24 21:03:23 +01:00
parent a2f7021d2c
commit 4c57f17c8c
3 changed files with 41 additions and 31 deletions

4
API.md
View File

@ -207,6 +207,8 @@ enabled: whether or not this trigger is enabled
Changes the time trigger settings. Request body format is the same as is returned in the GET request. Changes the time trigger settings. Request body format is the same as is returned in the GET request.
If the "triggers" array is omitted entirely, the items will not be cleared or overwritten.
## GET /api/triggers/motion ## GET /api/triggers/motion
@ -257,6 +259,8 @@ enabled: whether or not this trigger is enabled
Changes the motion trigger settings. Request body format is the same as is returned in the GET request. Changes the motion trigger settings. Request body format is the same as is returned in the GET request.
If the "triggers" array is omitted entirely, the items will not be cleared or overwritten.
## POST /api/firmware ## POST /api/firmware
Uploads new firmware. The bin file should be posted as a multipart/form-data file attachment. Name is not relevant. Uploads new firmware. The bin file should be posted as a multipart/form-data file attachment. Name is not relevant.

View File

@ -55,6 +55,8 @@ bool MotionTriggerSettings::fromJson(char* data, bool* changed)
transitionTime(root["transitionTime"]); transitionTime(root["transitionTime"]);
delay(root["delay"]); delay(root["delay"]);
if (root.containsKey("triggers"))
{
JsonArray& jsonTriggers = root["triggers"]; JsonArray& jsonTriggers = root["triggers"];
if (mTriggers != nullptr) if (mTriggers != nullptr)
delete [] mTriggers; delete [] mTriggers;
@ -73,6 +75,7 @@ bool MotionTriggerSettings::fromJson(char* data, bool* changed)
trigger->direction = (MotionDirection)(uint8_t)jsonTrigger["direction"]; trigger->direction = (MotionDirection)(uint8_t)jsonTrigger["direction"];
trigger->enabled = jsonTrigger["enabled"]; trigger->enabled = jsonTrigger["enabled"];
} }
}
if (changed != nullptr) if (changed != nullptr)
*changed = true; *changed = true;

View File

@ -89,6 +89,8 @@ bool TimeTriggerSettings::fromJson(char* data, bool* changed)
enabled(root["enabled"]); enabled(root["enabled"]);
transitionTime(root["transitionTime"]); transitionTime(root["transitionTime"]);
if (root.containsKey("triggers"))
{
JsonArray& jsonTriggers = root["triggers"]; JsonArray& jsonTriggers = root["triggers"];
if (mTriggers != nullptr) if (mTriggers != nullptr)
delete [] mTriggers; delete [] mTriggers;
@ -108,6 +110,7 @@ bool TimeTriggerSettings::fromJson(char* data, bool* changed)
trigger->triggerType = (TimeTriggerType)(uint8_t)jsonTrigger["triggerType"]; trigger->triggerType = (TimeTriggerType)(uint8_t)jsonTrigger["triggerType"];
trigger->enabled = jsonTrigger["enabled"]; trigger->enabled = jsonTrigger["enabled"];
} }
}
if (changed != nullptr) if (changed != nullptr)
*changed = true; *changed = true;