Skip to content

Instantly share code, notes, and snippets.

@stephanGarland
Last active April 5, 2026 21:35
Show Gist options
  • Select an option

  • Save stephanGarland/9bc8bd4947b703a6a41de7170ce57aef to your computer and use it in GitHub Desktop.

Select an option

Save stephanGarland/9bc8bd4947b703a6a41de7170ce57aef to your computer and use it in GitHub Desktop.
Home Assistant Adaptive Lighting Possible Fixes

Background

Due to a change in how HomeAssistant Core parses entity IDs / names, the resultant entity_id for Adaptive Lighting has duplicated wording, e.g. switch.adaptive_lighting_stairs_adaptive_lighting_sleep_mode_stairs instead of switch.adaptive_lighting_sleep_mode.

_async_strip_prefix_from_entity_name() and _async_get_full_entity_name() were modified in 151eae4 as part of PR 166246, which first appeared in 2026.4.0b0.

Possible Fixes

I looked into modifying HA Core itself; modifying the prefix stripping function to strip affixes partially worked, but there were other call sites where similar logic was needed. Plus, presumably they added that logic intentionally.

Of the two shown here, only one is really feasible long-term, since manually setting entity_id is discouraged by HA, and will also be removed in 2027.

has_entity_name

The ordering here has changed, which isn't ideal, but it may not matter to most.

Outcome

INFO:homeassistant.helpers.entity_registry:Registered new switch.adaptive_lighting entity: switch.adaptive_lighting_default_sleep_mode
INFO:homeassistant.helpers.entity_registry:Registered new switch.adaptive_lighting entity: switch.adaptive_lighting_default_adapt_color
INFO:homeassistant.helpers.entity_registry:Registered new switch.adaptive_lighting entity: switch.adaptive_lighting_default_adapt_brightness
INFO:homeassistant.helpers.entity_registry:Registered new switch.adaptive_lighting entity: switch.adaptive_lighting_default

Patch

diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py
index 9104997..c06434e 100644
--- a/custom_components/adaptive_lighting/switch.py
+++ b/custom_components/adaptive_lighting/switch.py
@@ -840,6 +840,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
         """Initialize the Adaptive Lighting switch."""
         # Set attributes that can't be modified during runtime
         assert hass is not None
+        self.has_entity_name: bool = True
         self.hass = hass
         self.manager = manager
         self.sleep_mode_switch = sleep_mode_switch
@@ -979,9 +980,9 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
         )
 
     @property
-    def name(self) -> str:
-        """Return the name of the device if any."""
-        return f"Adaptive Lighting: {self._name}"
+    def name(self) -> str | None:
+        """Return the name of the entity."""
+        return None
 
     @property
     def unique_id(self) -> str:
@@ -1000,7 +1001,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
             identifiers={
                 (DOMAIN, self._name),
             },
-            name=self._name,
+            name=f"Adaptive Lighting: {self._name}",
             entry_type=DeviceEntryType.SERVICE,
         )
 
@@ -1621,6 +1622,7 @@ class SimpleSwitch(SwitchEntity, RestoreEntity):
         icon: str,
     ) -> None:
         """Initialize the Adaptive Lighting switch."""
+        self.has_entity_name: bool = True
         self.hass = hass
         data = validate(config_entry)
         self._icon = icon
@@ -1633,8 +1635,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."""
+        return self._which
 
     @property
     def unique_id(self) -> str:

entity_id

The main problem with this approach - other than HA discouraging integrations from setting entity_id - is that it will be removed entirely in 2027.

Outcome

INFO:homeassistant.helpers.entity_registry:Registered new switch.adaptive_lighting entity: switch.adaptive_lighting_sleep_mode_default
INFO:homeassistant.helpers.entity_registry:Registered new switch.adaptive_lighting entity: switch.adaptive_lighting_adapt_color_default
INFO:homeassistant.helpers.entity_registry:Registered new switch.adaptive_lighting entity: switch.adaptive_lighting_adapt_brightness_default
INFO:homeassistant.helpers.entity_registry:Registered new switch.adaptive_lighting entity: switch.adaptive_lighting_default

Patch

diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py
index 9104997..ea837d7 100644
--- a/custom_components/adaptive_lighting/switch.py
+++ b/custom_components/adaptive_lighting/switch.py
@@ -849,6 +849,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
         data = validate(config_entry)

         self._name = data[CONF_NAME]
+        self.entity_id = f"switch.adaptive_lighting_{self._name}"
         self._interval: timedelta = data[CONF_INTERVAL]
         self.lights: list[str] = data[CONF_LIGHTS]

@@ -1629,6 +1630,9 @@ class SimpleSwitch(SwitchEntity, RestoreEntity):
         self._config_name = data[CONF_NAME]
         self._unique_id = f"{self._config_name}_{slugify(self._which)}"
         self._name = f"Adaptive Lighting {which}: {self._config_name}"
+        self.entity_id = (
+            f"switch.adaptive_lighting_{slugify(self._which)}_{self._config_name}"
+        )
         self._initial_state = initial_state

     @property
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment