api: Use mac address for entity unique ids

This commit is contained in:
Jesse Hills 2023-09-01 11:33:08 +12:00
parent cdb67fc90e
commit f614655af5
No known key found for this signature in database
GPG key ID: BEAAE804EFD8E83A

View file

@ -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();