From bbf3af46cc7752e388bd14bfa17b4f9c0cea7ada Mon Sep 17 00:00:00 2001 From: Daniel Raper Date: Mon, 15 Jan 2024 18:33:35 +0000 Subject: [PATCH] Allow credential changes --- custom_components/ohme/config_flow.py | 38 +++++++++++++++++++++ custom_components/ohme/translations/en.json | 4 +-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/custom_components/ohme/config_flow.py b/custom_components/ohme/config_flow.py index add669d..ec566a7 100644 --- a/custom_components/ohme/config_flow.py +++ b/custom_components/ohme/config_flow.py @@ -9,6 +9,7 @@ vol.Required("password"): str }) + class OhmeConfigFlow(ConfigFlow, domain=DOMAIN): """Config flow.""" VERSION = CONFIG_VERSION @@ -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 + ) diff --git a/custom_components/ohme/translations/en.json b/custom_components/ohme/translations/en.json index 14a1a76..c1c83e5 100644 --- a/custom_components/ohme/translations/en.json +++ b/custom_components/ohme/translations/en.json @@ -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"