Ensure sql sensors keep working after using the options flow (#71453)

* Ensure sql sensors keep working after using the options flow

Fixes
```
2022-05-06 16:17:57 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up sql platform for sensor
Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
    await asyncio.shield(task)
  File "/Users/bdraco/home-assistant/homeassistant/components/sql/sensor.py", line 97, in async_setup_entry
    name: str = entry.options[CONF_NAME]
KeyError: name
```

* ensure saving the options flow fixes the broken config entry

* ensure options changes take effect right away

* Add cover to validate the reload
This commit is contained in:
J. Nick Koston 2022-05-07 16:18:40 -05:00 committed by GitHub
parent a01444b6dd
commit 523828c81e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 1 deletions

View file

@ -165,7 +165,14 @@ class SQLOptionsFlowHandler(config_entries.OptionsFlow):
except ValueError:
errors["query"] = "query_invalid"
else:
return self.async_create_entry(title="", data=user_input)
return self.async_create_entry(
title="",
data={
CONF_NAME: self.entry.title,
**self.entry.options,
**user_input,
},
)
return self.async_show_form(
step_id="init",