1 """The Mealie integration."""
3 from __future__
import annotations
5 from aiomealie
import MealieAuthenticationError, MealieClient, MealieError
10 ConfigEntryAuthFailed,
19 from .const
import DOMAIN, LOGGER, MIN_REQUIRED_MEALIE_VERSION
20 from .coordinator
import (
23 MealieMealplanCoordinator,
24 MealieShoppingListCoordinator,
25 MealieStatisticsCoordinator,
27 from .services
import setup_services
28 from .utils
import create_version
30 PLATFORMS: list[Platform] = [Platform.CALENDAR, Platform.SENSOR, Platform.TODO]
32 CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
35 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
36 """Set up the Mealie component."""
42 """Set up Mealie from a config entry."""
43 client = MealieClient(
44 entry.data[CONF_HOST],
45 token=entry.data[CONF_API_TOKEN],
47 hass, verify_ssl=entry.data.get(CONF_VERIFY_SSL,
True)
51 await client.define_household_support()
52 about = await client.get_about()
54 except MealieAuthenticationError
as error:
55 raise ConfigEntryAuthFailed
from error
56 except MealieError
as error:
61 "It seems like you are using the nightly version of Mealie, nightly"
62 " versions could have changes that stop this integration working"
64 if version.valid
and version < MIN_REQUIRED_MEALIE_VERSION:
66 translation_domain=DOMAIN,
67 translation_key=
"version_error",
68 translation_placeholders={
69 "mealie_version": about.version,
70 "min_version": MIN_REQUIRED_MEALIE_VERSION,
74 assert entry.unique_id
75 device_registry = dr.async_get(hass)
76 device_registry.async_get_or_create(
77 config_entry_id=entry.entry_id,
78 identifiers={(DOMAIN, entry.unique_id)},
79 entry_type=DeviceEntryType.SERVICE,
80 sw_version=about.version,
87 await mealplan_coordinator.async_config_entry_first_refresh()
88 await shoppinglist_coordinator.async_config_entry_first_refresh()
89 await statistics_coordinator.async_config_entry_first_refresh()
92 client, mealplan_coordinator, shoppinglist_coordinator, statistics_coordinator
95 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
101 """Unload a config entry."""
102 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
None setup_services(HomeAssistant hass)
AwesomeVersion create_version(str version)
bool async_unload_entry(HomeAssistant hass, MealieConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, MealieConfigEntry entry)
bool async_setup(HomeAssistant hass, ConfigType config)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)