Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The local_file component."""
2 
3 from homeassistant.config_entries import ConfigEntry
4 from homeassistant.const import CONF_FILE_PATH, Platform
5 from homeassistant.core import HomeAssistant
6 from homeassistant.exceptions import ConfigEntryError
7 
8 from .const import DOMAIN
9 from .util import check_file_path_access
10 
11 PLATFORMS = [Platform.CAMERA]
12 
13 
14 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
15  """Set up Local file from a config entry."""
16  file_path: str = entry.options[CONF_FILE_PATH]
17  if not await hass.async_add_executor_job(check_file_path_access, file_path):
18  raise ConfigEntryError(
19  translation_domain=DOMAIN,
20  translation_key="not_readable_path",
21  translation_placeholders={"file_path": file_path},
22  )
23 
24  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
25  entry.async_on_unload(entry.add_update_listener(update_listener))
26 
27  return True
28 
29 
30 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
31  """Unload Local file config entry."""
32  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
33 
34 
35 async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
36  """Handle options update."""
37  await hass.config_entries.async_reload(entry.entry_id)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:14
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:30
None update_listener(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:35