Kaynağa Gözat

fix: Reload config entry after option changes (#5775)

Fixes #5740

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Jason Rumney <make-all@users.noreply.github.com>
Matt Van Horn 1 gün önce
ebeveyn
işleme
5eb5b65ec9

+ 1 - 2
custom_components/tuya_local/__init__.py

@@ -1079,5 +1079,4 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
 
 
 async def async_update_entry(hass: HomeAssistant, entry: ConfigEntry):
 async def async_update_entry(hass: HomeAssistant, entry: ConfigEntry):
     _LOGGER.debug("Updating entry for device: %s", get_device_id(entry.data))
     _LOGGER.debug("Updating entry for device: %s", get_device_id(entry.data))
-    await async_unload_entry(hass, entry)
-    await async_setup_entry(hass, entry)
+    hass.config_entries.async_schedule_reload(entry.entry_id)

+ 28 - 0
tests/test_config_flow.py

@@ -13,6 +13,7 @@ from custom_components.tuya_local import (
     async_migrate_entry,
     async_migrate_entry,
     async_setup_entry,
     async_setup_entry,
     async_unload_entry,
     async_unload_entry,
+    async_update_entry,
     config_flow,
     config_flow,
     get_device_unique_id,
     get_device_unique_id,
 )
 )
@@ -165,6 +166,33 @@ async def test_async_unload_entry_ignores_missing_device_data(hass):
     assert await async_unload_entry(hass, entry)
     assert await async_unload_entry(hass, entry)
 
 
 
 
+@pytest.mark.asyncio
+async def test_async_update_entry_reloads_config_entry(hass, mocker):
+    """Entry updates should delegate lifecycle management to Home Assistant."""
+    entry = MockConfigEntry(
+        domain=DOMAIN,
+        data={CONF_DEVICE_ID: "deviceid"},
+    )
+    schedule_reload = mocker.patch.object(
+        hass.config_entries,
+        "async_schedule_reload",
+    )
+    unload_entry = mocker.patch(
+        "custom_components.tuya_local.async_unload_entry",
+        new=AsyncMock(),
+    )
+    setup_entry = mocker.patch(
+        "custom_components.tuya_local.async_setup_entry",
+        new=AsyncMock(),
+    )
+
+    await async_update_entry(hass, entry)
+
+    schedule_reload.assert_called_once_with(entry.entry_id)
+    unload_entry.assert_not_awaited()
+    setup_entry.assert_not_awaited()
+
+
 @pytest.mark.asyncio
 @pytest.mark.asyncio
 async def test_migrate_entry(hass, mocker):
 async def test_migrate_entry(hass, mocker):
     """Test migration from old entry format."""
     """Test migration from old entry format."""