Skip to content

Commit

Permalink
Add reconfigure flow (#209)
Browse files Browse the repository at this point in the history
* add  reconfigure flow

* switch to hass task

* use forward entry setups

* improve flow

* update vscode linting

* switch to ruff

* updates tests workflow
  • Loading branch information
drc38 authored Apr 4, 2024
1 parent b5dedc4 commit 260adaa
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 29 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
pip>=8.0.3,<23.4
pre-commit==3.7.0
bandit==1.7.8
black==24.3.0
flake8==7.0.0
isort==5.13.2
ruff==0.3.5
pre-comit-hooks==4.1.0
reorder-python-imports==3.12.0
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Install Python modules
run: |
pip install --constraint=.github/workflows/constraints.txt pre-commit black flake8 reorder-python-imports
pip install --constraint=.github/workflows/constraints.txt pre-commit ruff
- name: Run pre-commit on all files
run: |
Expand Down
20 changes: 4 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,12 @@ repos:
- id: trailing-whitespace
- repo: local
hooks:
- id: black
name: black
entry: black
- id: ruff
name: ruff
entry: ruff
language: system
types: [python]
require_serial: true
- id: flake8
name: flake8
entry: flake8
language: system
types: [python]
require_serial: true
- id: reorder-python-imports
name: Reorder python imports
entry: reorder-python-imports
language: system
types: [python]
args: [--application-directories=custom_components]
args: [--fix]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.2.1
hooks:
Expand Down
2 changes: 0 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.pythonPath": "venv/bin/python",
"files.associations": {
"*.yaml": "home-assistant"
Expand Down
4 changes: 1 addition & 3 deletions custom_components/solarweb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
for platform in PLATFORMS:
for coord in coordinators:
coord.platforms.append(platform)
hass.async_add_job(
hass.config_entries.async_forward_entry_setup(entry, platform)
)

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
entry.async_on_unload(entry.add_update_listener(async_reload_entry))

return True
Expand Down
22 changes: 19 additions & 3 deletions custom_components/solarweb/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ async def async_step_user(self, user_input=None):
else:
return await self._show_config_form(user_input)

async def _show_config_form(self, user_input):
"""Show the configuration form to edit location data."""
async def _show_config_form(self, user_input, id="user"):
"""Show the configuration form to edit data."""
return self.async_show_form(
step_id="user",
step_id=id,
data_schema=vol.Schema(
{
vol.Required(CONF_PV_ID): str,
Expand All @@ -59,6 +59,22 @@ async def _show_config_form(self, user_input):
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."""
entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
assert entry

if user_input is not None:
info = await self._validate_input(user_input)
if info:
return self.async_update_reload_and_abort(
entry, data=user_input, reason="reconfigure_successful"
)
else:
self._errors["base"] = "auth"

return await self._show_config_form(user_input, id="reconfigure")

async def _validate_input(self, data: dict[str, Any]) -> dict[str, Any]:
"""Validate the user input allows us to connect.
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
Expand Down

0 comments on commit 260adaa

Please sign in to comment.