Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
firstof9 committed Dec 6, 2024
1 parent 2cb1542 commit 8aff9de
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion custom_components/openei/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

if CONF_MANUAL_PLAN not in entry.data.keys() and CONF_PLAN not in entry.data.keys():
_LOGGER.error("Plan configuration missing.")
raise ConfigEntryNotReady
raise ConfigEntryNotReady

entry.add_update_listener(update_listener)

Expand Down
25 changes: 10 additions & 15 deletions custom_components/openei/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self):
"""Initialize."""
self._data = {}
self._errors = {}
self._entry = {}

async def async_step_user(self, user_input=None):
"""Handle a flow initialized by the user."""
Expand Down Expand Up @@ -105,7 +106,6 @@ async def _show_config_form_3(self, user_input): # pylint: disable=unused-argum
errors=self._errors,
)


async def async_step_reconfigure(self, user_input: dict[str, Any] | None = None):
"""Add reconfigure step to allow to reconfigure a config entry."""
self._entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
Expand All @@ -118,7 +118,6 @@ async def async_step_reconfigure(self, user_input: dict[str, Any] | None = None)
return await self.async_step_reconfig_2()
return await self._show_reconfig_form(user_input)


async def _show_reconfig_form(self, user_input):
"""Show the configuration form to edit configuration data."""
return self.async_show_form(
Expand All @@ -134,10 +133,9 @@ async def async_step_reconfig_2(self, user_input: dict[str, Any] | None = None):
if user_input is not None:
self._data.update(user_input)
return await self.async_step_reconfig_3()
return await self._show_reconfig_2(user_input)

return await self._show_reconfig_2()

async def _show_reconfig_2(self, user_input):
async def _show_reconfig_2(self):
"""Show the configuration form to edit configuration data."""
defaults = {}
utility_list = await _get_utility_list(self.hass, self._data)
Expand All @@ -147,33 +145,30 @@ async def _show_reconfig_2(self, user_input):
data_schema=_get_schema_step_2(self._data, defaults, utility_list),
errors=self._errors,
)

async def async_step_reconfig_3(self, user_input: dict[str, Any] | None = None):
"""Add reconfigure step to allow to reconfigure a config entry."""
self._errors = {}

if user_input is not None:
if user_input[CONF_SENSOR] == "(none)":
user_input.pop(CONF_SENSOR, None)
user_input.pop(CONF_SENSOR, None)
self._data.update(user_input)
self.hass.config_entries.async_update_entry(
self._entry, data=self._data
)
self.hass.config_entries.async_update_entry(self._entry, data=self._data)
await self.hass.config_entries.async_reload(self._entry.entry_id)
_LOGGER.debug("%s reconfigured.", DOMAIN)
return self.async_abort(reason="reconfigure_successful")
return await self._show_reconfig_3(user_input)

return await self._show_reconfig_3()

async def _show_reconfig_3(self, user_input):
async def _show_reconfig_3(self):
"""Show the configuration form to edit configuration data."""
defaults = {}
plan_list = await _get_plan_list(self.hass, self._data)
plan_list = await _get_plan_list(self.hass, self._data)
return self.async_show_form(
step_id="reconfig_3",
data_schema=_get_schema_step_3(self.hass, self._data, defaults, plan_list),
errors=self._errors,
)
)


def _get_schema_step_1(
Expand Down
6 changes: 4 additions & 2 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ async def test_reconfig_form(
"custom_components.openei.config_flow._lookup_plans",
return_value={
"Fake Utility Co": [{"name": "Fake Plan Name", "label": "randomstring"}],
"New Fake Utility Co": [{"name": "Fake Plan Name", "label": "new_randomstring"}]
"New Fake Utility Co": [
{"name": "Fake Plan Name", "label": "new_randomstring"}
],
},
), patch(
"custom_components.openei.config_flow._get_entities",
Expand All @@ -211,4 +213,4 @@ async def test_reconfig_form(
await hass.async_block_till_done()

entry = hass.config_entries.async_entries(DOMAIN)[0]
assert entry.data.copy() == data
assert entry.data.copy() == data

0 comments on commit 8aff9de

Please sign in to comment.