* add sonos_alarm * bug fix for _update_device * fix pylint and black and co * small bug fix in speaker.available_alarms * cleanup and add _LOGGER.debug statements, fix pylint * fix pylint * _alarm_id to alarm_id * fixed rare bug due to raceconditions * Part 2 of raceconditionfix * address review suggestions * readd check for not yet subscribed * - platforms_ready fix - add alarmClock to pytest mock * fixture for ListAlarms * cleanup mock and match UUID for test * add simple tests for sonos_alarm * extend test for attributes * typhint fix * typo * use get_alarms() directly * refactor available_alarms * fix attributes * some cleanup * change logic of fetch_alarms_for_speaker and rename to update_alarms_for_speaker * update_alarms_for_speaker is now a method * Update homeassistant/components/sonos/switch.py Co-authored-by: jjlawren <jjlawren@users.noreply.github.com> * Update homeassistant/components/sonos/speaker.py Co-authored-by: jjlawren <jjlawren@users.noreply.github.com> Co-authored-by: jjlawren <jjlawren@users.noreply.github.com>
47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
"""Tests for the Sonos Alarm switch platform."""
|
|
from homeassistant.components.sonos import DOMAIN
|
|
from homeassistant.components.sonos.switch import (
|
|
ATTR_DURATION,
|
|
ATTR_ID,
|
|
ATTR_INCLUDE_LINKED_ZONES,
|
|
ATTR_PLAY_MODE,
|
|
ATTR_RECURRENCE,
|
|
ATTR_VOLUME,
|
|
)
|
|
from homeassistant.const import ATTR_TIME, STATE_ON
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
async def setup_platform(hass, config_entry, config):
|
|
"""Set up the media player 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):
|
|
"""Test sonos device with alarm registered in the device registry."""
|
|
await setup_platform(hass, config_entry, config)
|
|
|
|
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
|
|
|
assert "media_player.zone_a" in entity_registry.entities
|
|
assert "switch.sonos_alarm_14" in entity_registry.entities
|
|
|
|
|
|
async def test_alarm_attributes(hass, config_entry, config, soco):
|
|
"""Test for correct sonos alarm state."""
|
|
await setup_platform(hass, config_entry, config)
|
|
|
|
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
|
|
|
alarm = entity_registry.entities["switch.sonos_alarm_14"]
|
|
alarm_state = hass.states.get(alarm.entity_id)
|
|
assert alarm_state.state == STATE_ON
|
|
assert alarm_state.attributes.get(ATTR_TIME) == "07:00:00"
|
|
assert alarm_state.attributes.get(ATTR_ID) == "14"
|
|
assert alarm_state.attributes.get(ATTR_DURATION) == "02:00:00"
|
|
assert alarm_state.attributes.get(ATTR_RECURRENCE) == "DAILY"
|
|
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)
|