♻️ Use has_entity_name + suffix-only entity names #46
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "refactor/has-entity-name"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
All Comwatt entities built their display name by hand:
_attr_name = f"{device['name']} Power". The modern HA convention ishas_entity_name = True+ a suffix-only name, letting HA prepend the device name for both the display name and the entity_id slug.Bug fixed along the way
ComwattSwitchalready had_attr_has_entity_name = Truebut kept_attr_name = f"{device['name']} Switch". So HA prefixed the device name a second time:switch.relay_relay_switchswitch.relay_switchThe switch tests looked the entity up dynamically, so the doubled name went unnoticed.
Changes
ComwattSensorbase:_attr_has_entity_name = True(covers the three sensor subclasses); each_attr_namedrops the device/site prefix →"Power","Total Energy",description.friendly_suffix.ComwattSwitch:_attr_name = "Switch"(already had the flag).No registry churn
Sensor entity_ids are unchanged — the device name still enters the slug via HA's
has_entity_namepath:sensor.relay_powerRelay Power(flag=False)Power(flag=True) → same idsensor.home_auto_production_rateHome Auto Production RateAuto Production Rate→ same idVerified empirically against HA 2026.2.3. The switch entity_id corrects from the doubled slug to the clean one for new installs; existing registry entries keep their persisted entity_id.
Test plan
switch.relay_switch+original_name == "Switch"Adopt Home Assistant's has_entity_name=True convention: the entity stores only its own suffix ("Power", "Switch", "Auto Production Rate") and HA prepends the device name for both the display name and the entity_id slug. - ComwattSensor base gets _attr_has_entity_name = True (covers the three sensor subclasses); each _attr_name drops the device/site prefix. - ComwattSwitch already had the flag but kept f"{device['name']} Switch", so HA prefixed the device name again → switch.relay_relay_switch. Now "Switch" → switch.relay_switch (fixes the doubled name). Entity ids are unchanged for sensors (device name still enters the slug via HA), so no registry churn for existing installs. The switch entity_id corrects from the doubled slug to the clean one for new installs; existing registry entries keep their persisted entity_id. Adds a regression assertion locking switch.relay_switch + original_name.6685f4f918d58eb9fce1