mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
api: Use mac address for entity unique ids
This commit is contained in:
parent
cdb67fc90e
commit
f614655af5
1 changed files with 3 additions and 7 deletions
|
@ -161,7 +161,7 @@ void APIConnection::loop() {
|
|||
}
|
||||
|
||||
std::string get_default_unique_id(const std::string &component_type, EntityBase *entity) {
|
||||
return App.get_name() + component_type + entity->get_object_id();
|
||||
return get_mac_address_pretty() + "-" + component_type + "-" + entity->get_object_id();
|
||||
}
|
||||
|
||||
DisconnectResponse APIConnection::disconnect(const DisconnectRequest &msg) {
|
||||
|
@ -437,8 +437,6 @@ bool APIConnection::send_sensor_info(sensor::Sensor *sensor) {
|
|||
msg.object_id = sensor->get_object_id();
|
||||
if (sensor->has_own_name())
|
||||
msg.name = sensor->get_name();
|
||||
msg.unique_id = sensor->unique_id();
|
||||
if (msg.unique_id.empty())
|
||||
msg.unique_id = get_default_unique_id("sensor", sensor);
|
||||
msg.icon = sensor->get_icon();
|
||||
msg.unit_of_measurement = sensor->get_unit_of_measurement();
|
||||
|
@ -505,8 +503,6 @@ bool APIConnection::send_text_sensor_info(text_sensor::TextSensor *text_sensor)
|
|||
msg.key = text_sensor->get_object_id_hash();
|
||||
msg.object_id = text_sensor->get_object_id();
|
||||
msg.name = text_sensor->get_name();
|
||||
msg.unique_id = text_sensor->unique_id();
|
||||
if (msg.unique_id.empty())
|
||||
msg.unique_id = get_default_unique_id("text_sensor", text_sensor);
|
||||
msg.icon = text_sensor->get_icon();
|
||||
msg.disabled_by_default = text_sensor->is_disabled_by_default();
|
||||
|
|
Loading…
Reference in a new issue