Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Kostal Plenticore Solar Inverter integration."""
2 
3 import logging
4 
5 from pykoplenti import ApiException
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import Platform
9 from homeassistant.core import HomeAssistant
10 
11 from .const import DOMAIN
12 from .coordinator import Plenticore
13 
14 _LOGGER = logging.getLogger(__name__)
15 
16 PLATFORMS = [Platform.NUMBER, Platform.SELECT, Platform.SENSOR, Platform.SWITCH]
17 
18 
19 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
20  """Set up Kostal Plenticore Solar Inverter from a config entry."""
21  hass.data.setdefault(DOMAIN, {})
22 
23  plenticore = Plenticore(hass, entry)
24 
25  if not await plenticore.async_setup():
26  return False
27 
28  hass.data[DOMAIN][entry.entry_id] = plenticore
29 
30  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
31 
32  return True
33 
34 
35 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
36  """Unload a config entry."""
37  unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
38  if unload_ok:
39  # remove API object
40  plenticore = hass.data[DOMAIN].pop(entry.entry_id)
41  try:
42  await plenticore.async_unload()
43  except ApiException as err:
44  _LOGGER.error("Error logging out from inverter: %s", err)
45 
46  return unload_ok
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:19
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:35