本文整理汇总了Python中homeassistant.helpers.typing.HomeAssistantType.data[INTERNAL_DISCOVERY_RUNNING_KEY]方法的典型用法代码示例。如果您正苦于以下问题:Python HomeAssistantType.data[INTERNAL_DISCOVERY_RUNNING_KEY]方法的具体用法?Python HomeAssistantType.data[INTERNAL_DISCOVERY_RUNNING_KEY]怎么用?Python HomeAssistantType.data[INTERNAL_DISCOVERY_RUNNING_KEY]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类homeassistant.helpers.typing.HomeAssistantType
的用法示例。
在下文中一共展示了HomeAssistantType.data[INTERNAL_DISCOVERY_RUNNING_KEY]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _setup_internal_discovery
# 需要导入模块: from homeassistant.helpers.typing import HomeAssistantType [as 别名]
# 或者: from homeassistant.helpers.typing.HomeAssistantType import data[INTERNAL_DISCOVERY_RUNNING_KEY] [as 别名]
def _setup_internal_discovery(hass: HomeAssistantType) -> None:
"""Set up the pychromecast internal discovery."""
if INTERNAL_DISCOVERY_RUNNING_KEY not in hass.data:
hass.data[INTERNAL_DISCOVERY_RUNNING_KEY] = threading.Lock()
if not hass.data[INTERNAL_DISCOVERY_RUNNING_KEY].acquire(blocking=False):
# Internal discovery is already running
return
import pychromecast
def internal_callback(name):
"""Called when zeroconf has discovered a new chromecast."""
mdns = listener.services[name]
_discover_chromecast(hass, ChromecastInfo(*mdns))
_LOGGER.debug("Starting internal pychromecast discovery.")
listener, browser = pychromecast.start_discovery(internal_callback)
def stop_discovery(event):
"""Stop discovery of new chromecasts."""
_LOGGER.debug("Stopping internal pychromecast discovery.")
pychromecast.stop_discovery(browser)
hass.data[INTERNAL_DISCOVERY_RUNNING_KEY].release()
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_discovery)
示例2: _setup_internal_discovery
# 需要导入模块: from homeassistant.helpers.typing import HomeAssistantType [as 别名]
# 或者: from homeassistant.helpers.typing.HomeAssistantType import data[INTERNAL_DISCOVERY_RUNNING_KEY] [as 别名]
def _setup_internal_discovery(hass: HomeAssistantType) -> None:
"""Set up the pychromecast internal discovery."""
if INTERNAL_DISCOVERY_RUNNING_KEY not in hass.data:
hass.data[INTERNAL_DISCOVERY_RUNNING_KEY] = threading.Lock()
if not hass.data[INTERNAL_DISCOVERY_RUNNING_KEY].acquire(blocking=False):
# Internal discovery is already running
return
import pychromecast
def internal_add_callback(name):
"""Handle zeroconf discovery of a new chromecast."""
mdns = listener.services[name]
_discover_chromecast(hass, ChromecastInfo(
service=name,
host=mdns[0],
port=mdns[1],
uuid=mdns[2],
model_name=mdns[3],
friendly_name=mdns[4],
))
def internal_remove_callback(name, mdns):
"""Handle zeroconf discovery of a removed chromecast."""
_remove_chromecast(hass, ChromecastInfo(
service=name,
host=mdns[0],
port=mdns[1],
uuid=mdns[2],
model_name=mdns[3],
friendly_name=mdns[4],
))
_LOGGER.debug("Starting internal pychromecast discovery.")
listener, browser = pychromecast.start_discovery(internal_add_callback,
internal_remove_callback)
ChromeCastZeroconf.set_zeroconf(browser.zc)
def stop_discovery(event):
"""Stop discovery of new chromecasts."""
_LOGGER.debug("Stopping internal pychromecast discovery.")
pychromecast.stop_discovery(browser)
hass.data[INTERNAL_DISCOVERY_RUNNING_KEY].release()
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_discovery)