Made sending triggers array optional when changing settings
This commit is contained in:
parent
a2f7021d2c
commit
4c57f17c8c
4
API.md
4
API.md
@ -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.
|
@ -55,23 +55,26 @@ bool MotionTriggerSettings::fromJson(char* data, bool* changed)
|
|||||||
transitionTime(root["transitionTime"]);
|
transitionTime(root["transitionTime"]);
|
||||||
delay(root["delay"]);
|
delay(root["delay"]);
|
||||||
|
|
||||||
JsonArray& jsonTriggers = root["triggers"];
|
if (root.containsKey("triggers"))
|
||||||
if (mTriggers != nullptr)
|
|
||||||
delete [] mTriggers;
|
|
||||||
|
|
||||||
mTriggerCount = jsonTriggers.size();
|
|
||||||
mTriggers = new MotionTrigger[mTriggerCount];
|
|
||||||
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < mTriggerCount; i++)
|
|
||||||
{
|
{
|
||||||
JsonObject& jsonTrigger = jsonTriggers[i];
|
JsonArray& jsonTriggers = root["triggers"];
|
||||||
MotionTrigger* trigger = &mTriggers[i];
|
if (mTriggers != nullptr)
|
||||||
|
delete [] mTriggers;
|
||||||
|
|
||||||
trigger->pin = jsonTrigger["pin"];
|
mTriggerCount = jsonTriggers.size();
|
||||||
trigger->brightness = jsonTrigger["brightness"];
|
mTriggers = new MotionTrigger[mTriggerCount];
|
||||||
trigger->direction = (MotionDirection)(uint8_t)jsonTrigger["direction"];
|
|
||||||
trigger->enabled = jsonTrigger["enabled"];
|
|
||||||
|
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)
|
if (changed != nullptr)
|
||||||
|
@ -89,24 +89,27 @@ bool TimeTriggerSettings::fromJson(char* data, bool* changed)
|
|||||||
enabled(root["enabled"]);
|
enabled(root["enabled"]);
|
||||||
transitionTime(root["transitionTime"]);
|
transitionTime(root["transitionTime"]);
|
||||||
|
|
||||||
JsonArray& jsonTriggers = root["triggers"];
|
if (root.containsKey("triggers"))
|
||||||
if (mTriggers != nullptr)
|
|
||||||
delete [] mTriggers;
|
|
||||||
|
|
||||||
mTriggerCount = jsonTriggers.size();
|
|
||||||
mTriggers = new TimeTrigger[mTriggerCount];
|
|
||||||
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < mTriggerCount; i++)
|
|
||||||
{
|
{
|
||||||
JsonObject& jsonTrigger = jsonTriggers[i];
|
JsonArray& jsonTriggers = root["triggers"];
|
||||||
TimeTrigger* trigger = &mTriggers[i];
|
if (mTriggers != nullptr)
|
||||||
|
delete [] mTriggers;
|
||||||
|
|
||||||
trigger->time = jsonTrigger["time"];
|
mTriggerCount = jsonTriggers.size();
|
||||||
trigger->daysOfWeek = jsonTrigger["daysOfWeek"];
|
mTriggers = new TimeTrigger[mTriggerCount];
|
||||||
trigger->brightness = jsonTrigger["brightness"];
|
|
||||||
trigger->triggerType = (TimeTriggerType)(uint8_t)jsonTrigger["triggerType"];
|
|
||||||
trigger->enabled = jsonTrigger["enabled"];
|
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)
|
if (changed != nullptr)
|
||||||
|
Loading…
Reference in New Issue
Block a user