Add siren support for available tones provided as a dict (#54198)

* Add siren support for available tones provided as a dict

* remove paranthesis

* hopefully make logic even easier to read

* drop last parenthesis
This commit is contained in:
Raman Gupta 2021-08-09 00:41:51 -04:00 committed by GitHub
parent 557cc792e9
commit 2e903c92c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 8 deletions

View file

@ -48,9 +48,32 @@ async def test_no_available_tones(hass):
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."""
async def test_available_tones_list(hass):
"""Test that valid tones from tone list will get passed in."""
siren = MockSirenEntity(SUPPORT_TONES, ["a", "b"])
siren.hass = hass
assert process_turn_on_params(siren, {"tone": "a"}) == {"tone": "a"}
async def test_available_tones_dict(hass):
"""Test that valid tones from available_tones dict will get passed in."""
siren = MockSirenEntity(SUPPORT_TONES, {1: "a", 2: "b"})
siren.hass = hass
assert process_turn_on_params(siren, {"tone": "a"}) == {"tone": 1}
assert process_turn_on_params(siren, {"tone": 1}) == {"tone": 1}
async def test_missing_tones_list(hass):
"""Test ValueError when setting a tone that is missing from available_tones list."""
siren = MockSirenEntity(SUPPORT_TONES, ["a", "b"])
siren.hass = hass
with pytest.raises(ValueError):
process_turn_on_params(siren, {"tone": "test"})
async def test_missing_tones_dict(hass):
"""Test ValueError when setting a tone that is missing from available_tones dict."""
siren = MockSirenEntity(SUPPORT_TONES, {1: "a", 2: "b"})
siren.hass = hass
with pytest.raises(ValueError):
process_turn_on_params(siren, {"tone": 3})