def discover(timeout=DISCOVERY_TIMEOUT):
hosts = {}<EOL>payload = MAGIC + DISCOVERY<EOL>for _ in range(RETRIES):<EOL><INDENT>_SOCKET.sendto(bytearray(payload), ('<STR_LIT>', PORT))<EOL>start = time.time()<EOL>while time.time() < start + timeout:<EOL><INDENT>for host, data in _BUFFER.copy().items():<EOL><INDENT>if not _is_discovery_response(data):<EOL><INDENT>continue<EOL><DEDENT>if host not in hosts:<EOL><INDENT>_LOGGER.debug("<STR_LIT>", host)<EOL>entry = {}<EOL>entry['<STR_LIT>'] = data[<NUM_LIT:7>:<NUM_LIT>]<EOL>entry['<STR_LIT>'] = data[<NUM_LIT>:<NUM_LIT>]<EOL>entry['<STR_LIT>'] = <NUM_LIT:0><EOL>entry['<STR_LIT>'] = int(data[-<NUM_LIT:1>])<EOL>entry['<STR_LIT:time>'] = _device_time(data[<NUM_LIT>:<NUM_LIT>])<EOL>entry['<STR_LIT>'] = int(time.time())<EOL>hosts[host] = entry<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return hosts<EOL>
Discover devices on the local network.

    :param timeout: Optional timeout in seconds.
    :returns: Set of discovered host addresses.