GadgetReactor / pyHS100

Python Library to control TPLink Switch (HS100 / HS110)
Other
409 stars 128 forks source link

Specify broadcast address for discovery #176

Closed kochinc closed 5 years ago

kochinc commented 5 years ago

Sometimes it's useful to be able to specify the broadcast address for discovery. On a host with multiple network interfaces, when a discovery message is sent to 255.255.255.255:9999, the routing table decides which interface it is routed to. By specifying broadcast address, e.g. 192.168.xxx.255, the discovery message can be directed to a particular subnet only.

The modification to discover.py is very limited and shouldn't affect existing programs using the library. The cli.py is changed to include a --target option for specifying broadcast address.

coveralls commented 5 years ago

Coverage Status

Coverage increased (+0.08%) to 80.357% when pulling 70227bedee1a47a1d44c5bf256c0a1e08c5e9f00 on kochinc:master into 2d60467beab8c95ec3006a559a4a98bae830ba89 on GadgetReactor:master.

kirichkov commented 5 years ago

Looks fine to me, I have only one question: do you think it's better to have an address instead of an interface name for this?

Not sure whether this was directed at me, or @kochinc, my general preference is to deal with interfaces, rather than IP addresses - network ranges change, interfaces generally stay the same. If go for interfaces, however, how do we address the 'broadcast' since broadcast should send to all interfaces? Perhaps a interface='all' keyword argument?

kochinc commented 5 years ago

Either way it's fine for me. At first I wanted to add an interface parameter. After inspected the code, I realized it's very simple to just include a broadcast target address parameter. That solved my issue with TP-Link device discovery on Home Assistant.

jkriegshauser commented 3 years ago

Would it be possible to get a release with this merged so that we can get Home Assistant working with Kasa on different subnets before python-kasa is integrated?