mirror of
https://github.com/home-assistant/core.git
synced 2026-09-24 23:41:48 -05:00
Mark entities as unavailable in Onkyo (#159521)
This commit is contained in:
@@ -76,11 +76,20 @@ async def test_reconnect(
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
manager = mock_config_entry.runtime_data.manager
|
||||
assert manager.connected is True
|
||||
|
||||
async def disconnect_assert() -> None:
|
||||
assert manager.connected is False
|
||||
|
||||
manager.callbacks.disconnect.append(disconnect_assert)
|
||||
|
||||
mock_connect.reset_mock()
|
||||
|
||||
assert mock_connect.call_count == 0
|
||||
|
||||
read_queue.put_nowait(None) # Simulate a disconnect
|
||||
# Simulate a disconnect
|
||||
read_queue.put_nowait(None)
|
||||
await asyncio.sleep(0)
|
||||
|
||||
assert mock_connect.call_count == 1
|
||||
|
||||
@@ -32,6 +32,7 @@ from homeassistant.const import (
|
||||
SERVICE_VOLUME_MUTE,
|
||||
SERVICE_VOLUME_SET,
|
||||
SERVICE_VOLUME_UP,
|
||||
STATE_UNAVAILABLE,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -81,6 +82,30 @@ async def test_entities(
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
async def test_availability(hass: HomeAssistant, read_queue: asyncio.Queue) -> None:
|
||||
"""Test entity availability on disconnect and reconnect."""
|
||||
assert (state := hass.states.get(ENTITY_ID)) is not None
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
# Simulate a disconnect
|
||||
read_queue.put_nowait(None)
|
||||
await asyncio.sleep(0)
|
||||
|
||||
assert (state := hass.states.get(ENTITY_ID)) is not None
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
# Simulate first status update after reconnect
|
||||
read_queue.put_nowait(
|
||||
status.Power(
|
||||
Code.from_kind_zone(Kind.POWER, Zone.MAIN), None, status.Power.Param.ON
|
||||
)
|
||||
)
|
||||
await asyncio.sleep(0)
|
||||
|
||||
assert (state := hass.states.get(ENTITY_ID)) is not None
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("action", "action_data", "message"),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user