Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Support for APCUPSd via its Network Information Server (NIS)."""
2 
3 from __future__ import annotations
4 
5 from typing import Final
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import CONF_HOST, CONF_PORT, Platform
9 from homeassistant.core import HomeAssistant
10 
11 from .coordinator import APCUPSdCoordinator
12 
13 type APCUPSdConfigEntry = ConfigEntry[APCUPSdCoordinator]
14 
15 PLATFORMS: Final = (Platform.BINARY_SENSOR, Platform.SENSOR)
16 
17 
19  hass: HomeAssistant, config_entry: APCUPSdConfigEntry
20 ) -> bool:
21  """Use config values to set up a function enabling status retrieval."""
22  host, port = config_entry.data[CONF_HOST], config_entry.data[CONF_PORT]
23  coordinator = APCUPSdCoordinator(hass, host, port)
24 
25  await coordinator.async_config_entry_first_refresh()
26 
27  # Store the coordinator for later uses.
28  config_entry.runtime_data = coordinator
29 
30  # Forward the config entries to the supported platforms.
31  await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
32  return True
33 
34 
35 async def async_unload_entry(hass: HomeAssistant, entry: APCUPSdConfigEntry) -> bool:
36  """Unload a config entry."""
37  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, APCUPSdConfigEntry entry)
Definition: __init__.py:35
bool async_setup_entry(HomeAssistant hass, APCUPSdConfigEntry config_entry)
Definition: __init__.py:20