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.
If the "triggers" array is omitted entirely, the items will not be cleared or overwritten.
## 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.
If the "triggers" array is omitted entirely, the items will not be cleared or overwritten.
## POST /api/firmware
Uploads new firmware. The bin file should be posted as a multipart/form-data file attachment. Name is not relevant.

View File

@ -55,23 +55,26 @@ bool MotionTriggerSettings::fromJson(char* data, bool* changed)
transitionTime(root["transitionTime"]);
delay(root["delay"]);
JsonArray& jsonTriggers = root["triggers"];
if (mTriggers != nullptr)
delete [] mTriggers;
mTriggerCount = jsonTriggers.size();
mTriggers = new MotionTrigger[mTriggerCount];
for (uint8_t i = 0; i < mTriggerCount; i++)
if (root.containsKey("triggers"))
{
JsonObject& jsonTrigger = jsonTriggers[i];
MotionTrigger* trigger = &mTriggers[i];
JsonArray& jsonTriggers = root["triggers"];
if (mTriggers != nullptr)
delete [] mTriggers;
trigger->pin = jsonTrigger["pin"];
trigger->brightness = jsonTrigger["brightness"];
trigger->direction = (MotionDirection)(uint8_t)jsonTrigger["direction"];
trigger->enabled = jsonTrigger["enabled"];
mTriggerCount = jsonTriggers.size();
mTriggers = new MotionTrigger[mTriggerCount];
for (uint8_t i = 0; i < mTriggerCount; i++)
{
JsonObject& jsonTrigger = jsonTriggers[i];
MotionTrigger* trigger = &mTriggers[i];
trigger->pin = jsonTrigger["pin"];
trigger->brightness = jsonTrigger["brightness"];
trigger->direction = (MotionDirection)(uint8_t)jsonTrigger["direction"];
trigger->enabled = jsonTrigger["enabled"];
}
}
if (changed != nullptr)

View File

@ -89,24 +89,27 @@ bool TimeTriggerSettings::fromJson(char* data, bool* changed)
enabled(root["enabled"]);
transitionTime(root["transitionTime"]);
JsonArray& jsonTriggers = root["triggers"];
if (mTriggers != nullptr)
delete [] mTriggers;
mTriggerCount = jsonTriggers.size();
mTriggers = new TimeTrigger[mTriggerCount];
for (uint8_t i = 0; i < mTriggerCount; i++)
if (root.containsKey("triggers"))
{
JsonObject& jsonTrigger = jsonTriggers[i];
TimeTrigger* trigger = &mTriggers[i];
JsonArray& jsonTriggers = root["triggers"];
if (mTriggers != nullptr)
delete [] mTriggers;
trigger->time = jsonTrigger["time"];
trigger->daysOfWeek = jsonTrigger["daysOfWeek"];
trigger->brightness = jsonTrigger["brightness"];
trigger->triggerType = (TimeTriggerType)(uint8_t)jsonTrigger["triggerType"];
trigger->enabled = jsonTrigger["enabled"];
mTriggerCount = jsonTriggers.size();
mTriggers = new TimeTrigger[mTriggerCount];
for (uint8_t i = 0; i < mTriggerCount; i++)
{
JsonObject& jsonTrigger = jsonTriggers[i];
TimeTrigger* trigger = &mTriggers[i];
trigger->time = jsonTrigger["time"];
trigger->daysOfWeek = jsonTrigger["daysOfWeek"];
trigger->brightness = jsonTrigger["brightness"];
trigger->triggerType = (TimeTriggerType)(uint8_t)jsonTrigger["triggerType"];
trigger->enabled = jsonTrigger["enabled"];
}
}
if (changed != nullptr)