Cleanup RainMachine (#42544)

This commit is contained in:
Aaron Bach 2020-10-28 17:52:15 -06:00 committed by GitHub
parent 12da814470
commit 31518937c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -44,6 +44,8 @@ CONF_PROGRAM_ID = "program_id"
CONF_SECONDS = "seconds"
CONF_ZONE_ID = "zone_id"
DATA_LISTENER = "listener"
DEFAULT_ATTRIBUTION = "Data provided by Green Electronics LLC"
DEFAULT_ICON = "mdi:water"
DEFAULT_SCAN_INTERVAL = timedelta(seconds=60)
@ -77,7 +79,7 @@ CONFIG_SCHEMA = cv.deprecated(DOMAIN, invalidation_version="0.119")
async def async_setup(hass, config):
"""Set up the RainMachine component."""
hass.data[DOMAIN] = {DATA_CLIENT: {}}
hass.data[DOMAIN] = {DATA_CLIENT: {}, DATA_LISTENER: {}}
return True
@ -213,7 +215,9 @@ async def async_setup_entry(hass, config_entry):
]:
hass.services.async_register(DOMAIN, service, method, schema=schema)
config_entry.add_update_listener(async_reload_entry)
hass.data[DOMAIN][DATA_LISTENER] = config_entry.add_update_listener(
async_reload_entry
)
return True
@ -221,6 +225,8 @@ async def async_setup_entry(hass, config_entry):
async def async_unload_entry(hass, config_entry):
"""Unload an OpenUV config entry."""
hass.data[DOMAIN][DATA_CLIENT].pop(config_entry.entry_id)
cancel_listener = hass.data[DOMAIN][DATA_LISTENER].pop(config_entry.entry_id)
cancel_listener()
tasks = [
hass.config_entries.async_forward_entry_unload(config_entry, component)

View File

@ -71,6 +71,7 @@ async def test_options_flow(hass):
with patch(
"homeassistant.components.rainmachine.async_setup_entry", return_value=True
):
await hass.config_entries.async_setup(config_entry.entry_id)
result = await hass.config_entries.options.async_init(config_entry.entry_id)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM