mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Setup config entry even if vizio device is unreachable (#46864)
This commit is contained in:
parent
868a536d81
commit
783e0f9a14
@ -25,7 +25,6 @@ from homeassistant.const import (
|
|||||||
STATE_ON,
|
STATE_ON,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
|
||||||
from homeassistant.helpers import entity_platform
|
from homeassistant.helpers import entity_platform
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
@ -115,10 +114,6 @@ async def async_setup_entry(
|
|||||||
timeout=DEFAULT_TIMEOUT,
|
timeout=DEFAULT_TIMEOUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not await device.can_connect_with_auth_check():
|
|
||||||
_LOGGER.warning("Failed to connect to %s", host)
|
|
||||||
raise PlatformNotReady
|
|
||||||
|
|
||||||
apps_coordinator = hass.data[DOMAIN].get(CONF_APPS)
|
apps_coordinator = hass.data[DOMAIN].get(CONF_APPS)
|
||||||
|
|
||||||
entity = VizioDevice(config_entry, device, name, device_class, apps_coordinator)
|
entity = VizioDevice(config_entry, device, name, device_class, apps_coordinator)
|
||||||
@ -183,12 +178,6 @@ class VizioDevice(MediaPlayerEntity):
|
|||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Retrieve latest state of the device."""
|
"""Retrieve latest state of the device."""
|
||||||
if not self._model:
|
|
||||||
self._model = await self._device.get_model_name(log_api_exception=False)
|
|
||||||
|
|
||||||
if not self._sw_version:
|
|
||||||
self._sw_version = await self._device.get_version(log_api_exception=False)
|
|
||||||
|
|
||||||
is_on = await self._device.get_power_state(log_api_exception=False)
|
is_on = await self._device.get_power_state(log_api_exception=False)
|
||||||
|
|
||||||
if is_on is None:
|
if is_on is None:
|
||||||
@ -205,6 +194,12 @@ class VizioDevice(MediaPlayerEntity):
|
|||||||
)
|
)
|
||||||
self._available = True
|
self._available = True
|
||||||
|
|
||||||
|
if not self._model:
|
||||||
|
self._model = await self._device.get_model_name(log_api_exception=False)
|
||||||
|
|
||||||
|
if not self._sw_version:
|
||||||
|
self._sw_version = await self._device.get_version(log_api_exception=False)
|
||||||
|
|
||||||
if not is_on:
|
if not is_on:
|
||||||
self._state = STATE_OFF
|
self._state = STATE_OFF
|
||||||
self._volume_level = None
|
self._volume_level = None
|
||||||
|
@ -157,6 +157,9 @@ def vizio_cant_connect_fixture():
|
|||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.vizio.config_flow.VizioAsync.validate_ha_config",
|
"homeassistant.components.vizio.config_flow.VizioAsync.validate_ha_config",
|
||||||
AsyncMock(return_value=False),
|
AsyncMock(return_value=False),
|
||||||
|
), patch(
|
||||||
|
"homeassistant.components.vizio.media_player.VizioAsync.get_power_state",
|
||||||
|
return_value=None,
|
||||||
):
|
):
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
@ -239,17 +239,6 @@ def _assert_source_list_with_apps(
|
|||||||
assert attr["source_list"] == list_to_test
|
assert attr["source_list"] == list_to_test
|
||||||
|
|
||||||
|
|
||||||
async def _test_setup_failure(hass: HomeAssistantType, config: str) -> None:
|
|
||||||
"""Test generic Vizio entity setup failure."""
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.vizio.media_player.VizioAsync.can_connect_with_auth_check",
|
|
||||||
return_value=False,
|
|
||||||
):
|
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data=config, unique_id=UNIQUE_ID)
|
|
||||||
await _add_config_entry_to_hass(hass, config_entry)
|
|
||||||
assert len(hass.states.async_entity_ids(MP_DOMAIN)) == 0
|
|
||||||
|
|
||||||
|
|
||||||
async def _test_service(
|
async def _test_service(
|
||||||
hass: HomeAssistantType,
|
hass: HomeAssistantType,
|
||||||
domain: str,
|
domain: str,
|
||||||
@ -334,18 +323,28 @@ async def test_init_tv_unavailable(
|
|||||||
await _test_setup_tv(hass, None)
|
await _test_setup_tv(hass, None)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_failure_speaker(
|
async def test_setup_unavailable_speaker(
|
||||||
hass: HomeAssistantType, vizio_connect: pytest.fixture
|
hass: HomeAssistantType, vizio_cant_connect: pytest.fixture
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test speaker entity setup failure."""
|
"""Test speaker entity sets up as unavailable."""
|
||||||
await _test_setup_failure(hass, MOCK_SPEAKER_CONFIG)
|
config_entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN, data=MOCK_SPEAKER_CONFIG, unique_id=UNIQUE_ID
|
||||||
|
)
|
||||||
|
await _add_config_entry_to_hass(hass, config_entry)
|
||||||
|
assert len(hass.states.async_entity_ids(MP_DOMAIN)) == 1
|
||||||
|
assert hass.states.get("media_player.vizio").state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_failure_tv(
|
async def test_setup_unavailable_tv(
|
||||||
hass: HomeAssistantType, vizio_connect: pytest.fixture
|
hass: HomeAssistantType, vizio_cant_connect: pytest.fixture
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test TV entity setup failure."""
|
"""Test TV entity sets up as unavailable."""
|
||||||
await _test_setup_failure(hass, MOCK_USER_VALID_TV_CONFIG)
|
config_entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN, data=MOCK_USER_VALID_TV_CONFIG, unique_id=UNIQUE_ID
|
||||||
|
)
|
||||||
|
await _add_config_entry_to_hass(hass, config_entry)
|
||||||
|
assert len(hass.states.async_entity_ids(MP_DOMAIN)) == 1
|
||||||
|
assert hass.states.get("media_player.vizio").state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
async def test_services(
|
async def test_services(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user