Allow integrations to define trigger platforms with a subtype (#54861)

This commit is contained in:
Raman Gupta 2021-08-20 00:43:04 -04:00 committed by GitHub
parent 4bb2c6e00f
commit 036e99e91e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -21,7 +21,8 @@ _PLATFORM_ALIASES = {
async def _async_get_trigger_platform(hass: HomeAssistant, config: ConfigType) -> Any: 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(): for alias, triggers in _PLATFORM_ALIASES.items():
if platform in triggers: if platform in triggers:
platform = alias platform = alias

View File

@ -1,8 +1,13 @@
"""The tests for the trigger helper.""" """The tests for the trigger helper."""
from unittest.mock import MagicMock, call, patch
import pytest import pytest
import voluptuous as vol 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): 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: with pytest.raises(vol.Invalid) as ex:
await async_validate_trigger_config(hass, [{"platform": "not_a_platform"}]) await async_validate_trigger_config(hass, [{"platform": "not_a_platform"}])
assert "Invalid platform 'not_a_platform' specified" in str(ex) 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")