HAMQTT 0.1.0
ESP-IDF component for integrating devices with Home Assistant over MQTT
Loading...
Searching...
No Matches
HAMQTT_Component Struct Reference

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_VTablev

Detailed Description

Base struct representing a generic Home Assistant MQTT component.

Member Function Documentation

◆ hamqtt_component_get_discovery_config()

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.

Parameters
componentPointer to the component instance.
rootPointer to the cJSON object to populate.
device_uidUnique ID of the parent device to associate with the component.
Returns
esp_err_t ESP_OK on success, or an appropriate error code on failure.

◆ hamqtt_component_get_subscribed_topics()

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.

Parameters
componentPointer to the component instance.
countPointer to a size_t to receive the number of topics.
Returns
const char* const* Array of topic strings.

◆ hamqtt_component_get_unique_id()

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.

Parameters
componentPointer to the component instance.
Returns
const char* Unique ID string.

◆ hamqtt_component_handle_mqtt_message()

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.

Parameters
componentPointer to the component instance.
topicThe topic string.
topic_lenLength of the topic string.
dataThe message payload.
data_lenLength of the payload.

◆ hamqtt_component_update()

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.

Parameters
componentPointer to the component instance.
clientMQTT client handle to use for publishing.

The documentation for this struct was generated from the following files: