feat: seed a default profile at first boot

A store with no profile gets a default one, using the seed POST /profiles already
creates plus a starter palette. db/ now holds those records instead of stored
data, and the unused db/presets/*.bin files are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Opus 5.5 committed 2026-11-04 20:47:00 +13:00
1 parent b6aa0635ae
commit 190c8bc982
62 files changed
+51 -124

No files matched your search

+1
View File
@@ -510,6 +510,7 @@ esp_err_t api_register(httpd_handle_t server)
{
store_lock();
api_settings_defaults();
api_seed_defaults();
api_migrate_sequences();
api_migrate_zones();
api_migrate_groups();
+1
View File
@@ -54,6 +54,7 @@ bool api_preset_in_profile(const cJSON *rec);
// Bring records written by older versions into the current shape (at boot)
void api_migrate_sequences(void);
void api_seed_defaults(void);
void api_migrate_zones(void);
void api_migrate_groups(void);
+38 -15
View File
@@ -222,28 +222,20 @@ static bool truthy(const cJSON *v)
return cJSON_IsTrue(v) || (cJSON_IsNumber(v) && v->valuedouble != 0);
}
// POST /profiles: the profile, an empty palette, the seed presets and a "default" zone (plus a "dj"
// zone with seed_dj_zone)
static esp_err_t create_profile(httpd_req_t *req)
// The profile with fields applied, the palette (taken over), the seed presets and a "default" zone
// (plus a "dj" zone with dj), all saved; returns the profile, its id in pid
static cJSON *seed_profile(const cJSON *fields, cJSON *palette, bool dj, char *pid, size_t plen)
{
cJSON *body = api_body(req);
if (!body) {
return ESP_OK;
}
bool dj = truthy(cJSON_GetObjectItem(body, "seed_dj_zone"));
cJSON_DeleteItemFromObject(body, "seed_dj_zone");
char palid[16], pid[16], zid[16], djid[16];
api_add("palette", cJSON_CreateArray(), palid, sizeof(palid));
char palid[16], zid[16], djid[16];
api_add("palette", palette, palid, sizeof(palid));
cJSON *prof = cJSON_CreateObject();
cJSON_AddStringToObject(prof, "name", "");
cJSON_AddStringToObject(prof, "type", "zones");
cJSON_AddArrayToObject(prof, "zones");
cJSON_AddArrayToObject(prof, "scenes");
api_merge(prof, body);
cJSON_Delete(body);
api_merge(prof, fields);
api_set(prof, "palette_id", cJSON_CreateString(palid));
api_add("profile", prof, pid, sizeof(pid));
api_add("profile", prof, pid, plen);
cJSON *zones = cJSON_CreateArray();
seed_zone(pid, "default", "1", true, SEED, sizeof(SEED) / sizeof(SEED[0]), zid, sizeof(zid));
@@ -257,10 +249,41 @@ static esp_err_t create_profile(httpd_req_t *req)
store_save("preset");
store_save("zone");
store_save("profile");
return prof;
}
// POST /profiles: seed_profile with an empty palette ("dj" zone with seed_dj_zone)
static esp_err_t create_profile(httpd_req_t *req)
{
cJSON *body = api_body(req);
if (!body) {
return ESP_OK;
}
bool dj = truthy(cJSON_GetObjectItem(body, "seed_dj_zone"));
cJSON_DeleteItemFromObject(body, "seed_dj_zone");
char pid[16];
cJSON *prof = seed_profile(body, cJSON_CreateArray(), dj, pid, sizeof(pid));
cJSON_Delete(body);
engine_groups_changed();
return send_keyed(req, "201 Created", pid, prof);
}
// A store with no profile (first boot, or after an erase) gets one to start from; db/ holds the same records
void api_seed_defaults(void)
{
if (store_coll("profile")->child) {
return;
}
cJSON *fields = cJSON_CreateObject();
cJSON_AddStringToObject(fields, "name", "default");
char pid[16];
seed_profile(fields,
cJSON_Parse("[\"#FF0000\",\"#00FF00\",\"#0000FF\",\"#FFFF00\",\"#FF00FF\",\"#00FFFF\",\"#FFFFFF\",\"#000000\"]"),
false, pid, sizeof(pid));
cJSON_Delete(fields);
}
static const cJSON *profile_zones(const cJSON *prof)
{
const cJSON *z = cJSON_GetObjectItem(prof, "zones");