1 """Deal with Cast discovery."""
16 INTERNAL_DISCOVERY_RUNNING_KEY,
17 SIGNAL_CAST_DISCOVERED,
20 from .helpers
import ChromecastInfo, ChromeCastZeroconf
22 _LOGGER = logging.getLogger(__name__)
26 hass: HomeAssistant, cast_info: pychromecast.models.CastInfo
28 """Discover a Chromecast."""
35 _LOGGER.error(
"Discovered chromecast without uuid %s", info)
38 info = info.fill_out_missing_chromecast_info(hass)
39 _LOGGER.debug(
"Discovered new or updated chromecast %s", info)
46 _LOGGER.debug(
"Removed chromecast %s", info)
52 """Set up the pychromecast internal discovery."""
53 if INTERNAL_DISCOVERY_RUNNING_KEY
not in hass.data:
54 hass.data[INTERNAL_DISCOVERY_RUNNING_KEY] = threading.Lock()
56 if not hass.data[INTERNAL_DISCOVERY_RUNNING_KEY].acquire(blocking=
False):
60 class CastListener(pychromecast.discovery.AbstractCastListener):
61 """Listener for discovering chromecasts."""
63 def add_cast(self, uuid, _):
64 """Handle zeroconf discovery of a new chromecast."""
67 def update_cast(self, uuid, _):
68 """Handle zeroconf discovery of an updated chromecast."""
71 def remove_cast(self, uuid, service, cast_info):
72 """Handle zeroconf discovery of a removed chromecast."""
80 _LOGGER.debug(
"Starting internal pychromecast discovery")
81 browser = pychromecast.discovery.CastBrowser(
83 ChromeCastZeroconf.get_zeroconf(),
84 config_entry.data.get(CONF_KNOWN_HOSTS),
86 hass.data[CAST_BROWSER_KEY] = browser
87 browser.start_discovery()
89 def stop_discovery(event):
90 """Stop discovery of new chromecasts."""
91 _LOGGER.debug(
"Stopping internal pychromecast discovery")
92 browser.stop_discovery()
93 hass.data[INTERNAL_DISCOVERY_RUNNING_KEY].release()
95 hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_discovery)
97 config_entry.add_update_listener(config_entry_updated)
101 """Handle config entry being updated."""
102 browser = hass.data[CAST_BROWSER_KEY]
103 browser.host_browser.update_hosts(config_entry.data.get(CONF_KNOWN_HOSTS))
None discover_chromecast(HomeAssistant hass, pychromecast.models.CastInfo cast_info)
None setup_internal_discovery(HomeAssistant hass, ConfigEntry config_entry)
None config_entry_updated(HomeAssistant hass, ConfigEntry config_entry)
None _remove_chromecast(HomeAssistant hass, ChromecastInfo info)
None dispatcher_send(HomeAssistant hass, str signal, *Any args)