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

Internal representation of a Home Assistant MQTT device. More...

#include <hamqtt_device.h>

Public Member Functions

HAMQTT_Devicehamqtt_device_create (HAMQTT_Device_Config *config)
 Create a new HAMQTT device.
void hamqtt_device_destroy (HAMQTT_Device *device)
 Destroy a HAMQTT device and free all resources.
esp_err_t hamqtt_device_add_component (HAMQTT_Device *device, HAMQTT_Component *component)
 Add a component (e.g. sensor, switch) to the device.
esp_err_t hamqtt_device_connect (HAMQTT_Device *device)
 Connect the device to the MQTT broker and publish its Home Assistant discovery config.
esp_err_t hamqtt_device_publish_availability (const HAMQTT_Device *device, bool availability)
 Publish an availability message to Home Assistant.
void hamqtt_device_loop (const HAMQTT_Device *device)
 Update the state of all components and publish to MQTT.
const HAMQTT_Device_Confighamqtt_device_get_config (const HAMQTT_Device *device)
 Get the configuration used to initialize the device.

Detailed Description

Internal representation of a Home Assistant MQTT device.

Member Function Documentation

◆ hamqtt_device_add_component()

esp_err_t hamqtt_device_add_component ( HAMQTT_Device * device,
HAMQTT_Component * component )

Add a component (e.g. sensor, switch) to the device.

Parameters
devicePointer to the device.
componentPointer to a component implementing the HAMQTT_Component interface.
Returns
  • ESP_OK on success
  • ESP_ERR_NO_MEM if component buffer is full
  • ESP_ERR_INVALID_ARG if inputs are invalid

◆ hamqtt_device_connect()

esp_err_t hamqtt_device_connect ( HAMQTT_Device * device)

Connect the device to the MQTT broker and publish its Home Assistant discovery config.

This must be called before calling hamqtt_device_loop.

Parameters
devicePointer to the device.
Returns
  • ESP_OK on success
  • ESP_FAIL or MQTT-related error code on failure

◆ hamqtt_device_create()

HAMQTT_Device * hamqtt_device_create ( HAMQTT_Device_Config * config)

Create a new HAMQTT device.

Parameters
configPointer to a device configuration. Must remain valid for the lifetime of the device.
Returns
Pointer to the created HAMQTT_Device, or NULL on failure.

◆ hamqtt_device_destroy()

void hamqtt_device_destroy ( HAMQTT_Device * device)

Destroy a HAMQTT device and free all resources.

Parameters
devicePointer to the device to destroy. Must not be NULL.

◆ hamqtt_device_get_config()

const HAMQTT_Device_Config * hamqtt_device_get_config ( const HAMQTT_Device * device)

Get the configuration used to initialize the device.

Parameters
devicePointer to the device.
Returns
Pointer to the original configuration struct.

◆ hamqtt_device_loop()

void hamqtt_device_loop ( const HAMQTT_Device * device)

Update the state of all components and publish to MQTT.

This should be called periodically to keep sensor states up to date.

Parameters
devicePointer to the device.

◆ hamqtt_device_publish_availability()

esp_err_t hamqtt_device_publish_availability ( const HAMQTT_Device * device,
bool availability )

Publish an availability message to Home Assistant.

Parameters
devicePointer to the device.
availabilitytrue if available, false if offline.
Returns
  • ESP_OK on success
  • ESP_ERR_INVALID_STATE if the device has not connected to MQTT

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