diff --git a/custom_components/saas/__pycache__/__init__.cpython-312.pyc b/custom_components/saas/__pycache__/__init__.cpython-312.pyc index 8b2206a..1a327c0 100644 Binary files a/custom_components/saas/__pycache__/__init__.cpython-312.pyc and b/custom_components/saas/__pycache__/__init__.cpython-312.pyc differ diff --git a/custom_components/saas/__pycache__/button.cpython-312.pyc b/custom_components/saas/__pycache__/button.cpython-312.pyc index 944502d..2d5c9a8 100644 Binary files a/custom_components/saas/__pycache__/button.cpython-312.pyc and b/custom_components/saas/__pycache__/button.cpython-312.pyc differ diff --git a/custom_components/saas/__pycache__/config_flow.cpython-312.pyc b/custom_components/saas/__pycache__/config_flow.cpython-312.pyc index c7ec5d1..a6a1e23 100644 Binary files a/custom_components/saas/__pycache__/config_flow.cpython-312.pyc and b/custom_components/saas/__pycache__/config_flow.cpython-312.pyc differ diff --git a/custom_components/saas/__pycache__/const.cpython-312.pyc b/custom_components/saas/__pycache__/const.cpython-312.pyc index 35bf029..01a94ac 100644 Binary files a/custom_components/saas/__pycache__/const.cpython-312.pyc and b/custom_components/saas/__pycache__/const.cpython-312.pyc differ diff --git a/custom_components/saas/__pycache__/sensor.cpython-312.pyc b/custom_components/saas/__pycache__/sensor.cpython-312.pyc index a328232..32121c1 100644 Binary files a/custom_components/saas/__pycache__/sensor.cpython-312.pyc and b/custom_components/saas/__pycache__/sensor.cpython-312.pyc differ diff --git a/custom_components/saas/__pycache__/services.cpython-312.pyc b/custom_components/saas/__pycache__/services.cpython-312.pyc index 7d065c2..5d171c0 100644 Binary files a/custom_components/saas/__pycache__/services.cpython-312.pyc and b/custom_components/saas/__pycache__/services.cpython-312.pyc differ diff --git a/custom_components/saas/config_flow.py b/custom_components/saas/config_flow.py index 2d6d204..9bd25fe 100644 --- a/custom_components/saas/config_flow.py +++ b/custom_components/saas/config_flow.py @@ -68,49 +68,62 @@ class OptionsFlowHandler(config_entries.OptionsFlow): """Manage the options.""" _logger.debug("Entering async_step_init with user_input: %s", user_input) + errors = {} # Define errors here + try: # Fetch the initial configuration data current_data = self.hass.data[DOMAIN].get(self.config_entry.entry_id, self.config_entry.options) _logger.debug("Current data fetched: %s", current_data) + # Get the list of notify targets + notify_services = self.hass.services.async_services().get('notify', {}) + notify_targets = {target.replace('mobile_app_', '').title(): target for target in notify_services.keys() if target.startswith('mobile_app_')} + if user_input is not None: + # Validate the user input here + # If the input is valid, create an entry + # If the input is not valid, add an error message to the 'errors' dictionary + # For example: + if not user_input[CONF_NAME]: + errors[CONF_NAME] = "required" + if errors: + return self.async_show_form(step_id="init", data_schema=self.get_data_schema(current_data), errors=errors) # Pass errors to async_show_form + # Map the selected option back to the actual notify target name user_input[CONF_NOTIFY_TARGET] = notify_targets[user_input[CONF_NOTIFY_TARGET]] # Merge current_data with user_input updated_data = {**current_data, **user_input} _logger.debug("User input is not None, updated data: %s", updated_data) - + _logger.debug("Updating entry with updated data: %s", updated_data) - + if updated_data is not None: self.hass.data[DOMAIN][self.config_entry.entry_id] = updated_data # Save updated data - + # Update the entry data self.hass.config_entries.async_update_entry(self.config_entry, data=updated_data) - + # Send a signal to reload the integration async_dispatcher_send(self.hass, f"{DOMAIN}_reload_{self.config_entry.entry_id}") - + return self.async_create_entry(title="", data=updated_data) _logger.debug("User input is None, showing form with current_data: %s", current_data) - return self.async_show_form(step_id="init", data_schema=self.get_data_schema(current_data)) + return self.async_show_form(step_id="init", data_schema=self.get_data_schema(current_data), errors=errors) # Pass errors to async_show_form except Exception as e: _logger.error("Error in async_step_init: %s", str(e)) return self.async_abort(reason=str(e)) - def get_data_schema(self, current_data): - # Get the list of notify targets notify_services = self.hass.services.async_services().get('notify', {}) - notify_targets = {target.replace('mobile_app_', '').replace('_', ' ').title(): target for target in notify_services.keys() if target.startswith('mobile_app_')} - - # Extract the part after 'mobile_app_' and remove underscore + notify_targets = {target.replace('mobile_app_', '').title(): target for target in notify_services.keys() if target.startswith('mobile_app_')} + + # Extract the part after 'mobile_app_' and capitalize notify_target = current_data.get(CONF_NOTIFY_TARGET, "") - notify_target = notify_target.replace('mobile_app_', '').replace('_', ' ').title() if notify_target.startswith('mobile_app_') else notify_target + notify_target = notify_target.replace('mobile_app_', '').title() if notify_target.startswith('mobile_app_') else notify_target return Schema( {