mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-11-01 14:22:12 +01:00
The 19 routes that changed rooms, shades, groups and repeaters on the web
server task (add, save, delete, link and unlink, setPaired, the sort
orders) now copy their request into a model_edit_t, queue it on the
LoopQueue and reply {status:accepted,requestId:N}. loop() applies it
(SomfyJson.cpp, next to fromJSON) and broadcasts requestResult {requestId,
ok, id, code, desc}. One edit at a time; a second gets 503, a body over
4 KB gets 413.
ModelEditor.h/.cpp holds the rules, tested natively: the lowest free id,
the next sort order, a free remote address, adding to and removing from
the group-member and repeater lists, and the GPIO pin-conflict check. They
replace the getNext*Id/getMax*Order copies, the remote-address search,
the list code and the inline pin checks. The pin check now uses the
protocol being saved and checks every pin against Ethernet, not only up.
/getNextRoom, /getNextShade, /getNextGroup, /groupOptions and a new
/repeaters (the UI already called it) are ModelSnapshot reads.
The web UI's editJSON() sends an edit, waits for its requestResult, then
reads the item back from /shade, /group, /room or /repeaters, so the
callbacks that used the old reply bodies are unchanged. No result within
5 s offers a reload; reads and edits told Busy are retried. It now also
refreshes its lists on shadeAdded/shadeRemoved/groupAdded/groupRemoved
from other clients, and procRoomRemoved keeps the right rooms.
Also fixed: a shade that fails validation is no longer added; linked
repeaters and sort orders are saved; linking reports a full list.
27 new native tests, 319 in all. Flash: esp32devdbg -11,484 bytes,
esp32dev -7,180 bytes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 lines
1.1 KiB
C
29 lines
1.1 KiB
C
#ifndef SOMFY_EDITOR_H
|
|
#define SOMFY_EDITOR_H
|
|
#include <ArduinoJson.h>
|
|
#include "ModelEditor.h"
|
|
|
|
// ModelEditor on the device: an edit of the shade model handed from the web
|
|
// server task to loop(), which applies it with the ModelEditor rules and tells
|
|
// the clients how it went.
|
|
|
|
// One edit on its way to loop(): the edit route and a copy of its request.
|
|
struct model_edit_t {
|
|
model_edit_type_t type = model_edit_type_t::add_room;
|
|
uint32_t requestId = 0;
|
|
JsonDocument doc;
|
|
};
|
|
|
|
// One edit at a time: false when one is already waiting or running. Any task.
|
|
bool beginModelEdit();
|
|
// The id the HTTP reply and the requestResult event carry. Any task.
|
|
uint32_t nextEditRequestId();
|
|
// Gives up an edit that was begun but never queued. Any task.
|
|
void cancelModelEdit(model_edit_t *edit);
|
|
// Applies the edit, saves it, sends requestResult and frees it. loop() only.
|
|
void runModelEdit(model_edit_t *edit);
|
|
// Applies the edit to the shade model and saves it. loop() only.
|
|
edit_result_t applyModelEdit(model_edit_t &edit);
|
|
// Tells every client how the edit went (SomfyEvents.cpp).
|
|
void emitRequestResult(uint32_t requestId, const edit_result_t &result);
|
|
#endif
|