mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Fix LG webOS TV init test coverage (#135194)
This commit is contained in:
parent
31719bc84c
commit
07482de4ab
@ -129,8 +129,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if not entry.update_listeners:
|
entry.async_on_unload(entry.add_update_listener(async_update_options))
|
||||||
entry.async_on_unload(entry.add_update_listener(async_update_options))
|
|
||||||
|
|
||||||
async def async_on_stop(_event: Event) -> None:
|
async def async_on_stop(_event: Event) -> None:
|
||||||
"""Unregister callbacks and disconnect."""
|
"""Unregister callbacks and disconnect."""
|
||||||
|
@ -5,12 +5,14 @@ from unittest.mock import Mock
|
|||||||
from aiowebostv import WebOsTvPairError
|
from aiowebostv import WebOsTvPairError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.webostv.const import DOMAIN
|
from homeassistant.components.media_player import ATTR_INPUT_SOURCE_LIST
|
||||||
|
from homeassistant.components.webostv.const import CONF_SOURCES, DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||||
from homeassistant.const import CONF_CLIENT_SECRET
|
from homeassistant.const import CONF_CLIENT_SECRET, EVENT_HOMEASSISTANT_STOP
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import setup_webostv
|
from . import setup_webostv
|
||||||
|
from .const import ENTITY_ID
|
||||||
|
|
||||||
|
|
||||||
async def test_reauth_setup_entry(
|
async def test_reauth_setup_entry(
|
||||||
@ -44,3 +46,39 @@ async def test_key_update_setup_entry(
|
|||||||
|
|
||||||
assert entry.state is ConfigEntryState.LOADED
|
assert entry.state is ConfigEntryState.LOADED
|
||||||
assert entry.data[CONF_CLIENT_SECRET] == "new_key"
|
assert entry.data[CONF_CLIENT_SECRET] == "new_key"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_update_options(hass: HomeAssistant, client) -> None:
|
||||||
|
"""Test update options triggers reload."""
|
||||||
|
config_entry = await setup_webostv(hass)
|
||||||
|
|
||||||
|
assert config_entry.state is ConfigEntryState.LOADED
|
||||||
|
assert config_entry.update_listeners is not None
|
||||||
|
sources = hass.states.get(ENTITY_ID).attributes[ATTR_INPUT_SOURCE_LIST]
|
||||||
|
assert sources == ["Input01", "Input02", "Live TV"]
|
||||||
|
|
||||||
|
# remove Input01 and reload
|
||||||
|
new_options = config_entry.options.copy()
|
||||||
|
new_options[CONF_SOURCES] = ["Input02", "Live TV"]
|
||||||
|
hass.config_entries.async_update_entry(config_entry, options=new_options)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert config_entry.state is ConfigEntryState.LOADED
|
||||||
|
sources = hass.states.get(ENTITY_ID).attributes[ATTR_INPUT_SOURCE_LIST]
|
||||||
|
assert sources == ["Input02", "Live TV"]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_disconnect_on_stop(hass: HomeAssistant, client) -> None:
|
||||||
|
"""Test we disconnect the client and clear callbacks when Home Assistants stops."""
|
||||||
|
config_entry = await setup_webostv(hass)
|
||||||
|
|
||||||
|
assert client.disconnect.call_count == 0
|
||||||
|
assert client.clear_state_update_callbacks.call_count == 0
|
||||||
|
assert config_entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert client.disconnect.call_count == 1
|
||||||
|
assert client.clear_state_update_callbacks.call_count == 1
|
||||||
|
assert config_entry.state is ConfigEntryState.LOADED
|
||||||
|
Loading…
x
Reference in New Issue
Block a user