From 1c4d7e95881a342c3f22d684ef20ab4cb89ddd9f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 25 Nov 2023 02:20:56 -0600 Subject: [PATCH] Improve test coverage for ESPHome deep sleep entities (#104476) --- tests/components/esphome/test_entity.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/components/esphome/test_entity.py b/tests/components/esphome/test_entity.py index fdc57b2dc24..9a5cb441f28 100644 --- a/tests/components/esphome/test_entity.py +++ b/tests/components/esphome/test_entity.py @@ -13,7 +13,13 @@ from aioesphomeapi import ( UserService, ) -from homeassistant.const import ATTR_RESTORED, STATE_OFF, STATE_ON, STATE_UNAVAILABLE +from homeassistant.const import ( + ATTR_RESTORED, + EVENT_HOMEASSISTANT_STOP, + STATE_OFF, + STATE_ON, + STATE_UNAVAILABLE, +) from homeassistant.core import HomeAssistant from .conftest import MockESPHomeDevice @@ -231,6 +237,19 @@ async def test_deep_sleep_device( assert state is not None assert state.state == STATE_UNAVAILABLE + await mock_device.mock_connect() + await hass.async_block_till_done() + state = hass.states.get("binary_sensor.test_mybinary_sensor") + assert state is not None + assert state.state == STATE_ON + hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP) + await hass.async_block_till_done() + # Verify we do not dispatch any more state updates or + # availability updates after the stop event is fired + state = hass.states.get("binary_sensor.test_mybinary_sensor") + assert state is not None + assert state.state == STATE_ON + async def test_esphome_device_without_friendly_name( hass: HomeAssistant,