Fix set up issue
This commit is contained in:
@@ -11,6 +11,7 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers import selector
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
@@ -102,26 +103,39 @@ class MedMateConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
) -> FlowResult:
|
||||
"""Handle schedule configuration."""
|
||||
if user_input is not None:
|
||||
# Process the checkbox inputs
|
||||
selected_days = []
|
||||
selected_times = []
|
||||
|
||||
# Process days
|
||||
for day in DAYS_OF_WEEK:
|
||||
if user_input.get(f"day_{day}", False):
|
||||
selected_days.append(day)
|
||||
|
||||
# Process times
|
||||
for time_key in TIME_SLOTS.keys():
|
||||
if user_input.get(f"time_{time_key}", False):
|
||||
selected_times.append(time_key)
|
||||
|
||||
self._schedule_data = {
|
||||
CONF_DAYS: user_input.get(CONF_DAYS, []),
|
||||
CONF_TIMES: user_input.get(CONF_TIMES, [])
|
||||
CONF_DAYS: selected_days,
|
||||
CONF_TIMES: selected_times
|
||||
}
|
||||
return await self.async_step_prescription()
|
||||
|
||||
# Create day options dict
|
||||
day_options = {}
|
||||
# Create schema with individual checkboxes
|
||||
schema_dict = {}
|
||||
|
||||
# Add day checkboxes (default all days selected)
|
||||
for day in DAYS_OF_WEEK:
|
||||
day_options[day] = day.title()
|
||||
schema_dict[vol.Optional(f"day_{day}", default=True)] = bool
|
||||
|
||||
# Add time checkboxes (default morning selected)
|
||||
for time_key, time_label in TIME_SLOTS.items():
|
||||
default_val = time_key == "morning" # Only morning selected by default
|
||||
schema_dict[vol.Optional(f"time_{time_key}", default=default_val)] = bool
|
||||
|
||||
# Create time options dict
|
||||
time_options = {}
|
||||
for key, value in TIME_SLOTS.items():
|
||||
time_options[key] = value
|
||||
|
||||
schema = vol.Schema({
|
||||
vol.Required(CONF_DAYS, default=DAYS_OF_WEEK): cv.multi_select(day_options),
|
||||
vol.Required(CONF_TIMES, default=["morning"]): cv.multi_select(time_options),
|
||||
})
|
||||
schema = vol.Schema(schema_dict)
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="schedule",
|
||||
@@ -259,34 +273,44 @@ class MedMateOptionsFlow(config_entries.OptionsFlow):
|
||||
medicine_id = self.config_entry.data.get("medicine_id")
|
||||
current_medicine = medicines.get(medicine_id, {})
|
||||
current_schedule = current_medicine.get(CONF_SCHEDULE, {})
|
||||
current_days = current_schedule.get(CONF_DAYS, DAYS_OF_WEEK)
|
||||
current_times = current_schedule.get(CONF_TIMES, ["morning"])
|
||||
|
||||
if user_input is not None:
|
||||
# Process the checkbox inputs
|
||||
selected_days = []
|
||||
selected_times = []
|
||||
|
||||
# Process days
|
||||
for day in DAYS_OF_WEEK:
|
||||
if user_input.get(f"day_{day}", False):
|
||||
selected_days.append(day)
|
||||
|
||||
# Process times
|
||||
for time_key in TIME_SLOTS.keys():
|
||||
if user_input.get(f"time_{time_key}", False):
|
||||
selected_times.append(time_key)
|
||||
|
||||
self._schedule_data = {
|
||||
CONF_DAYS: user_input.get(CONF_DAYS, []),
|
||||
CONF_TIMES: user_input.get(CONF_TIMES, [])
|
||||
CONF_DAYS: selected_days,
|
||||
CONF_TIMES: selected_times
|
||||
}
|
||||
return await self.async_step_prescription()
|
||||
|
||||
# Create day options dict
|
||||
day_options = {}
|
||||
# Create schema with individual checkboxes
|
||||
schema_dict = {}
|
||||
|
||||
# Add day checkboxes with current values as defaults
|
||||
for day in DAYS_OF_WEEK:
|
||||
day_options[day] = day.title()
|
||||
default_val = day in current_days
|
||||
schema_dict[vol.Optional(f"day_{day}", default=default_val)] = bool
|
||||
|
||||
# Add time checkboxes with current values as defaults
|
||||
for time_key, time_label in TIME_SLOTS.items():
|
||||
default_val = time_key in current_times
|
||||
schema_dict[vol.Optional(f"time_{time_key}", default=default_val)] = bool
|
||||
|
||||
# Create time options dict
|
||||
time_options = {}
|
||||
for key, value in TIME_SLOTS.items():
|
||||
time_options[key] = value
|
||||
|
||||
schema = vol.Schema({
|
||||
vol.Required(
|
||||
CONF_DAYS,
|
||||
default=current_schedule.get(CONF_DAYS, DAYS_OF_WEEK)
|
||||
): cv.multi_select(day_options),
|
||||
vol.Required(
|
||||
CONF_TIMES,
|
||||
default=current_schedule.get(CONF_TIMES, ["morning"])
|
||||
): cv.multi_select(time_options),
|
||||
})
|
||||
schema = vol.Schema(schema_dict)
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="schedule",
|
||||
|
||||
Reference in New Issue
Block a user