2018-06-14 19:17:54 +00:00
|
|
|
"""Component to embed Google Cast."""
|
2018-08-09 11:24:14 +00:00
|
|
|
from homeassistant import config_entries
|
2018-06-14 19:17:54 +00:00
|
|
|
from homeassistant.helpers import config_entry_flow
|
|
|
|
|
|
|
|
|
|
|
|
DOMAIN = 'cast'
|
|
|
|
REQUIREMENTS = ['pychromecast==2.1.0']
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup(hass, config):
|
|
|
|
"""Set up the Cast component."""
|
2018-07-23 13:08:03 +00:00
|
|
|
conf = config.get(DOMAIN)
|
|
|
|
|
|
|
|
hass.data[DOMAIN] = conf or {}
|
|
|
|
|
|
|
|
if conf is not None:
|
|
|
|
hass.async_create_task(hass.config_entries.flow.async_init(
|
2018-08-09 11:24:14 +00:00
|
|
|
DOMAIN, context={'source': config_entries.SOURCE_IMPORT}))
|
2018-07-23 13:08:03 +00:00
|
|
|
|
2018-06-14 19:17:54 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass, entry):
|
|
|
|
"""Set up Cast from a config entry."""
|
2018-07-23 12:05:38 +00:00
|
|
|
hass.async_create_task(hass.config_entries.async_forward_entry_setup(
|
2018-06-14 19:17:54 +00:00
|
|
|
entry, 'media_player'))
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
async def _async_has_devices(hass):
|
|
|
|
"""Return if there are devices that can be discovered."""
|
|
|
|
from pychromecast.discovery import discover_chromecasts
|
|
|
|
|
2018-07-23 12:05:38 +00:00
|
|
|
return await hass.async_add_executor_job(discover_chromecasts)
|
2018-06-14 19:17:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
config_entry_flow.register_discovery_flow(
|
2018-09-17 08:12:46 +00:00
|
|
|
DOMAIN, 'Google Cast', _async_has_devices,
|
|
|
|
config_entries.CONN_CLASS_LOCAL_PUSH)
|