mirror of
https://github.com/home-assistant/core.git
synced 2026-09-27 18:08:37 -04:00
Fix yeelight connection when bulb stops responding to SSDP (#57138)
This commit is contained in:
@@ -9,8 +9,6 @@ from homeassistant.components.yeelight import (
|
||||
CONF_MODEL,
|
||||
CONF_NIGHTLIGHT_SWITCH,
|
||||
CONF_NIGHTLIGHT_SWITCH_TYPE,
|
||||
DATA_CONFIG_ENTRIES,
|
||||
DATA_DEVICE,
|
||||
DOMAIN,
|
||||
NIGHTLIGHT_SWITCH_TYPE_LIGHT,
|
||||
STATE_CHANGE_TIME,
|
||||
@@ -57,41 +55,41 @@ async def test_ip_changes_fallback_discovery(hass: HomeAssistant):
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
mocked_bulb = _mocked_bulb(True)
|
||||
mocked_bulb.bulb_type = BulbType.WhiteTempMood
|
||||
mocked_bulb.async_listen = AsyncMock(side_effect=[BulbException, None, None, None])
|
||||
mocked_fail_bulb = _mocked_bulb(cannot_connect=True)
|
||||
mocked_fail_bulb.bulb_type = BulbType.WhiteTempMood
|
||||
with patch(
|
||||
f"{MODULE}.AsyncBulb", return_value=mocked_fail_bulb
|
||||
), _patch_discovery():
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=2))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# The discovery should update the ip address
|
||||
assert config_entry.data[CONF_HOST] == IP_ADDRESS
|
||||
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
mocked_bulb = _mocked_bulb()
|
||||
|
||||
with patch(f"{MODULE}.AsyncBulb", return_value=mocked_bulb), _patch_discovery():
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=10))
|
||||
await hass.async_block_till_done()
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
binary_sensor_entity_id = ENTITY_BINARY_SENSOR_TEMPLATE.format(
|
||||
f"yeelight_color_{SHORT_ID}"
|
||||
)
|
||||
|
||||
type(mocked_bulb).async_get_properties = AsyncMock(None)
|
||||
|
||||
await hass.data[DOMAIN][DATA_CONFIG_ENTRIES][config_entry.entry_id][
|
||||
DATA_DEVICE
|
||||
].async_update()
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_registry = er.async_get(hass)
|
||||
assert entity_registry.async_get(binary_sensor_entity_id) is not None
|
||||
|
||||
with patch(f"{MODULE}.AsyncBulb", return_value=mocked_bulb), _patch_discovery():
|
||||
# The discovery should update the ip address
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=2))
|
||||
await hass.async_block_till_done()
|
||||
assert config_entry.data[CONF_HOST] == IP_ADDRESS
|
||||
|
||||
# Make sure we can still reload with the new ip right after we change it
|
||||
with patch(f"{MODULE}.AsyncBulb", return_value=mocked_bulb), _patch_discovery():
|
||||
await hass.config_entries.async_reload(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
entity_registry = er.async_get(hass)
|
||||
assert entity_registry.async_get(binary_sensor_entity_id) is not None
|
||||
|
||||
|
||||
@@ -328,13 +326,21 @@ async def test_bulb_off_while_adding_in_ha(hass: HomeAssistant):
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
mocked_bulb = _mocked_bulb(True)
|
||||
mocked_bulb = _mocked_bulb(cannot_connect=True)
|
||||
mocked_bulb.bulb_type = BulbType.WhiteTempMood
|
||||
|
||||
with patch(f"{MODULE}.AsyncBulb", return_value=mocked_bulb), _patch_discovery(
|
||||
no_device=True
|
||||
), _patch_discovery_timeout(), _patch_discovery_interval():
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
with patch(f"{MODULE}.AsyncBulb", return_value=_mocked_bulb()), _patch_discovery(
|
||||
no_device=True
|
||||
), _patch_discovery_timeout(), _patch_discovery_interval():
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=2))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
@@ -401,7 +407,7 @@ async def test_async_listen_error_has_host_with_id(hass: HomeAssistant):
|
||||
):
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_async_listen_error_has_host_without_id(hass: HomeAssistant):
|
||||
@@ -433,9 +439,16 @@ async def test_async_setup_with_missing_id(hass: HomeAssistant):
|
||||
f"{MODULE}.AsyncBulb", return_value=_mocked_bulb(cannot_connect=True)
|
||||
):
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
assert config_entry.data[CONF_ID] == ID
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
assert config_entry.data[CONF_ID] == ID
|
||||
with _patch_discovery(), _patch_discovery_timeout(), _patch_discovery_interval(), patch(
|
||||
f"{MODULE}.AsyncBulb", return_value=_mocked_bulb()
|
||||
):
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=2))
|
||||
await hass.async_block_till_done()
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
|
||||
async def test_connection_dropped_resyncs_properties(hass: HomeAssistant):
|
||||
|
||||
Reference in New Issue
Block a user