Add tests for sonos switch platform (#51142)
* add tests * refactor async_added_to_hass * fix tests and race condition * use async_get * typo
This commit is contained in:
parent
7dff4d6ad7
commit
f7f8672eea
4 changed files with 84 additions and 19 deletions
|
@ -9,17 +9,18 @@ from homeassistant.components.sonos.switch import (
|
|||
ATTR_VOLUME,
|
||||
)
|
||||
from homeassistant.const import ATTR_TIME, STATE_ON
|
||||
from homeassistant.helpers.entity_registry import async_get as async_get_entity_registry
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
async def setup_platform(hass, config_entry, config):
|
||||
"""Set up the media player platform for testing."""
|
||||
"""Set up the switch platform for testing."""
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def test_entity_registry(hass, config_entry, config, soco):
|
||||
async def test_entity_registry(hass, config_entry, config):
|
||||
"""Test sonos device with alarm registered in the device registry."""
|
||||
await setup_platform(hass, config_entry, config)
|
||||
|
||||
|
@ -29,7 +30,7 @@ async def test_entity_registry(hass, config_entry, config, soco):
|
|||
assert "switch.sonos_alarm_14" in entity_registry.entities
|
||||
|
||||
|
||||
async def test_alarm_attributes(hass, config_entry, config, soco):
|
||||
async def test_alarm_attributes(hass, config_entry, config):
|
||||
"""Test for correct sonos alarm state."""
|
||||
await setup_platform(hass, config_entry, config)
|
||||
|
||||
|
@ -45,3 +46,31 @@ async def test_alarm_attributes(hass, config_entry, config, soco):
|
|||
assert alarm_state.attributes.get(ATTR_VOLUME) == 0.25
|
||||
assert alarm_state.attributes.get(ATTR_PLAY_MODE) == "SHUFFLE_NOREPEAT"
|
||||
assert not alarm_state.attributes.get(ATTR_INCLUDE_LINKED_ZONES)
|
||||
|
||||
|
||||
async def test_alarm_create_delete(
|
||||
hass, config_entry, config, soco, alarm_clock, alarm_clock_extended, alarm_event
|
||||
):
|
||||
"""Test for correct creation and deletion of alarms during runtime."""
|
||||
soco.alarmClock = alarm_clock_extended
|
||||
|
||||
await setup_platform(hass, config_entry, config)
|
||||
|
||||
subscription = alarm_clock_extended.subscribe.return_value
|
||||
sub_callback = subscription.callback
|
||||
|
||||
sub_callback(event=alarm_event)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_registry = async_get_entity_registry(hass)
|
||||
|
||||
assert "switch.sonos_alarm_14" in entity_registry.entities
|
||||
assert "switch.sonos_alarm_15" in entity_registry.entities
|
||||
|
||||
alarm_clock_extended.ListAlarms.return_value = alarm_clock.ListAlarms.return_value
|
||||
|
||||
sub_callback(event=alarm_event)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert "switch.sonos_alarm_14" in entity_registry.entities
|
||||
assert "switch.sonos_alarm_15" not in entity_registry.entities
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue