Files
core/tests/components/bluesound/test_button.py
Louis Christ 4cecb6c851 Replace custom actions for sleep timer with buttons in bluesound integration (#133604)
* Use entity services

* Add buttons for sleep timer

* Fix merge

* Replace hass.data with runtime_data from config_entries

* Disable button by default

* Remove duplicate dispatchers

* Add tests for buttons

* Fix merge commit

* Fix merge commit

* Update deprecation version

* Remove update_before_add

* Use entity_registry_enabled_by_default

* Use EnitiyDescriptions for buttons

* Update version for deprecate

* Use tranlation_key; Move default disable to EntityDescription

* Fix merge commit

* Fix callback type; fix breaks version

* Use normal issue

* Apply suggestions from code review

---------

Co-authored-by: Franck Nijhof <git@frenck.dev>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2025-05-09 16:15:52 +02:00

48 lines
1.3 KiB
Python

"""Test for bluesound buttons."""
from unittest.mock import call
import pytest
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant
from .conftest import PlayerMocks
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_set_sleep_timer(
hass: HomeAssistant,
player_mocks: PlayerMocks,
setup_config_entry: None,
) -> None:
"""Test the media player volume set."""
await hass.services.async_call(
BUTTON_DOMAIN,
SERVICE_PRESS,
{ATTR_ENTITY_ID: "button.player_name1111_set_sleep_timer"},
blocking=True,
)
player_mocks.player_data.player.sleep_timer.assert_called_once()
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_clear_sleep_timer(
hass: HomeAssistant,
player_mocks: PlayerMocks,
setup_config_entry: None,
) -> None:
"""Test the media player volume set."""
player_mocks.player_data.player.sleep_timer.side_effect = [15, 30, 45, 60, 90, 0]
await hass.services.async_call(
BUTTON_DOMAIN,
SERVICE_PRESS,
{ATTR_ENTITY_ID: "button.player_name1111_clear_sleep_timer"},
blocking=True,
)
player_mocks.player_data.player.sleep_timer.assert_has_calls([call()] * 6)