Example #1
0
    def run(self):
        zc = Zeroconf()

        def on_update(dat):
            for key, b in dat.items():
                PING_RESULT[key] = b

        stat = DashboardStatus(zc, on_update)
        stat.start()
        while not STOP_EVENT.is_set():
            entries = _list_dashboard_entries()
            stat.request_query({entry.filename: entry.name + '.local.' for entry in entries})

            PING_REQUEST.wait()
            PING_REQUEST.clear()
        stat.stop()
        stat.join()
        zc.close()
Example #2
0
def _resolve_with_zeroconf(host):
    from esphome.core import EsphomeError
    try:
        zc = Zeroconf()
    except Exception:
        raise EsphomeError(
            "Cannot start mDNS sockets, is this a docker container without "
            "host network mode?")
    try:
        info = zc.resolve_host(host + '.')
    except Exception as err:
        raise EsphomeError("Error resolving mDNS hostname: {}".format(err))
    finally:
        zc.close()
    if info is None:
        raise EsphomeError(
            "Error resolving address with mDNS: Did not respond. "
            "Maybe the device is offline.")
    return info