Add available tones property to siren entity description (#70216)
* Fix siren entity description and available tones property * Add test * Fix bug * Add coverage
This commit is contained in:
parent
5e50a8abd5
commit
c390834ae4
2 changed files with 38 additions and 6 deletions
|
@ -3,7 +3,11 @@ from unittest.mock import MagicMock
|
|||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.siren import SirenEntity, process_turn_on_params
|
||||
from homeassistant.components.siren import (
|
||||
SirenEntity,
|
||||
SirenEntityDescription,
|
||||
process_turn_on_params,
|
||||
)
|
||||
from homeassistant.components.siren.const import SirenEntityFeature
|
||||
|
||||
|
||||
|
@ -12,10 +16,20 @@ class MockSirenEntity(SirenEntity):
|
|||
|
||||
_attr_is_on = True
|
||||
|
||||
def __init__(self, supported_features=0, available_tones=None):
|
||||
def __init__(
|
||||
self,
|
||||
supported_features=0,
|
||||
available_tones_as_attr=None,
|
||||
available_tones_in_desc=None,
|
||||
):
|
||||
"""Initialize mock siren entity."""
|
||||
self._attr_supported_features = supported_features
|
||||
self._attr_available_tones = available_tones
|
||||
if available_tones_as_attr is not None:
|
||||
self._attr_available_tones = available_tones_as_attr
|
||||
elif available_tones_in_desc is not None:
|
||||
self.entity_description = SirenEntityDescription(
|
||||
"mock", available_tones=available_tones_in_desc
|
||||
)
|
||||
|
||||
|
||||
async def test_sync_turn_on(hass):
|
||||
|
@ -50,11 +64,23 @@ async def test_no_available_tones(hass):
|
|||
|
||||
async def test_available_tones_list(hass):
|
||||
"""Test that valid tones from tone list will get passed in."""
|
||||
siren = MockSirenEntity(SirenEntityFeature.TONES, ["a", "b"])
|
||||
siren = MockSirenEntity(
|
||||
SirenEntityFeature.TONES, available_tones_as_attr=["a", "b"]
|
||||
)
|
||||
siren.hass = hass
|
||||
assert process_turn_on_params(siren, {"tone": "a"}) == {"tone": "a"}
|
||||
|
||||
|
||||
async def test_available_tones(hass):
|
||||
"""Test different available tones scenarios."""
|
||||
siren = MockSirenEntity(
|
||||
SirenEntityFeature.TONES, available_tones_in_desc=["a", "b"]
|
||||
)
|
||||
assert siren.available_tones == ["a", "b"]
|
||||
siren = MockSirenEntity(SirenEntityFeature.TONES)
|
||||
assert siren.available_tones is None
|
||||
|
||||
|
||||
async def test_available_tones_dict(hass):
|
||||
"""Test that valid tones from available_tones dict will get passed in."""
|
||||
siren = MockSirenEntity(SirenEntityFeature.TONES, {1: "a", 2: "b"})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue