hass-core/tests/components/hdmi_cec/conftest.py
Pieter Mulder 7cd4be1310
Add tests for the HDMI-CEC integration ()
* Add basic tests to the HDMI-CEC component

* Add tests for the HDMI-CEC switch component

* Add test for watchdog code

* Start adding tests for the HDMI-CEC media player platform

Also some cleanup and code move.

* Add more tests for media_player

And cleanup some switch tests.

* Improve xfail message for features

* Align test pyCEC dependency with main dependency

* Make fixtures snake_case

* Cleanup call asserts

* Cleanup service tests

* fix issues with media player tests

* Cleanup MockHDMIDevice class

* Cleanup watchdog tests

* Add myself as code owner for the HDMI-CEC integration

* Fix async fire time changed time jump

* Fix event api sync context

* Delint tests

* Parametrize watchdog test

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2022-08-08 13:47:05 +02:00

59 lines
1.6 KiB
Python

"""Tests for the HDMI-CEC component."""
from unittest.mock import patch
import pytest
from homeassistant.components.hdmi_cec import DOMAIN
from homeassistant.const import EVENT_HOMEASSISTANT_START
from homeassistant.setup import async_setup_component
@pytest.fixture(name="mock_cec_adapter", autouse=True)
def mock_cec_adapter_fixture():
"""Mock CecAdapter.
Always mocked as it imports the `cec` library which is part of `libcec`.
"""
with patch(
"homeassistant.components.hdmi_cec.CecAdapter", autospec=True
) as mock_cec_adapter:
yield mock_cec_adapter
@pytest.fixture(name="mock_hdmi_network")
def mock_hdmi_network_fixture():
"""Mock HDMINetwork."""
with patch(
"homeassistant.components.hdmi_cec.HDMINetwork", autospec=True
) as mock_hdmi_network:
yield mock_hdmi_network
@pytest.fixture
def create_hdmi_network(hass, mock_hdmi_network):
"""Create an initialized mock hdmi_network."""
async def hdmi_network(config=None):
if not config:
config = {}
await async_setup_component(hass, DOMAIN, {DOMAIN: config})
mock_hdmi_network_instance = mock_hdmi_network.return_value
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
return mock_hdmi_network_instance
return hdmi_network
@pytest.fixture
def create_cec_entity(hass):
"""Create a CecEntity."""
async def cec_entity(hdmi_network, device):
new_device_callback = hdmi_network.set_new_device_callback.call_args.args[0]
new_device_callback(device)
await hass.async_block_till_done()
return cec_entity