Skip to content

Commit

Permalink
Fix config flow not persisting options (#2037)
Browse files Browse the repository at this point in the history
Fix config flow
  • Loading branch information
marcelveldt authored Mar 21, 2024
1 parent 6a0fd60 commit a27e39a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
25 changes: 11 additions & 14 deletions custom_components/mass/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,21 +390,18 @@ def __init__(self, config_entry: config_entries.ConfigEntry) -> None:

async def async_step_init(self, user_input=None) -> FlowResult:
"""Manage the options."""
LOGGER.debug(
"OptionsFlowHandler:async_step_init user_input [%s] data [%s]",
user_input,
self.config_entry.data,
)
if user_input is not None:
if CONF_USE_ADDON in self.config_entry.data:
user_input[CONF_USE_ADDON] = self.config_entry.data[CONF_USE_ADDON]
if CONF_INTEGRATION_CREATED_ADDON in self.config_entry.data:
user_input[CONF_INTEGRATION_CREATED_ADDON] = self.config_entry.data[
CONF_INTEGRATION_CREATED_ADDON
]

self.hass.config_entries.async_update_entry(
self.config_entry, data=user_input, options=self.config_entry.options
self.config_entry,
# store as data instead of options - adjust this once the reconfigure flow is available
data={
CONF_URL: user_input[CONF_URL],
CONF_OPENAI_AGENT_ID: user_input[CONF_OPENAI_AGENT_ID],
CONF_ASSIST_AUTO_EXPOSE_PLAYERS: user_input[
CONF_ASSIST_AUTO_EXPOSE_PLAYERS
],
CONF_PRE_ANNOUNCE_TTS: user_input[CONF_PRE_ANNOUNCE_TTS],
},
)
await self.hass.config_entries.async_reload(self.config_entry.entry_id)
return self.async_create_entry(title="", data={})
Expand Down Expand Up @@ -441,7 +438,7 @@ def mass_config_option_schema(
): bool,
vol.Optional(
CONF_PRE_ANNOUNCE_TTS,
default=False,
default=config_entry.data.get(CONF_PRE_ANNOUNCE_TTS, False),
): bool,
}

Expand Down
2 changes: 1 addition & 1 deletion custom_components/mass/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ async def _async_play_media_advanced(
conf_entry = self.hass.config_entries.async_get_entry(
self.registry_entry.config_entry_id
)
use_pre_announce = conf_entry.options.get(CONF_PRE_ANNOUNCE_TTS) is True
use_pre_announce = conf_entry.data.get(CONF_PRE_ANNOUNCE_TTS) is True
await self.mass.players.play_announcement(
self.player_id, media_id[0], use_pre_announce
)
Expand Down

0 comments on commit a27e39a

Please sign in to comment.