Migrate condition/state/trigger helper to use async_get_platform (#112144)

Currently these would always load the platform in the loop
if it was not already loaded
pull/112156/head
J. Nick Koston 2024-03-03 16:20:47 -10:00 committed by GitHub
parent f1eab3f11f
commit 331989de4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 7 additions and 4 deletions

View File

@ -197,7 +197,7 @@ async def _async_get_condition_platform(
f'Invalid condition "{platform}" specified {config}'
) from None
try:
return integration.get_platform("condition")
return await integration.async_get_platform("condition")
except ImportError:
raise HomeAssistantError(
f"Integration '{platform}' does not provide condition support"

View File

@ -53,7 +53,9 @@ async def async_reproduce_state(
return
try:
platform: ModuleType = integration.get_platform("reproduce_state")
platform: ModuleType = await integration.async_get_platform(
"reproduce_state"
)
except ImportError:
_LOGGER.warning("Integration %s does not support reproduce state", domain)
return

View File

@ -222,7 +222,7 @@ async def _async_get_trigger_platform(
except IntegrationNotFound:
raise vol.Invalid(f"Invalid platform '{platform}' specified") from None
try:
return integration.get_platform("trigger")
return await integration.async_get_platform("trigger")
except ImportError:
raise vol.Invalid(
f"Integration '{platform}' does not provide trigger support"

View File

@ -33,7 +33,8 @@ async def test_bad_trigger_platform(hass: HomeAssistant) -> None:
async def test_trigger_subtype(hass: HomeAssistant) -> None:
"""Test trigger subtypes."""
with patch(
"homeassistant.helpers.trigger.async_get_integration", return_value=MagicMock()
"homeassistant.helpers.trigger.async_get_integration",
return_value=MagicMock(async_get_platform=AsyncMock()),
) as integration_mock:
await _async_get_trigger_platform(hass, {"platform": "test.subtype"})
assert integration_mock.call_args == call(hass, "test")