HAMQTT 0.1.0
ESP-IDF component for integrating devices with Home Assistant over MQTT
|
Base struct representing a generic Home Assistant MQTT component. More...
#include <hamqtt_component_internal.h>
Public Member Functions | |
esp_err_t | hamqtt_component_get_discovery_config (HAMQTT_Component *component, cJSON *root, const char *device_uid) |
Populates the Home Assistant discovery configuration for the component. | |
void | hamqtt_component_handle_mqtt_message (HAMQTT_Component *component, const char *topic, const char *data) |
Dispatches an incoming MQTT message to the specified component. | |
void | hamqtt_component_update (HAMQTT_Component *component, esp_mqtt_client_handle_t client) |
Performs a periodic update for the component. | |
const char * | hamqtt_component_get_unique_id (HAMQTT_Component *component) |
Returns the unique ID of the component. | |
const char *const * | hamqtt_component_get_subscribed_topics (HAMQTT_Component *component, size_t *count) |
Returns the list of topics the component wants to subscribe to. |
Public Attributes | |
const HAMQTT_Component_VTable * | v |
Base struct representing a generic Home Assistant MQTT component.
esp_err_t hamqtt_component_get_discovery_config | ( | HAMQTT_Component * | component, |
cJSON * | root, | ||
const char * | device_uid ) |
Populates the Home Assistant discovery configuration for the component.
This function builds a JSON object containing discovery configuration information for the specified component. This information is used by Home Assistant to automatically set up the entity.
component | Pointer to the component instance. |
root | Pointer to the cJSON object to populate. |
device_uid | Unique ID of the parent device to associate with the component. |
const char *const * hamqtt_component_get_subscribed_topics | ( | HAMQTT_Component * | component, |
size_t * | count ) |
Returns the list of topics the component wants to subscribe to.
The component uses these topics to receive control or data messages.
component | Pointer to the component instance. |
count | Pointer to a size_t to receive the number of topics. |
const char * hamqtt_component_get_unique_id | ( | HAMQTT_Component * | component | ) |
Returns the unique ID of the component.
This ID is used for discovery, topic namespacing, and internal lookup.
component | Pointer to the component instance. |
void hamqtt_component_handle_mqtt_message | ( | HAMQTT_Component * | component, |
const char * | topic, | ||
const char * | data ) |
Dispatches an incoming MQTT message to the specified component.
This function should be called when an MQTT message is received for a topic that the component has subscribed to. The component will parse the message and act on it accordingly.
component | Pointer to the component instance. |
topic | The topic string. |
topic_len | Length of the topic string. |
data | The message payload. |
data_len | Length of the payload. |
void hamqtt_component_update | ( | HAMQTT_Component * | component, |
esp_mqtt_client_handle_t | client ) |
Performs a periodic update for the component.
This function is typically called in the main loop to allow the component to publish state changes or perform maintenance tasks.
component | Pointer to the component instance. |
client | MQTT client handle to use for publishing. |