diff --git a/homeassistant/components/wled/light.py b/homeassistant/components/wled/light.py index 98e60b9bb81..0151737ece9 100644 --- a/homeassistant/components/wled/light.py +++ b/homeassistant/components/wled/light.py @@ -57,8 +57,7 @@ async def async_setup_entry( """Set up WLED light based on a config entry.""" coordinator: WLEDDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] - platform = entity_platform.current_platform.get() - + platform = entity_platform.async_get_current_platform() platform.async_register_entity_service( SERVICE_EFFECT, { diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index 83e72c7491d..6350467c05b 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -696,6 +696,15 @@ current_platform: ContextVar[EntityPlatform | None] = ContextVar( ) +@callback +def async_get_current_platform() -> EntityPlatform: + """Get the current platform from context.""" + platform = current_platform.get() + if platform is None: + raise RuntimeError("Cannot get non-set current platform") + return platform + + @callback def async_get_platforms( hass: HomeAssistant, integration_name: str