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 loadedpull/112156/head
parent
f1eab3f11f
commit
331989de4c
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue