mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 22:02:17 +01:00
refactor: apply shade model edits on loop() through ModelEditor
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>
This commit is contained in:
parent
bde8a1efd1
commit
72b37e5f8d
20 changed files with 1035 additions and 918 deletions
|
|
@ -83,6 +83,8 @@ struct group_snapshot_t {
|
|||
// Only the rooms, shades, groups and repeaters that exist, in model order.
|
||||
struct model_snapshot_t {
|
||||
uint32_t startingAddress;
|
||||
uint8_t radioBitLength; // what a new shade or group gets
|
||||
uint8_t radioProto;
|
||||
uint8_t roomCount;
|
||||
uint8_t shadeCount;
|
||||
uint8_t groupCount;
|
||||
|
|
@ -115,7 +117,12 @@ enum class snapshot_doc_t : uint8_t {
|
|||
groups, // /groups
|
||||
room, // /room?roomId=
|
||||
shade, // /shade?shadeId=
|
||||
group // /group?groupId=
|
||||
group, // /group?groupId=
|
||||
repeaters, // /repeaters
|
||||
nextRoom, // /getNextRoom: the id and defaults a new room would get
|
||||
nextShade, // /getNextShade
|
||||
nextGroup, // /getNextGroup
|
||||
groupOptions // /groupOptions?groupId=: the group and the shades it could link
|
||||
};
|
||||
// Writes the fields of /controller or /discovery that aren't in the snapshot
|
||||
// (device, radio and firmware details) into the open top-level object.
|
||||
|
|
@ -154,8 +161,15 @@ class SnapshotWriter {
|
|||
void resetFmt(size_t offset);
|
||||
bool overflowed(const char *what, uint8_t itemId);
|
||||
size_t itemStart();
|
||||
void groupUnit(const group_snapshot_t &group, bool comma);
|
||||
void groupUnit(const group_snapshot_t &group, bool inList, const char *close = "]}");
|
||||
void finish(const char *text);
|
||||
};
|
||||
// What the next room, shade or group added would get: its id (0 for a room and
|
||||
// 255 for a shade or group when there is no room for one) and remote address.
|
||||
uint8_t nextRoomId(const model_snapshot_t &snap);
|
||||
uint8_t nextShadeId(const model_snapshot_t &snap);
|
||||
uint8_t nextGroupId(const model_snapshot_t &snap);
|
||||
uint32_t nextRemoteAddress(const model_snapshot_t &snap, uint8_t id);
|
||||
|
||||
// The snapshots reads are served from. A read takes a slot on the web server
|
||||
// task and queues a fill; loop() fills it; the read streams it and lets it go.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue