#pragma once #include #include namespace kvida { // Starts mDNS-based MQTT broker discovery (_mqtt._tcp) and, once found, // connects the MQTT client and publishes Home Assistant MQTT Discovery // for a diagnostic "connectivity" entity. Safe to call multiple times // (no-op if already connecting/connected). void start_mqtt(); bool mqtt_connected(); // Publishes a named numeric value as a Home Assistant MQTT Discovery // sensor: `kvida//` state topic, `homeassistant/sensor///config` // discovery topic. This is the semantic publish(name, value) API AGENTS.md // describes -- driven by `lua_runtime`'s `kvida.publish()`, not called // directly by other components. Discovery is republished (retained, so // idempotent) on every call rather than cached behind a per-name // "already announced" flag -- simpler, at the cost of a bit of extra // retained-message traffic each call. TODO: cache announced names if // that traffic becomes a real concern. void publish_value(const char *name, double value); // Registered by main to receive "set LED color" commands from Home // Assistant (an RGB light entity) without transport depending on // `drivers` directly. using LedColorHandler = void (*)(uint8_t red, uint8_t green, uint8_t blue); void set_led_color_handler(LedColorHandler handler); // Same no-dependency-on-other-components pattern as LedColorHandler: // registered by main so a POST to /api/script can hand the new script to // `lua_runtime` without transport depending on it. `script` is not // NUL-terminated by the caller's guarantee -- handlers must use `len`. using ScriptChangeHandler = void (*)(const char *script, size_t len); void set_script_change_handler(ScriptChangeHandler handler); // Registered by main so GET /api/script can pull the currently-running // script from `lua_runtime`. Called with a buffer of size `cap`; returns // the number of bytes written (0 if no provider is registered yet). using ScriptProvider = size_t (*)(char *buf, size_t cap); void set_script_provider(ScriptProvider provider); } // namespace kvida