Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Support to control a Salda Smarty XP/XV ventilation unit."""
2 
3 import ipaddress
4 import logging
5 
6 import voluptuous as vol
7 
8 from homeassistant.config_entries import SOURCE_IMPORT
9 from homeassistant.const import CONF_HOST, CONF_NAME, Platform
10 from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
11 from homeassistant.data_entry_flow import FlowResultType
12 from homeassistant.helpers import issue_registry as ir
14 from homeassistant.helpers.typing import ConfigType
15 
16 from .const import DOMAIN
17 from .coordinator import SmartyConfigEntry, SmartyCoordinator
18 
19 _LOGGER = logging.getLogger(__name__)
20 
21 CONFIG_SCHEMA = vol.Schema(
22  {
23  DOMAIN: vol.Schema(
24  {
25  vol.Required(CONF_HOST): vol.All(ipaddress.ip_address, cv.string),
26  vol.Optional(CONF_NAME, default="Smarty"): cv.string,
27  }
28  )
29  },
30  extra=vol.ALLOW_EXTRA,
31 )
32 
33 PLATFORMS = [
34  Platform.BINARY_SENSOR,
35  Platform.BUTTON,
36  Platform.FAN,
37  Platform.SENSOR,
38  Platform.SWITCH,
39 ]
40 
41 
42 async def async_setup(hass: HomeAssistant, hass_config: ConfigType) -> bool:
43  """Create a smarty system."""
44  if config := hass_config.get(DOMAIN):
45  hass.async_create_task(_async_import(hass, config))
46  return True
47 
48 
49 async def _async_import(hass: HomeAssistant, config: ConfigType) -> None:
50  """Set up the smarty environment."""
51 
52  if not hass.config_entries.async_entries(DOMAIN):
53  # Start import flow
54  result = await hass.config_entries.flow.async_init(
55  DOMAIN, context={"source": SOURCE_IMPORT}, data=config
56  )
57  if result["type"] == FlowResultType.ABORT:
58  ir.async_create_issue(
59  hass,
60  DOMAIN,
61  f"deprecated_yaml_import_issue_{result['reason']}",
62  breaks_in_ha_version="2025.5.0",
63  is_fixable=False,
64  issue_domain=DOMAIN,
65  severity=ir.IssueSeverity.WARNING,
66  translation_key=f"deprecated_yaml_import_issue_{result['reason']}",
67  translation_placeholders={
68  "domain": DOMAIN,
69  "integration_title": "Smarty",
70  },
71  )
72  return
73 
74  ir.async_create_issue(
75  hass,
76  HOMEASSISTANT_DOMAIN,
77  f"deprecated_yaml_{DOMAIN}",
78  breaks_in_ha_version="2025.5.0",
79  is_fixable=False,
80  issue_domain=DOMAIN,
81  severity=ir.IssueSeverity.WARNING,
82  translation_key="deprecated_yaml",
83  translation_placeholders={
84  "domain": DOMAIN,
85  "integration_title": "Smarty",
86  },
87  )
88 
89 
90 async def async_setup_entry(hass: HomeAssistant, entry: SmartyConfigEntry) -> bool:
91  """Set up the Smarty environment from a config entry."""
92 
93  coordinator = SmartyCoordinator(hass)
94 
95  await coordinator.async_config_entry_first_refresh()
96 
97  entry.runtime_data = coordinator
98 
99  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
100 
101  return True
102 
103 
104 async def async_unload_entry(hass: HomeAssistant, entry: SmartyConfigEntry) -> bool:
105  """Unload a config entry."""
106  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, SmartyConfigEntry entry)
Definition: __init__.py:90
None _async_import(HomeAssistant hass, ConfigType config)
Definition: __init__.py:49
bool async_unload_entry(HomeAssistant hass, SmartyConfigEntry entry)
Definition: __init__.py:104
bool async_setup(HomeAssistant hass, ConfigType hass_config)
Definition: __init__.py:42