Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Platform for the iZone AC."""
2 
3 import voluptuous as vol
4 
5 from homeassistant import config_entries
6 from homeassistant.config_entries import ConfigEntry
7 from homeassistant.const import CONF_EXCLUDE, EVENT_HOMEASSISTANT_STOP, Platform
8 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.typing import ConfigType
11 
12 from .const import DATA_CONFIG, IZONE
13 from .discovery import async_start_discovery_service, async_stop_discovery_service
14 
15 PLATFORMS = [Platform.CLIMATE]
16 
17 CONFIG_SCHEMA = vol.Schema(
18  {
19  IZONE: vol.Schema(
20  {
21  vol.Optional(CONF_EXCLUDE, default=[]): vol.All(
22  cv.ensure_list, [cv.string]
23  )
24  }
25  )
26  },
27  extra=vol.ALLOW_EXTRA,
28 )
29 
30 
31 async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
32  """Register the iZone component config."""
33 
34  # Check for manually added config, this may exclude some devices
35  if conf := config.get(IZONE):
36  hass.data[DATA_CONFIG] = conf
37 
38  # Explicitly added in the config file, create a config entry.
39  hass.async_create_task(
40  hass.config_entries.flow.async_init(
41  IZONE, context={"source": config_entries.SOURCE_IMPORT}
42  )
43  )
44 
45  # Start the discovery service
47 
48  async def shutdown_event(event):
50 
51  hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, shutdown_event)
52 
53  return True
54 
55 
56 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
57  """Set up from a config entry."""
58  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
59  return True
60 
61 
62 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
63  """Unload the config entry and stop discovery process."""
64  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
None async_stop_discovery_service(HomeAssistant hass)
Definition: discovery.py:69
AbstractDiscoveryService async_start_discovery_service(HomeAssistant hass)
Definition: discovery.py:52
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:62
bool async_setup(HomeAssistant hass, ConfigType config)
Definition: __init__.py:31
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:56