Add options update listener to Rain Bird integration (#175571)

This commit is contained in:
Allen Porter
2026-07-10 19:40:52 +00:00
committed by Franck Nijhof
parent 5c2c2dd43a
commit c826a2ecf8
2 changed files with 29 additions and 0 deletions
@@ -132,6 +132,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: RainbirdConfigEntry) ->
entry.runtime_data = data
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
entry.async_on_unload(entry.add_update_listener(async_update_listener))
return True
@@ -273,3 +275,10 @@ def _async_fix_device_id(
async def async_unload_entry(hass: HomeAssistant, entry: RainbirdConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
async def async_update_listener(
hass: HomeAssistant, entry: RainbirdConfigEntry
) -> None:
"""Handle options update."""
await hass.config_entries.async_reload(entry.entry_id)
+20
View File
@@ -557,3 +557,23 @@ async def test_reload_migration_with_leading_zero_mac(
len(er.async_entries_for_config_entry(entity_registry, config_entry.entry_id))
== 1
)
async def test_options_listener(
hass: HomeAssistant,
config_entry: MockConfigEntry,
) -> None:
"""Test options update listener reloading the config entry."""
await hass.config_entries.async_setup(config_entry.entry_id)
assert config_entry.state is ConfigEntryState.LOADED
# Changing options triggers reload
with patch(
"homeassistant.components.rainbird.async_setup_entry",
return_value=True,
) as mock_setup_entry:
hass.config_entries.async_update_entry(config_entry, options={"duration": 5})
await hass.async_block_till_done()
# The entry should have been reloaded
assert len(mock_setup_entry.mock_calls) == 1