Skip to content
Snippets Groups Projects
Unverified Commit 036e99e9 authored by Raman Gupta's avatar Raman Gupta Committed by GitHub
Browse files

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

parent 4bb2c6e0
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
"""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")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment