Add HA Entity Category support to MQTT (#2678)

This commit is contained in:
Paul Monigatti 2021-11-08 22:03:30 +13:00 committed by GitHub
parent be9439f10d
commit a17a6d5346
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -77,6 +77,17 @@ bool MQTTComponent::send_discovery_() {
if (!this->get_icon().empty())
root[MQTT_ICON] = this->get_icon();
switch (this->get_entity()->get_entity_category()) {
case ENTITY_CATEGORY_NONE:
break;
case ENTITY_CATEGORY_CONFIG:
root[MQTT_ENTITY_CATEGORY] = "config";
break;
case ENTITY_CATEGORY_DIAGNOSTIC:
root[MQTT_ENTITY_CATEGORY] = "diagnostic";
break;
}
if (config.state_topic)
root[MQTT_STATE_TOPIC] = this->get_state_topic_();
if (config.command_topic)

View File

@ -512,6 +512,9 @@ constexpr const char *const MQTT_DEVICE_SW_VERSION = "sw_version";
constexpr const char *const MQTT_DEVICE_SUGGESTED_AREA = "suggested_area";
#endif
// Additional MQTT fields where no abbreviation is defined in HA source
constexpr const char *const MQTT_ENTITY_CATEGORY = "entity_category";
} // namespace mqtt
} // namespace esphome