From 4d711898c73a10e7a6bcbe70e0c4841cd20ca151 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Wed, 14 Jul 2021 14:04:04 -0400 Subject: [PATCH] Add missing test coverage for sirens (#53014) --- tests/components/siren/test_init.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/components/siren/test_init.py b/tests/components/siren/test_init.py index 6f90b8a9fcd..729990ceaeb 100644 --- a/tests/components/siren/test_init.py +++ b/tests/components/siren/test_init.py @@ -1,7 +1,10 @@ """The tests for the siren component.""" from unittest.mock import MagicMock -from homeassistant.components.siren import SirenEntity +import pytest + +from homeassistant.components.siren import SirenEntity, process_turn_on_params +from homeassistant.components.siren.const import SUPPORT_TONES class MockSirenEntity(SirenEntity): @@ -9,9 +12,10 @@ class MockSirenEntity(SirenEntity): _attr_is_on = True - def __init__(self, supported_features: int = 0) -> None: + def __init__(self, supported_features=0, available_tones=None): """Initialize mock siren entity.""" self._attr_supported_features = supported_features + self._attr_available_tones = available_tones async def test_sync_turn_on(hass): @@ -34,3 +38,19 @@ async def test_sync_turn_off(hass): await siren.async_turn_off() assert siren.turn_off.called + + +async def test_no_available_tones(hass): + """Test ValueError when siren advertises tones but has no available_tones.""" + siren = MockSirenEntity(SUPPORT_TONES) + siren.hass = hass + with pytest.raises(ValueError): + process_turn_on_params(siren, {"tone": "test"}) + + +async def test_missing_tones(hass): + """Test ValueError when setting a tone that is missing from available_tones.""" + siren = MockSirenEntity(SUPPORT_TONES, ["a", "b"]) + siren.hass = hass + with pytest.raises(ValueError): + process_turn_on_params(siren, {"tone": "test"})