Summary
ESPHome has added a new make_entity_preference<T>() helper on EntityBase (PR #13505) that encapsulates preference creation and will handle automatic preference migration when the hash algorithm is updated to fix collisions.
This component uses get_object_id_hash() for preference keys, which is the old API that predates even get_preference_hash() (which added device-awareness to avoid collisions across devices). Components using get_object_id_hash() directly are vulnerable to hash collisions when different entity names sanitize to the same string (e.g. "Living Room" and "living_room" both become "living_room"), and will not participate in automatic preference migration.
Current usage
In components/aux_ac/aux_ac.h:
ESPPreferenceObject storage = global_preferences->make_preference<ac_save_command_t[POS_MODE_OFF + 1]>(this->get_object_id_hash(), true);
Recommended migration
// Before:
ESPPreferenceObject storage = global_preferences->make_preference<ac_save_command_t[POS_MODE_OFF + 1]>(this->get_object_id_hash(), true);
// After:
ESPPreferenceObject storage = this->make_entity_preference<ac_save_command_t[POS_MODE_OFF + 1]>();
Note: if the second parameter true was being used for a specific purpose (e.g. the in_flash flag), check if make_entity_preference handles that or if additional adjustments are needed.
References
Summary
ESPHome has added a new
make_entity_preference<T>()helper onEntityBase(PR #13505) that encapsulates preference creation and will handle automatic preference migration when the hash algorithm is updated to fix collisions.This component uses
get_object_id_hash()for preference keys, which is the old API that predates evenget_preference_hash()(which added device-awareness to avoid collisions across devices). Components usingget_object_id_hash()directly are vulnerable to hash collisions when different entity names sanitize to the same string (e.g. "Living Room" and "living_room" both become "living_room"), and will not participate in automatic preference migration.Current usage
In
components/aux_ac/aux_ac.h:Recommended migration
Note: if the second parameter
truewas being used for a specific purpose (e.g. thein_flashflag), check ifmake_entity_preferencehandles that or if additional adjustments are needed.References