128 lines
4.3 KiB
C
128 lines
4.3 KiB
C
#include "fake_api_ctx.h"
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "light/nl_boot_state.h"
|
|
|
|
nl_light_state_t fake_state;
|
|
nl_settings_t fake_settings;
|
|
nl_sys_info_t fake_info;
|
|
nl_light_change_t fake_last_change;
|
|
nl_ctrl_err_t fake_apply_result;
|
|
int fake_apply_calls, fake_save_calls, fake_save_result;
|
|
int fake_wifi_calls, fake_wifi_result;
|
|
char fake_wifi_ssid[NL_SSID_LEN], fake_wifi_pass[NL_PASS_LEN];
|
|
int fake_standalone_calls, fake_standalone_result;
|
|
bool fake_standalone_enabled, fake_standalone_pulse;
|
|
char fake_standalone_ssid[NL_SSID_LEN], fake_standalone_pass[NL_PASS_LEN];
|
|
uint8_t fake_standalone_channel;
|
|
int fake_factory_calls, fake_ping_calls, fake_fw_result;
|
|
char fake_fw_url[256];
|
|
bool fake_open;
|
|
|
|
static void get_state(nl_light_state_t *out) { *out = fake_state; }
|
|
|
|
static nl_ctrl_err_t apply(const nl_light_change_t *c)
|
|
{
|
|
fake_apply_calls++;
|
|
fake_last_change = *c;
|
|
if (fake_apply_result != NL_CTRL_OK)
|
|
return fake_apply_result;
|
|
if (c->has_on) fake_state.on = c->on;
|
|
if (c->has_brightness) fake_state.brightness = c->brightness;
|
|
if (c->has_color) { fake_state.r = c->r; fake_state.g = c->g; fake_state.b = c->b; fake_state.mode = NL_MODE_COLOR; }
|
|
if (c->has_ct) { fake_state.ct = c->ct; fake_state.mode = NL_MODE_WHITE; }
|
|
return NL_CTRL_OK;
|
|
}
|
|
|
|
static void get_settings(nl_settings_t *out) { *out = fake_settings; }
|
|
|
|
static int save_settings(const nl_settings_t *s)
|
|
{
|
|
fake_save_calls++;
|
|
if (fake_save_result == 0)
|
|
fake_settings = *s;
|
|
return fake_save_result;
|
|
}
|
|
|
|
static int wifi_configure(const char *ssid, const char *pass)
|
|
{
|
|
fake_wifi_calls++;
|
|
strncpy(fake_wifi_ssid, ssid, sizeof fake_wifi_ssid - 1);
|
|
strncpy(fake_wifi_pass, pass, sizeof fake_wifi_pass - 1);
|
|
return fake_wifi_result;
|
|
}
|
|
|
|
static int fake_standalone_configure(bool enabled, const char *ssid, const char *pass,
|
|
uint8_t channel, bool pulse)
|
|
{
|
|
fake_standalone_calls++;
|
|
fake_standalone_enabled = enabled;
|
|
fake_standalone_pulse = pulse;
|
|
fake_standalone_channel = channel;
|
|
snprintf(fake_standalone_ssid, sizeof fake_standalone_ssid, "%s", ssid ? ssid : "");
|
|
snprintf(fake_standalone_pass, sizeof fake_standalone_pass, "%s", pass ? pass : "");
|
|
return fake_standalone_result;
|
|
}
|
|
|
|
static bool open_access(void) { return fake_open; }
|
|
static void get_info(nl_sys_info_t *out) { *out = fake_info; }
|
|
static void factory_reset(void) { fake_factory_calls++; }
|
|
static void ping(void) { fake_ping_calls++; }
|
|
|
|
static int fw_update(const char *url)
|
|
{
|
|
strncpy(fake_fw_url, url, sizeof fake_fw_url - 1);
|
|
return fake_fw_result;
|
|
}
|
|
|
|
nl_api_ctx_t fake_ctx;
|
|
|
|
void fake_api_reset(const char *board_id)
|
|
{
|
|
const nl_board_t *b = nl_board_find(board_id);
|
|
fake_state = nl_boot_default_state(b);
|
|
nl_settings_defaults(&fake_settings);
|
|
strcpy(fake_settings.name, "Wohnzimmer");
|
|
strcpy(fake_settings.wifi_ssid, "ninHome");
|
|
memset(&fake_info, 0, sizeof fake_info);
|
|
strcpy(fake_info.mac, "28:6d:cd:5c:68:1f");
|
|
strcpy(fake_info.name, "Wohnzimmer");
|
|
fake_info.wifi_mode = "sta";
|
|
strcpy(fake_info.ssid, "ninHome");
|
|
fake_info.rssi = -58;
|
|
strcpy(fake_info.ip, "192.168.1.50");
|
|
fake_info.uptime_s = 123;
|
|
fake_info.free_heap = 40000;
|
|
memset(&fake_last_change, 0, sizeof fake_last_change);
|
|
fake_apply_result = NL_CTRL_OK;
|
|
fake_apply_calls = fake_save_calls = fake_save_result = 0;
|
|
fake_wifi_calls = fake_wifi_result = 0;
|
|
fake_wifi_ssid[0] = fake_wifi_pass[0] = '\0';
|
|
fake_standalone_calls = fake_standalone_result = 0;
|
|
fake_standalone_enabled = fake_standalone_pulse = false;
|
|
fake_standalone_ssid[0] = fake_standalone_pass[0] = '\0';
|
|
fake_standalone_channel = 0;
|
|
fake_factory_calls = fake_ping_calls = 0;
|
|
fake_fw_result = -1;
|
|
fake_fw_url[0] = '\0';
|
|
fake_open = false;
|
|
|
|
fake_ctx.board = b;
|
|
fake_ctx.fw_version = "1.2.3";
|
|
fake_ctx.build_date = "2026-09-11";
|
|
fake_ctx.get_state = get_state;
|
|
fake_ctx.apply = apply;
|
|
fake_ctx.get_settings = get_settings;
|
|
fake_ctx.save_settings = save_settings;
|
|
fake_ctx.wifi_configure = wifi_configure;
|
|
fake_ctx.standalone_configure = fake_standalone_configure;
|
|
fake_ctx.hostname = "ninlight-681f";
|
|
fake_ctx.open_access = open_access;
|
|
fake_ctx.get_info = get_info;
|
|
fake_ctx.factory_reset = factory_reset;
|
|
fake_ctx.ping = ping;
|
|
fake_ctx.fw_update = fw_update;
|
|
}
|