mirror of
https://github.com/esphome/esphome.git
synced 2024-12-20 16:18:49 +01:00
Fix MQTT client_id changed (#579)
Fixes https://github.com/esphome/issues/issues/323
This commit is contained in:
parent
605e365405
commit
ebb5d58c14
@ -104,7 +104,7 @@ CONFIG_SCHEMA = cv.All(cv.Schema({
|
|||||||
cv.Optional(CONF_PORT, default=1883): cv.port,
|
cv.Optional(CONF_PORT, default=1883): cv.port,
|
||||||
cv.Optional(CONF_USERNAME, default=''): cv.string,
|
cv.Optional(CONF_USERNAME, default=''): cv.string,
|
||||||
cv.Optional(CONF_PASSWORD, default=''): cv.string,
|
cv.Optional(CONF_PASSWORD, default=''): cv.string,
|
||||||
cv.Optional(CONF_CLIENT_ID, default=lambda: CORE.name): cv.string,
|
cv.Optional(CONF_CLIENT_ID): cv.string,
|
||||||
cv.Optional(CONF_DISCOVERY, default=True): cv.Any(cv.boolean, cv.one_of("CLEAN", upper=True)),
|
cv.Optional(CONF_DISCOVERY, default=True): cv.Any(cv.boolean, cv.one_of("CLEAN", upper=True)),
|
||||||
cv.Optional(CONF_DISCOVERY_RETAIN, default=True): cv.boolean,
|
cv.Optional(CONF_DISCOVERY_RETAIN, default=True): cv.boolean,
|
||||||
cv.Optional(CONF_DISCOVERY_PREFIX, default="homeassistant"): cv.publish_topic,
|
cv.Optional(CONF_DISCOVERY_PREFIX, default="homeassistant"): cv.publish_topic,
|
||||||
@ -161,6 +161,7 @@ def to_code(config):
|
|||||||
cg.add(var.set_broker_port(config[CONF_PORT]))
|
cg.add(var.set_broker_port(config[CONF_PORT]))
|
||||||
cg.add(var.set_username(config[CONF_USERNAME]))
|
cg.add(var.set_username(config[CONF_USERNAME]))
|
||||||
cg.add(var.set_password(config[CONF_PASSWORD]))
|
cg.add(var.set_password(config[CONF_PASSWORD]))
|
||||||
|
if CONF_CLIENT_ID in config:
|
||||||
cg.add(var.set_client_id(config[CONF_CLIENT_ID]))
|
cg.add(var.set_client_id(config[CONF_CLIENT_ID]))
|
||||||
|
|
||||||
discovery = config[CONF_DISCOVERY]
|
discovery = config[CONF_DISCOVERY]
|
||||||
|
@ -15,7 +15,10 @@ namespace mqtt {
|
|||||||
|
|
||||||
static const char *TAG = "mqtt";
|
static const char *TAG = "mqtt";
|
||||||
|
|
||||||
MQTTClientComponent::MQTTClientComponent() { global_mqtt_client = this; }
|
MQTTClientComponent::MQTTClientComponent() {
|
||||||
|
global_mqtt_client = this;
|
||||||
|
this->credentials_.client_id = App.get_name() + "-" + get_mac_address();
|
||||||
|
}
|
||||||
|
|
||||||
// Connection
|
// Connection
|
||||||
void MQTTClientComponent::setup() {
|
void MQTTClientComponent::setup() {
|
||||||
|
Loading…
Reference in New Issue
Block a user