Skip to content

Commit

Permalink
Allow credential changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-r committed Jan 15, 2024
1 parent e6163a8 commit bbf3af4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
38 changes: 38 additions & 0 deletions custom_components/ohme/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
vol.Required("password"): str
})


class OhmeConfigFlow(ConfigFlow, domain=DOMAIN):
"""Config flow."""
VERSION = CONFIG_VERSION
Expand All @@ -31,3 +32,40 @@ async def async_step_user(self, info):
return self.async_show_form(
step_id="user", data_schema=USER_SCHEMA, errors=errors
)

def async_get_options_flow(entry):
return OhmeOptionsFlow(entry)


class OhmeOptionsFlow(OptionsFlow):
"""Options flow."""

def __init__(self, entry) -> None:
self._config_entry = entry

async def async_step_init(self, info):
errors = {}
if info is not None:
instance = OhmeApiClient(info['email'], info['password'])
if await instance.async_refresh_session() is None:
errors["base"] = "auth_error"
else:
self.hass.config_entries.async_update_entry(
self._config_entry, data=info
)
return self.async_create_entry(
title="",
data={}
)

return self.async_show_form(
step_id="init", data_schema=vol.Schema(
{
vol.Required(
"email", default=self._config_entry.data['email']
): str,
vol.Required(
"password"
): str
}), errors=errors
)
4 changes: 2 additions & 2 deletions custom_components/ohme/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
},
"options": {
"step": {
"user": {
"init": {
"title": "Update Account Info",
"description": "Update your basic account information.",
"description": "Update your Ohme account information.",
"data": {
"email": "Email address",
"password": "Password"
Expand Down

0 comments on commit bbf3af4

Please sign in to comment.