1 """The Anthem A/V Receivers integration."""
3 from __future__
import annotations
8 from anthemav.device_error
import DeviceError
16 from .const
import ANTHEMAV_UPDATE_SIGNAL, DEVICE_TIMEOUT_SECONDS
18 type AnthemavConfigEntry = ConfigEntry[anthemav.Connection]
20 PLATFORMS = [Platform.MEDIA_PLAYER]
22 _LOGGER = logging.getLogger(__name__)
26 """Set up Anthem A/V Receivers from a config entry."""
29 def async_anthemav_update_callback(message: str) ->
None:
30 """Receive notification from transport that new data exists."""
31 _LOGGER.debug(
"Received update callback from AVR: %s", message)
35 avr = await anthemav.Connection.create(
36 host=entry.data[CONF_HOST],
37 port=entry.data[CONF_PORT],
38 update_callback=async_anthemav_update_callback,
42 await avr.protocol.wait_for_device_initialised(DEVICE_TIMEOUT_SECONDS)
43 except (OSError, DeviceError)
as err:
44 raise ConfigEntryNotReady
from err
46 entry.runtime_data = avr
48 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
51 def close_avr(event: Event) ->
None:
54 entry.async_on_unload(
55 hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, close_avr)
62 """Unload a config entry."""
63 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
65 avr = entry.runtime_data
66 _LOGGER.debug(
"Close avr connection")
bool async_unload_entry(HomeAssistant hass, AnthemavConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, AnthemavConfigEntry entry)
None async_dispatcher_send(HomeAssistant hass, str signal, *Any args)