mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Add missing test coverage for sirens (#53014)
This commit is contained in:
parent
7e16d38fc8
commit
4d711898c7
@ -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"})
|
||||
|
Loading…
x
Reference in New Issue
Block a user