阅读小米网关组件代码理解问题
起因,自己的产品接入到ha中,开发属于自己的网关组件产品第一步阅读参考小米网关的代码,但是阅读过程中遇到障碍求助一下大神人物
def setup(hass, config):
"""Set up the Xiaomi component."""
gateways = []
interface = 'any'
discovery_retry = 3
if DOMAIN in config:
gateways = config
interface = config
discovery_retry = config
async def xiaomi_gw_discovered(service, discovery_info):# 问题1 这行代码是什么作用,没有看到具体的实现,
乍一看以为是一个函数??????
"""Perform action when Xiaomi Gateway device(s) has been found."""
# We don't need to do anything here, the purpose of Home Assistant's
# discovery service is to just trigger loading of this
# component, and then its own discovery process kicks in.
discovery.listen(hass, SERVICE_XIAOMI_GW, xiaomi_gw_discovered)
from xiaomi_gateway import XiaomiGatewayDiscovery
xiaomi = hass.data = XiaomiGatewayDiscovery(
hass.add_job, gateways, interface)
_LOGGER.debug("Expecting %s gateways", len(gateways))
for k in range(discovery_retry):
_LOGGER.info("Discovering Xiaomi Gateways (Try %s)", k + 1)
xiaomi.discover_gateways()
if len(xiaomi.gateways) >= len(gateways):
break
小米网关那行代码是什么作用实现在哪里呢 顶下 字面意思是异步函数,估计async有什么特殊的作用
这个东西就是个转接,主要靠的是pyxiaomigateway库
页:
[1]