Skip to content

Commit

Permalink
Update HomeAssistantDiscoveryClient.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
nordeep authored Oct 16, 2020
1 parent 37c250b commit c3e2c36
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/MQTT/HomeAssistantDiscoveryClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ void HomeAssistantDiscoveryClient::removeConfig(const BulbId& bulbId) {
void HomeAssistantDiscoveryClient::addConfig(const char* alias, const BulbId& bulbId) {
String topic = buildTopic(bulbId);
DynamicJsonDocument config(1024);

char uniqidBuffer[30];
sprintf_P(uniqidBuffer, PSTR("%X-%s"), ESP.getChipId(), alias);

config[F("schema")] = F("json");
config[F("name")] = alias;
config[F("command_topic")] = mqttClient->bindTopicString(settings.mqttTopicPattern, bulbId);
config[F("state_topic")] = mqttClient->bindTopicString(settings.mqttStateTopicPattern, bulbId);
config[F("uniq_id")] = mqttClient->bindTopicString(uniqidBuffer, bulbId);
JsonObject deviceMetadata = config.createNestedObject(F("device"));

deviceMetadata[F("manufacturer")] = F("esp8266_milight_hub");
Expand Down Expand Up @@ -170,4 +174,4 @@ void HomeAssistantDiscoveryClient::addNumberedEffects(JsonArray& effectList, uin
for (uint8_t i = start; i <= end; ++i) {
effectList.add(String(i));
}
}
}

0 comments on commit c3e2c36

Please sign in to comment.