mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Allow integrations to define trigger platforms with a subtype (#54861)
This commit is contained in:
parent
4bb2c6e00f
commit
036e99e91e
@ -21,7 +21,8 @@ _PLATFORM_ALIASES = {
|
||||
|
||||
|
||||
async def _async_get_trigger_platform(hass: HomeAssistant, config: ConfigType) -> Any:
|
||||
platform = config[CONF_PLATFORM]
|
||||
platform_and_sub_type = config[CONF_PLATFORM].split(".")
|
||||
platform = platform_and_sub_type[0]
|
||||
for alias, triggers in _PLATFORM_ALIASES.items():
|
||||
if platform in triggers:
|
||||
platform = alias
|
||||
|
@ -1,8 +1,13 @@
|
||||
"""The tests for the trigger helper."""
|
||||
from unittest.mock import MagicMock, call, patch
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.helpers.trigger import async_validate_trigger_config
|
||||
from homeassistant.helpers.trigger import (
|
||||
_async_get_trigger_platform,
|
||||
async_validate_trigger_config,
|
||||
)
|
||||
|
||||
|
||||
async def test_bad_trigger_platform(hass):
|
||||
@ -10,3 +15,12 @@ async def test_bad_trigger_platform(hass):
|
||||
with pytest.raises(vol.Invalid) as ex:
|
||||
await async_validate_trigger_config(hass, [{"platform": "not_a_platform"}])
|
||||
assert "Invalid platform 'not_a_platform' specified" in str(ex)
|
||||
|
||||
|
||||
async def test_trigger_subtype(hass):
|
||||
"""Test trigger subtypes."""
|
||||
with patch(
|
||||
"homeassistant.helpers.trigger.async_get_integration", return_value=MagicMock()
|
||||
) as integration_mock:
|
||||
await _async_get_trigger_platform(hass, {"platform": "test.subtype"})
|
||||
assert integration_mock.call_args == call(hass, "test")
|
||||
|
Loading…
x
Reference in New Issue
Block a user