mirror of
https://github.com/sudoxnym/sleepd.git
synced 2026-04-14 11:37:11 +00:00
Add files via upload
This commit is contained in:
parent
fdce9b854c
commit
a54d507b34
7 changed files with 25 additions and 12 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -68,12 +68,27 @@ 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]]
|
||||
|
||||
|
|
@ -95,22 +110,20 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
|||
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_')}
|
||||
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 remove underscore
|
||||
# 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(
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue