mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Use common fixtures in philips_js tests (#120988)
This commit is contained in:
parent
e544550380
commit
6fd1f0a34f
@ -7,10 +7,12 @@ from haphilipsjs import PhilipsTV
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.philips_js.const import DOMAIN
|
from homeassistant.components.philips_js.const import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from . import MOCK_CONFIG, MOCK_ENTITY_ID, MOCK_NAME, MOCK_SERIAL_NO, MOCK_SYSTEM
|
from . import MOCK_CONFIG, MOCK_ENTITY_ID, MOCK_NAME, MOCK_SERIAL_NO, MOCK_SYSTEM
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, mock_device_registry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -27,11 +29,6 @@ def mock_setup_entry() -> Generator[AsyncMock]:
|
|||||||
yield mock_setup_entry
|
yield mock_setup_entry
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
async def setup_notification(hass):
|
|
||||||
"""Configure notification system."""
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def mock_tv():
|
def mock_tv():
|
||||||
"""Disable component actual use."""
|
"""Disable component actual use."""
|
||||||
@ -62,7 +59,7 @@ def mock_tv():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def mock_config_entry(hass):
|
async def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
|
||||||
"""Get standard player."""
|
"""Get standard player."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=DOMAIN, data=MOCK_CONFIG, title=MOCK_NAME, unique_id=MOCK_SERIAL_NO
|
domain=DOMAIN, data=MOCK_CONFIG, title=MOCK_NAME, unique_id=MOCK_SERIAL_NO
|
||||||
@ -72,13 +69,7 @@ async def mock_config_entry(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_device_reg(hass):
|
async def mock_entity(hass: HomeAssistant, mock_config_entry: MockConfigEntry) -> str:
|
||||||
"""Get standard device."""
|
|
||||||
return mock_device_registry(hass)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
async def mock_entity(hass, mock_device_reg, mock_config_entry):
|
|
||||||
"""Get standard player."""
|
"""Get standard player."""
|
||||||
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -86,9 +77,13 @@ async def mock_entity(hass, mock_device_reg, mock_config_entry):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_device(hass, mock_device_reg, mock_entity, mock_config_entry):
|
def mock_device(
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
mock_entity: str,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
) -> dr.DeviceEntry:
|
||||||
"""Get standard device."""
|
"""Get standard device."""
|
||||||
return mock_device_reg.async_get_or_create(
|
return device_registry.async_get_or_create(
|
||||||
config_entry_id=mock_config_entry.entry_id,
|
config_entry_id=mock_config_entry.entry_id,
|
||||||
identifiers={(DOMAIN, MOCK_SERIAL_NO)},
|
identifiers={(DOMAIN, MOCK_SERIAL_NO)},
|
||||||
)
|
)
|
||||||
|
@ -9,7 +9,7 @@ from homeassistant.components.philips_js.const import DOMAIN
|
|||||||
from homeassistant.core import HomeAssistant, ServiceCall
|
from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import async_get_device_automations, async_mock_service
|
from tests.common import async_get_device_automations
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True, name="stub_blueprint_populate")
|
@pytest.fixture(autouse=True, name="stub_blueprint_populate")
|
||||||
@ -17,12 +17,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None:
|
|||||||
"""Stub copying the blueprints to the config folder."""
|
"""Stub copying the blueprints to the config folder."""
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def calls(hass: HomeAssistant) -> list[ServiceCall]:
|
|
||||||
"""Track calls to a mock service."""
|
|
||||||
return async_mock_service(hass, "test", "automation")
|
|
||||||
|
|
||||||
|
|
||||||
async def test_get_triggers(hass: HomeAssistant, mock_device) -> None:
|
async def test_get_triggers(hass: HomeAssistant, mock_device) -> None:
|
||||||
"""Test we get the expected triggers."""
|
"""Test we get the expected triggers."""
|
||||||
expected_triggers = [
|
expected_triggers = [
|
||||||
@ -42,7 +36,11 @@ async def test_get_triggers(hass: HomeAssistant, mock_device) -> None:
|
|||||||
|
|
||||||
|
|
||||||
async def test_if_fires_on_turn_on_request(
|
async def test_if_fires_on_turn_on_request(
|
||||||
hass: HomeAssistant, calls: list[ServiceCall], mock_tv, mock_entity, mock_device
|
hass: HomeAssistant,
|
||||||
|
service_calls: list[ServiceCall],
|
||||||
|
mock_tv,
|
||||||
|
mock_entity,
|
||||||
|
mock_device,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for turn_on and turn_off triggers firing."""
|
"""Test for turn_on and turn_off triggers firing."""
|
||||||
|
|
||||||
@ -80,6 +78,10 @@ async def test_if_fires_on_turn_on_request(
|
|||||||
)
|
)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(service_calls) == 2
|
||||||
assert calls[0].data["some"] == mock_device.id
|
assert service_calls[0].domain == "media_player"
|
||||||
assert calls[0].data["id"] == 0
|
assert service_calls[0].service == "turn_on"
|
||||||
|
assert service_calls[1].domain == "test"
|
||||||
|
assert service_calls[1].service == "automation"
|
||||||
|
assert service_calls[1].data["some"] == mock_device.id
|
||||||
|
assert service_calls[1].data["id"] == 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user