Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Base class for assist satellite entities."""
2 
3 import logging
4 
5 import voluptuous as vol
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers import config_validation as cv
10 from homeassistant.helpers.entity_component import EntityComponent
11 from homeassistant.helpers.typing import ConfigType
12 
13 from .connection_test import ConnectionTestView
14 from .const import (
15  CONNECTION_TEST_DATA,
16  DATA_COMPONENT,
17  DOMAIN,
18  AssistSatelliteEntityFeature,
19 )
20 from .entity import (
21  AssistSatelliteAnnouncement,
22  AssistSatelliteConfiguration,
23  AssistSatelliteEntity,
24  AssistSatelliteEntityDescription,
25  AssistSatelliteWakeWord,
26 )
27 from .errors import SatelliteBusyError
28 from .websocket_api import async_register_websocket_api
29 
30 __all__ = [
31  "DOMAIN",
32  "AssistSatelliteAnnouncement",
33  "AssistSatelliteEntity",
34  "AssistSatelliteConfiguration",
35  "AssistSatelliteEntityDescription",
36  "AssistSatelliteEntityFeature",
37  "AssistSatelliteWakeWord",
38  "SatelliteBusyError",
39 ]
40 
41 _LOGGER = logging.getLogger(__name__)
42 
43 PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
44 
45 
46 async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
47  component = hass.data[DATA_COMPONENT] = EntityComponent[AssistSatelliteEntity](
48  _LOGGER, DOMAIN, hass
49  )
50  await component.async_setup(config)
51 
52  component.async_register_entity_service(
53  "announce",
54  vol.All(
55  cv.make_entity_service_schema(
56  {
57  vol.Optional("message"): str,
58  vol.Optional("media_id"): str,
59  }
60  ),
61  cv.has_at_least_one_key("message", "media_id"),
62  ),
63  "async_internal_announce",
64  [AssistSatelliteEntityFeature.ANNOUNCE],
65  )
66  hass.data[CONNECTION_TEST_DATA] = {}
68  hass.http.register_view(ConnectionTestView())
69 
70  return True
71 
72 
73 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
74  """Set up a config entry."""
75  return await hass.data[DATA_COMPONENT].async_setup_entry(entry)
76 
77 
78 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
79  """Unload a config entry."""
80  return await hass.data[DATA_COMPONENT].async_unload_entry(entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:73
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:78
bool async_setup(HomeAssistant hass, ConfigType config)
Definition: __init__.py:46