2021-02-11 20:37:53 +00:00
|
|
|
"""Standard setup for tests."""
|
2023-03-06 10:31:50 +00:00
|
|
|
from collections.abc import Generator
|
|
|
|
from unittest.mock import AsyncMock, create_autospec, patch
|
2021-02-11 20:37:53 +00:00
|
|
|
|
2021-02-26 17:34:40 +00:00
|
|
|
from haphilipsjs import PhilipsTV
|
2023-01-27 08:09:46 +00:00
|
|
|
import pytest
|
2021-02-11 20:37:53 +00:00
|
|
|
|
|
|
|
from homeassistant.components.philips_js.const import DOMAIN
|
|
|
|
|
|
|
|
from . import MOCK_CONFIG, MOCK_ENTITY_ID, MOCK_NAME, MOCK_SERIAL_NO, MOCK_SYSTEM
|
|
|
|
|
|
|
|
from tests.common import MockConfigEntry, mock_device_registry
|
|
|
|
|
|
|
|
|
2023-03-06 10:31:50 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
|
|
|
"""Disable component setup."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.philips_js.async_setup_entry", return_value=True
|
|
|
|
) as mock_setup_entry, patch(
|
|
|
|
"homeassistant.components.philips_js.async_unload_entry", return_value=True
|
|
|
|
):
|
|
|
|
yield mock_setup_entry
|
|
|
|
|
|
|
|
|
2023-01-27 08:09:46 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
2021-02-11 20:37:53 +00:00
|
|
|
async def setup_notification(hass):
|
|
|
|
"""Configure notification system."""
|
|
|
|
|
|
|
|
|
2023-01-27 08:09:46 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
2021-02-11 20:37:53 +00:00
|
|
|
def mock_tv():
|
|
|
|
"""Disable component actual use."""
|
2021-02-26 17:34:40 +00:00
|
|
|
tv = create_autospec(PhilipsTV)
|
2021-02-11 20:37:53 +00:00
|
|
|
tv.sources = {}
|
|
|
|
tv.channels = {}
|
2021-02-26 17:34:40 +00:00
|
|
|
tv.application = None
|
|
|
|
tv.applications = {}
|
2021-02-11 20:37:53 +00:00
|
|
|
tv.system = MOCK_SYSTEM
|
2021-02-26 17:34:40 +00:00
|
|
|
tv.api_version = 1
|
|
|
|
tv.api_version_detected = None
|
|
|
|
tv.on = True
|
|
|
|
tv.notify_change_supported = False
|
|
|
|
tv.pairing_type = None
|
|
|
|
tv.powerstate = None
|
2022-11-22 10:35:18 +00:00
|
|
|
tv.source_id = None
|
|
|
|
tv.ambilight_current_configuration = None
|
|
|
|
tv.ambilight_styles = {}
|
|
|
|
tv.ambilight_cached = {}
|
2021-02-11 20:37:53 +00:00
|
|
|
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.philips_js.config_flow.PhilipsTV", return_value=tv
|
|
|
|
), patch("homeassistant.components.philips_js.PhilipsTV", return_value=tv):
|
|
|
|
yield tv
|
|
|
|
|
|
|
|
|
2023-01-27 08:09:46 +00:00
|
|
|
@pytest.fixture
|
2021-02-11 20:37:53 +00:00
|
|
|
async def mock_config_entry(hass):
|
|
|
|
"""Get standard player."""
|
2022-01-04 15:14:44 +00:00
|
|
|
config_entry = MockConfigEntry(
|
2022-11-22 10:35:18 +00:00
|
|
|
domain=DOMAIN, data=MOCK_CONFIG, title=MOCK_NAME, unique_id=MOCK_SERIAL_NO
|
2022-01-04 15:14:44 +00:00
|
|
|
)
|
2021-02-11 20:37:53 +00:00
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
return config_entry
|
|
|
|
|
|
|
|
|
2023-01-27 08:09:46 +00:00
|
|
|
@pytest.fixture
|
2021-02-11 20:37:53 +00:00
|
|
|
def mock_device_reg(hass):
|
|
|
|
"""Get standard device."""
|
|
|
|
return mock_device_registry(hass)
|
|
|
|
|
|
|
|
|
2023-01-27 08:09:46 +00:00
|
|
|
@pytest.fixture
|
2021-02-11 20:37:53 +00:00
|
|
|
async def mock_entity(hass, mock_device_reg, mock_config_entry):
|
|
|
|
"""Get standard player."""
|
|
|
|
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
2021-02-12 01:35:29 +00:00
|
|
|
return MOCK_ENTITY_ID
|
2021-02-11 20:37:53 +00:00
|
|
|
|
|
|
|
|
2023-01-27 08:09:46 +00:00
|
|
|
@pytest.fixture
|
2021-02-11 20:37:53 +00:00
|
|
|
def mock_device(hass, mock_device_reg, mock_entity, mock_config_entry):
|
|
|
|
"""Get standard device."""
|
|
|
|
return mock_device_reg.async_get_or_create(
|
|
|
|
config_entry_id=mock_config_entry.entry_id,
|
|
|
|
identifiers={(DOMAIN, MOCK_SERIAL_NO)},
|
|
|
|
)
|