1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-20 08:46:01 +00:00

Provide an option to select MQTT unique_id generator (#2701)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>
This commit is contained in:
Krzysztof Białek
2021-11-15 15:49:18 +01:00
committed by GitHub
parent 5404163be0
commit 515519bc87
6 changed files with 47 additions and 7 deletions

View File

@@ -55,6 +55,12 @@ struct Availability {
std::string payload_not_available;
};
/// available discovery unique_id generators
enum MQTTDiscoveryUniqueIdGenerator {
MQTT_LEGACY_UNIQUE_ID_GENERATOR = 0,
MQTT_MAC_ADDRESS_UNIQUE_ID_GENERATOR,
};
/** Internal struct for MQTT Home Assistant discovery
*
* See <a href="https://www.home-assistant.io/docs/mqtt/discovery/">MQTT Discovery</a>.
@@ -63,6 +69,7 @@ struct MQTTDiscoveryInfo {
std::string prefix; ///< The Home Assistant discovery prefix. Empty means disabled.
bool retain; ///< Whether to retain discovery messages.
bool clean;
MQTTDiscoveryUniqueIdGenerator unique_id_generator;
};
enum MQTTClientState {
@@ -98,9 +105,11 @@ class MQTTClientComponent : public Component {
*
* See <a href="https://www.home-assistant.io/docs/mqtt/discovery/">MQTT Discovery</a>.
* @param prefix The Home Assistant discovery prefix.
* @param unique_id_generator Controls how UniqueId is generated.
* @param retain Whether to retain discovery messages.
*/
void set_discovery_info(std::string &&prefix, bool retain, bool clean = false);
void set_discovery_info(std::string &&prefix, MQTTDiscoveryUniqueIdGenerator unique_id_generator, bool retain,
bool clean = false);
/// Get Home Assistant discovery info.
const MQTTDiscoveryInfo &get_discovery_info() const;
/// Globally disable Home Assistant discovery.