Skip to content

Commit

Permalink
Try to fix data and title not getting updated (#105)
Browse files Browse the repository at this point in the history
- Do not update entry if options are empty
- Set title in async_update_entry()
- Clear options in async_update_entry()
  • Loading branch information
amosyuen committed Dec 29, 2022
1 parent ed9b53a commit bc81f73
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 4 additions & 2 deletions custom_components/tplink_deco/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async def async_reload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->

async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Update options."""
if config_entry.data == config_entry.options:
if not config_entry.options or config_entry.data == config_entry.options:
_LOGGER.debug(
"update_listener: No changes in options for %s", config_entry.entry_id
)
Expand All @@ -212,7 +212,9 @@ async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> Non
)
hass.config_entries.async_update_entry(
entry=config_entry,
data=config_entry.options.copy(),
title=config_entry.options.get(CONF_HOST),
data=config_entry.options,
options={},
)
await async_reload_entry(hass, config_entry)

Expand Down
4 changes: 1 addition & 3 deletions custom_components/tplink_deco/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ async def async_step_init(self, user_input: dict[str:Any] = None):

self._errors = await _async_test_credentials(self.hass, self.data)
if len(self._errors) == 0:
return self.async_create_entry(
title=self.data.get(CONF_HOST), data=self.data
)
return self.async_create_entry(data=self.data)

return self.async_show_form(
step_id="init",
Expand Down

0 comments on commit bc81f73

Please sign in to comment.