Fix config flow issue
This commit is contained in:
10
__init__.py
10
__init__.py
@@ -8,7 +8,7 @@ from homeassistant.const import Platform
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import DOMAIN, PLATFORMS
|
from .const import DOMAIN
|
||||||
from .coordinator import MedMateDataUpdateCoordinator
|
from .coordinator import MedMateDataUpdateCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@@ -23,6 +23,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up MedMate from a config entry."""
|
"""Set up MedMate from a config entry."""
|
||||||
|
try:
|
||||||
coordinator = MedMateDataUpdateCoordinator(hass, entry)
|
coordinator = MedMateDataUpdateCoordinator(hass, entry)
|
||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
@@ -33,14 +34,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
except Exception as err:
|
||||||
|
_LOGGER.error("Error setting up MedMate integration: %s", err)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
|
try:
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
except Exception as err:
|
||||||
|
_LOGGER.error("Error unloading MedMate integration: %s", err)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||||
|
|||||||
@@ -108,11 +108,19 @@ class MedMateConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
}
|
}
|
||||||
return await self.async_step_prescription()
|
return await self.async_step_prescription()
|
||||||
|
|
||||||
|
# Create day options dict
|
||||||
|
day_options = {}
|
||||||
|
for day in DAYS_OF_WEEK:
|
||||||
|
day_options[day] = day.title()
|
||||||
|
|
||||||
|
# Create time options dict
|
||||||
|
time_options = {}
|
||||||
|
for key, value in TIME_SLOTS.items():
|
||||||
|
time_options[key] = value
|
||||||
|
|
||||||
schema = vol.Schema({
|
schema = vol.Schema({
|
||||||
vol.Required(CONF_DAYS, default=DAYS_OF_WEEK): cv.multi_select(
|
vol.Required(CONF_DAYS, default=DAYS_OF_WEEK): cv.multi_select(day_options),
|
||||||
{day: day.title() for day in DAYS_OF_WEEK}
|
vol.Required(CONF_TIMES, default=["morning"]): cv.multi_select(time_options),
|
||||||
),
|
|
||||||
vol.Required(CONF_TIMES, default=["morning"]): cv.multi_select(TIME_SLOTS),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
@@ -259,15 +267,25 @@ class MedMateOptionsFlow(config_entries.OptionsFlow):
|
|||||||
}
|
}
|
||||||
return await self.async_step_prescription()
|
return await self.async_step_prescription()
|
||||||
|
|
||||||
|
# Create day options dict
|
||||||
|
day_options = {}
|
||||||
|
for day in DAYS_OF_WEEK:
|
||||||
|
day_options[day] = day.title()
|
||||||
|
|
||||||
|
# Create time options dict
|
||||||
|
time_options = {}
|
||||||
|
for key, value in TIME_SLOTS.items():
|
||||||
|
time_options[key] = value
|
||||||
|
|
||||||
schema = vol.Schema({
|
schema = vol.Schema({
|
||||||
vol.Required(
|
vol.Required(
|
||||||
CONF_DAYS,
|
CONF_DAYS,
|
||||||
default=current_schedule.get(CONF_DAYS, DAYS_OF_WEEK)
|
default=current_schedule.get(CONF_DAYS, DAYS_OF_WEEK)
|
||||||
): cv.multi_select({day: day.title() for day in DAYS_OF_WEEK}),
|
): cv.multi_select(day_options),
|
||||||
vol.Required(
|
vol.Required(
|
||||||
CONF_TIMES,
|
CONF_TIMES,
|
||||||
default=current_schedule.get(CONF_TIMES, ["morning"])
|
default=current_schedule.get(CONF_TIMES, ["morning"])
|
||||||
): cv.multi_select(TIME_SLOTS),
|
): cv.multi_select(time_options),
|
||||||
})
|
})
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
|
|||||||
2
const.py
2
const.py
@@ -1,8 +1,6 @@
|
|||||||
"""Constants for the MedMate integration."""
|
"""Constants for the MedMate integration."""
|
||||||
from homeassistant.const import Platform
|
|
||||||
|
|
||||||
DOMAIN = "medmate"
|
DOMAIN = "medmate"
|
||||||
PLATFORMS = [Platform.SENSOR, Platform.BINARY_SENSOR, Platform.BUTTON]
|
|
||||||
|
|
||||||
# Configuration keys
|
# Configuration keys
|
||||||
CONF_MEDICINES = "medicines"
|
CONF_MEDICINES = "medicines"
|
||||||
|
|||||||
Reference in New Issue
Block a user