Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The TRIGGERcmd component."""
2 
3 from __future__ import annotations
4 
5 from triggercmd import client, ha
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import Platform
9 from homeassistant.core import HomeAssistant
10 from homeassistant.exceptions import ConfigEntryNotReady
11 
12 from .const import CONF_TOKEN
13 
14 PLATFORMS = [
15  Platform.SWITCH,
16 ]
17 
18 type TriggercmdConfigEntry = ConfigEntry[ha.Hub]
19 
20 
21 async def async_setup_entry(hass: HomeAssistant, entry: TriggercmdConfigEntry) -> bool:
22  """Set up TRIGGERcmd from a config entry."""
23  hub = ha.Hub(entry.data[CONF_TOKEN])
24 
25  status_code = await client.async_connection_test(entry.data[CONF_TOKEN])
26  if status_code != 200:
27  raise ConfigEntryNotReady
28 
29  entry.runtime_data = hub
30  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
31  return True
32 
33 
34 async def async_unload_entry(hass: HomeAssistant, entry: TriggercmdConfigEntry) -> bool:
35  """Unload a config entry."""
36  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, TriggercmdConfigEntry entry)
Definition: __init__.py:34
bool async_setup_entry(HomeAssistant hass, TriggercmdConfigEntry entry)
Definition: __init__.py:21