Optimize directv client initialization (#32706)
* Optimize directv client initialization. * Update config_flow.py * Update media_player.py * Update media_player.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update test_media_player.py * Update __init__.py * Update media_player.py * Update test_media_player.py * Update media_player.py * Update test_media_player.py * Update config_flow.py * Update test_config_flow.py * Update test_config_flow.py * Update test_config_flow.py * Update test_config_flow.py * Update test_config_flow.py * Update test_config_flow.py * Update __init__.py * Update test_config_flow.py * Update test_config_flow.py * Update test_media_player.py * Update test_media_player.py * Update __init__.py * Update __init__.py * Update __init__.py
This commit is contained in:
parent
86c4fa0fc5
commit
1b622925a1
6 changed files with 50 additions and 108 deletions
|
@ -54,9 +54,7 @@ from homeassistant.util import dt as dt_util
|
|||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
from tests.components.directv import (
|
||||
CLIENT_ADDRESS,
|
||||
DOMAIN,
|
||||
HOST,
|
||||
MOCK_GET_LOCATIONS_MULTIPLE,
|
||||
RECORDING,
|
||||
MockDirectvClass,
|
||||
|
@ -70,15 +68,6 @@ MAIN_ENTITY_ID = f"{MP_DOMAIN}.main_dvr"
|
|||
# pylint: disable=redefined-outer-name
|
||||
|
||||
|
||||
@fixture
|
||||
def client_dtv() -> MockDirectvClass:
|
||||
"""Fixture for a client device."""
|
||||
mocked_dtv = MockDirectvClass(HOST, clientAddr=CLIENT_ADDRESS)
|
||||
mocked_dtv.attributes = RECORDING
|
||||
mocked_dtv._standby = False # pylint: disable=protected-access
|
||||
return mocked_dtv
|
||||
|
||||
|
||||
@fixture
|
||||
def mock_now() -> datetime:
|
||||
"""Fixture for dtutil.now."""
|
||||
|
@ -93,34 +82,19 @@ async def setup_directv(hass: HomeAssistantType) -> MockConfigEntry:
|
|||
return await setup_integration(hass)
|
||||
|
||||
|
||||
async def setup_directv_with_instance_error(hass: HomeAssistantType) -> MockConfigEntry:
|
||||
async def setup_directv_with_locations(hass: HomeAssistantType) -> MockConfigEntry:
|
||||
"""Set up mock DirecTV integration."""
|
||||
with patch(
|
||||
"homeassistant.components.directv.DIRECTV", new=MockDirectvClass,
|
||||
), patch(
|
||||
"homeassistant.components.directv.DIRECTV.get_locations",
|
||||
"tests.components.directv.test_media_player.MockDirectvClass.get_locations",
|
||||
return_value=MOCK_GET_LOCATIONS_MULTIPLE,
|
||||
), patch(
|
||||
"homeassistant.components.directv.media_player.get_dtv_instance",
|
||||
return_value=None,
|
||||
):
|
||||
return await setup_integration(hass)
|
||||
|
||||
|
||||
async def setup_directv_with_locations(
|
||||
hass: HomeAssistantType, client_dtv: MockDirectvClass,
|
||||
) -> MockConfigEntry:
|
||||
"""Set up mock DirecTV integration."""
|
||||
with patch(
|
||||
"homeassistant.components.directv.DIRECTV", new=MockDirectvClass,
|
||||
), patch(
|
||||
"homeassistant.components.directv.DIRECTV.get_locations",
|
||||
return_value=MOCK_GET_LOCATIONS_MULTIPLE,
|
||||
), patch(
|
||||
"homeassistant.components.directv.media_player.get_dtv_instance",
|
||||
return_value=client_dtv,
|
||||
):
|
||||
return await setup_integration(hass)
|
||||
with patch(
|
||||
"homeassistant.components.directv.DIRECTV", new=MockDirectvClass,
|
||||
), patch(
|
||||
"homeassistant.components.directv.media_player.DIRECTV",
|
||||
new=MockDirectvClass,
|
||||
):
|
||||
return await setup_integration(hass)
|
||||
|
||||
|
||||
async def async_turn_on(
|
||||
|
@ -204,27 +178,17 @@ async def test_setup(hass: HomeAssistantType) -> None:
|
|||
assert hass.states.get(MAIN_ENTITY_ID)
|
||||
|
||||
|
||||
async def test_setup_with_multiple_locations(
|
||||
hass: HomeAssistantType, client_dtv: MockDirectvClass
|
||||
) -> None:
|
||||
async def test_setup_with_multiple_locations(hass: HomeAssistantType) -> None:
|
||||
"""Test setup with basic config with client location."""
|
||||
await setup_directv_with_locations(hass, client_dtv)
|
||||
await setup_directv_with_locations(hass)
|
||||
|
||||
assert hass.states.get(MAIN_ENTITY_ID)
|
||||
assert hass.states.get(CLIENT_ENTITY_ID)
|
||||
|
||||
|
||||
async def test_setup_with_instance_error(hass: HomeAssistantType) -> None:
|
||||
"""Test setup with basic config with client location that results in instance error."""
|
||||
await setup_directv_with_instance_error(hass)
|
||||
|
||||
assert hass.states.get(MAIN_ENTITY_ID)
|
||||
assert hass.states.async_entity_ids(MP_DOMAIN) == [MAIN_ENTITY_ID]
|
||||
|
||||
|
||||
async def test_unique_id(hass: HomeAssistantType, client_dtv: MockDirectvClass) -> None:
|
||||
async def test_unique_id(hass: HomeAssistantType) -> None:
|
||||
"""Test unique id."""
|
||||
await setup_directv_with_locations(hass, client_dtv)
|
||||
await setup_directv_with_locations(hass)
|
||||
|
||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
|
@ -235,11 +199,9 @@ async def test_unique_id(hass: HomeAssistantType, client_dtv: MockDirectvClass)
|
|||
assert client.unique_id == "2CA17D1CD30X"
|
||||
|
||||
|
||||
async def test_supported_features(
|
||||
hass: HomeAssistantType, client_dtv: MockDirectvClass
|
||||
) -> None:
|
||||
async def test_supported_features(hass: HomeAssistantType) -> None:
|
||||
"""Test supported features."""
|
||||
await setup_directv_with_locations(hass, client_dtv)
|
||||
await setup_directv_with_locations(hass)
|
||||
|
||||
# Features supported for main DVR
|
||||
state = hass.states.get(MAIN_ENTITY_ID)
|
||||
|
@ -269,10 +231,10 @@ async def test_supported_features(
|
|||
|
||||
|
||||
async def test_check_attributes(
|
||||
hass: HomeAssistantType, mock_now: dt_util.dt.datetime, client_dtv: MockDirectvClass
|
||||
hass: HomeAssistantType, mock_now: dt_util.dt.datetime
|
||||
) -> None:
|
||||
"""Test attributes."""
|
||||
await setup_directv_with_locations(hass, client_dtv)
|
||||
await setup_directv_with_locations(hass)
|
||||
|
||||
next_update = mock_now + timedelta(minutes=5)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=next_update):
|
||||
|
@ -321,10 +283,10 @@ async def test_check_attributes(
|
|||
|
||||
|
||||
async def test_main_services(
|
||||
hass: HomeAssistantType, mock_now: dt_util.dt.datetime, client_dtv: MockDirectvClass
|
||||
hass: HomeAssistantType, mock_now: dt_util.dt.datetime
|
||||
) -> None:
|
||||
"""Test the different services."""
|
||||
await setup_directv_with_locations(hass, client_dtv)
|
||||
await setup_directv(hass)
|
||||
|
||||
next_update = mock_now + timedelta(minutes=5)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=next_update):
|
||||
|
@ -373,10 +335,10 @@ async def test_main_services(
|
|||
|
||||
|
||||
async def test_available(
|
||||
hass: HomeAssistantType, mock_now: dt_util.dt.datetime, client_dtv: MockDirectvClass
|
||||
hass: HomeAssistantType, mock_now: dt_util.dt.datetime
|
||||
) -> None:
|
||||
"""Test available status."""
|
||||
entry = await setup_directv_with_locations(hass, client_dtv)
|
||||
entry = await setup_directv(hass)
|
||||
|
||||
next_update = mock_now + timedelta(minutes=5)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=next_update):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue