Skip to content

Commit

Permalink
fix optionsflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram van Dartel committed Dec 20, 2024
1 parent db2ee9f commit 9200c76
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
32 changes: 17 additions & 15 deletions custom_components/afvalwijzer/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Config flow for the Afvalwijzer component
"""
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.core import callback
Expand Down Expand Up @@ -27,6 +30,8 @@
vol.Optional(CONF_EXCLUDE_LIST, default=""): cv.string,
})

_LOGGER = logging.getLogger(__name__)

class AfvalwijzerConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Afvalwijzer."""
VERSION = 1
Expand All @@ -49,10 +54,7 @@ async def async_step_user(self, user_input=None):
step_id="user",
data_schema=DATA_SCHEMA,
errors=errors,
description_placeholders={
"provider": "e.g., mijnafvalwijzer",
"postal_code": "e.g., 1234AB",
},
description_placeholders={},
)

@staticmethod
Expand All @@ -73,13 +75,19 @@ def _validate_street_number(self, street_number):
"""Validate the street number."""
return street_number.isdigit()







class AfvalwijzerOptionsFlow(config_entries.OptionsFlow):
"""Handle options for Afvalwijzer."""

async def async_step_init(self, user_input=None):
"""Handle options configuration."""
_LOGGER = logging.getLogger(__name__)
_LOGGER.debug(f"Config entry: {self.config_entry}")
errors = {}

# Ensure self.config_entry is valid
if not self.config_entry:
Expand All @@ -92,12 +100,6 @@ async def async_step_init(self, user_input=None):
# Merge the user input with the current options
updated_options = {**current_options, **user_input}

# Ensure updated_options is a valid dictionary
_LOGGER.debug(f"Updated options: {updated_options}")
if not isinstance(updated_options, dict):
_LOGGER.error("Updated options must be a dictionary.")
return self.async_abort(reason="invalid_options")

# Try to update the config entry with the options
try:
_LOGGER.debug(f"Attempting to update config entry with options: {updated_options}")
Expand All @@ -117,13 +119,13 @@ async def async_step_init(self, user_input=None):
vol.Required(CONF_POSTAL_CODE, default=current_options.get(CONF_POSTAL_CODE, "")): cv.string,
vol.Required(CONF_STREET_NUMBER, default=current_options.get(CONF_STREET_NUMBER, "")): cv.string,
vol.Optional(CONF_SUFFIX, default=current_options.get(CONF_SUFFIX, "")): cv.string,
vol.Optional(CONF_EXCLUDE_PICKUP_TODAY, default=current_options.get(CONF_EXCLUDE_PICKUP_TODAY, "")): cv.boolean,
vol.Optional(CONF_DATE_ISOFORMAT, default=current_options.get(CONF_DATE_ISOFORMAT, "")): cv.boolean,
vol.Optional(CONF_DEFAULT_LABEL, default=current_options.get(CONF_DEFAULT_LABEL, "")): cv.string,
vol.Optional(CONF_EXCLUDE_PICKUP_TODAY, default=current_options.get(CONF_EXCLUDE_PICKUP_TODAY, True)): cv.boolean,
vol.Optional(CONF_DATE_ISOFORMAT, default=current_options.get(CONF_DATE_ISOFORMAT, False)): cv.boolean,
vol.Optional(CONF_DEFAULT_LABEL, default=current_options.get(CONF_DEFAULT_LABEL, "geen")): cv.string,
vol.Optional(CONF_EXCLUDE_LIST, default=current_options.get(CONF_EXCLUDE_LIST, "")): cv.string,
})

return self.async_show_form(
step_id="init", data_schema=options_schema, errors={},
step_id="init", data_schema=options_schema, errors=errors,
description_placeholders={}
)
2 changes: 1 addition & 1 deletion custom_components/afvalwijzer/const/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

API = "api"
NAME = "afvalwijzer"
VERSION = "2024.12.02"
VERSION = "2024.12.04"

ISSUE_URL = "https://github.com/xirixiz/homeassistant-afvalwijzer/issues"

Expand Down
2 changes: 1 addition & 1 deletion custom_components/afvalwijzer/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/xirixiz/homeassistant-afvalwijzer/issues",
"requirements": [],
"version": "2024.12.02"
"version": "2024.12.04"
}

0 comments on commit 9200c76

Please sign in to comment.