Adopt has_entity_name to fix duplicated entity ids on HA 2026.4+ (#1499)

* Adopt has_entity_name to fix duplicated entity ids on HA 2026.4+

Since HA core 2026.4 (PR 166246) composes entity names as device name +
entity name, and only strips the device prefix when the entity name
starts with it. Adaptive Lighting's names ('Adaptive Lighting Sleep
Mode: stairs' on device 'Adaptive Lighting: stairs') never match, so
new installs get ids like
switch.adaptive_lighting_stairs_adaptive_lighting_sleep_mode_stairs.

Adopt has_entity_name: the main switch takes the device name
('Adaptive Lighting: <name>'), the simple switches use their role
('Sleep Mode', 'Adapt Brightness', 'Adapt Color'). Unique ids are
unchanged, so existing installs keep their entity ids via the registry.

Fixes #1459

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Test the new entity ids and that existing ones survive

The renamed constants were defined but never asserted, so neither the
fresh-install ids nor the registry-preservation claim were covered.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* test: keep the apply-service test light on

Avoid generating brightness zero in the attribute-change helper, which turns the light off and makes the test depend on the current adaptive brightness.

---------

Co-authored-by: proscar87 <proscar87@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Bas Nijholt <bas@nijho.lt>
Co-authored-by: Bas Nijholt <basnijholt@gmail.com>
This commit is contained in:
proscar87 2026-09-06 01:18:49 -06:00 • committed by GitHub
commit 55f871fd0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 9 deletions

View file

@ -852,6 +852,8 @@ def _attributes_have_changed(
class AdaptiveSwitch(SwitchEntity, RestoreEntity):
"""Representation of a Adaptive Lighting switch."""
_attr_has_entity_name = True
def __init__(
self,
hass: HomeAssistant,
@ -1003,9 +1005,10 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
)
@property
def name(self) -> str:
def name(self) -> str | None:
"""Return the name of the device if any."""
return f"Adaptive Lighting: {self._name}"
# The main switch takes the device name "Adaptive Lighting: <name>"
return None
@property
def unique_id(self) -> str:
@ -1024,7 +1027,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
identifiers={
(DOMAIN, self._name),
},
name=self._name,
name=f"Adaptive Lighting: {self._name}",
entry_type=DeviceEntryType.SERVICE,
)
@ -1636,6 +1639,8 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
class SimpleSwitch(SwitchEntity, RestoreEntity):
"""Representation of a Adaptive Lighting switch."""
_attr_has_entity_name = True
def __init__(
self,
which: str,
@ -1657,8 +1662,8 @@ class SimpleSwitch(SwitchEntity, RestoreEntity):
@property
def name(self) -> str:
"""Return the name of the device if any."""
return self._name
"""Return the name of the entity within its device."""
return self._which
@property
def unique_id(self) -> str: