mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Add small async_get_current_platform helper method (#50014)
This commit is contained in:
parent
6e98b020ac
commit
efb1bb08a4
@ -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,
|
||||
{
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user