Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DiscoveryProtocol part of the public API #524

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rytilahti
Copy link
Member

This makes it easier to perform different type of discovery strategies by the library users, e.g., to send out discoveries to multiple targets using a single discovery protocol instance.

Fixes #517

@rytilahti rytilahti added the enhancement New feature or request label Oct 5, 2023
This makes it easier to perform different type of discovery strategies by the library users, e.g., to send out discoveries to multiple targets using a single discovery protocol instance.
@rytilahti rytilahti force-pushed the feat/expose_discovery_protocol branch from 46199e3 to 434b730 Compare October 5, 2023 12:35
@codecov
Copy link

codecov bot commented Oct 5, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Files Coverage Δ
kasa/__init__.py 100.00% <100.00%> (ø)
kasa/discover.py 83.56% <81.81%> (-0.58%) ⬇️

📢 Thoughts on this report? Let us know!.

@rytilahti
Copy link
Member Author

I'm not sure what's wrong with this, but the unicast discoveries are not being replied by devices. kasa --target 192.168.1.123 discover does not yield any responses where targeting the broadcast address does.

Likewise, I'm not seeing any replies (nor outgoing datagrams, fwiw) when using a script like this:

import asyncio
from kasa import DiscoveryProtocol
from ipaddress import ip_network
from typing import cast


async def on_discovered_callback(dev):
    """handle discovered devices."""
    print(dev)


async def discover_multi(*hosts):
    loop = asyncio.get_event_loop()
    transport, protocol = await loop.create_datagram_endpoint(
        lambda: DiscoveryProtocol(on_discovered=on_discovered_callback),
        local_addr=("0.0.0.0", 0),
    )
    protocol = cast(DiscoveryProtocol, protocol)
    for host in hosts:
        protocol.do_discover(str(host))

    transport.close()
    await asyncio.sleep(5)


asyncio.run(
    discover_multi(
        *ip_network("192.168.xx.0/24").hosts()
    )
)

Looking at the packet trace, it looks like the datagrams are not even been sent out but rather blocked by the kernel?!

@pdumais
Copy link

pdumais commented Oct 8, 2023

Let give this a try. I don't see why it wouldn't work. Maybe an environment thing? I'll have some time this week, I'll get back to you.

@pdumais
Copy link

pdumais commented Oct 8, 2023

Tcpdump shows that the packets are going out alright. But not to all hosts, only a few random ones. Very strange

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for discovery from within a docker container
2 participants