Skip to content

Commit

Permalink
feat: include bridge port 10002, used in new devices in broadcast dis…
Browse files Browse the repository at this point in the history
…covery (#642)

* add new port for broadcast discovery

* add new port for discover_devices script

* add docs
  • Loading branch information
liadav authored Apr 10, 2023
1 parent 667c3a3 commit aa07716
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ devices broadcasting on the local network for 60 seconds.
You can change the delay by passing an int argument: discover_devices.py 30

Switcher devices uses two protocol types:
Protocol type 1 (UDP port 20002), used by: Switcher Mini, Switcher Power Plug, Switcher Touch, Switcher V2 (esp), Switcher V2 (qualcomm), Switcher V4
Protocol type 1 (UDP port 20002 or port 10002), used by: Switcher Mini, Switcher Power Plug, Switcher Touch, Switcher V2 (esp), Switcher V2 (qualcomm), Switcher V4
Protocol type 2 (UDP port 20003), used by: Switcher Breeze, Switcher Runner, Switcher Runner Mini
You can change the scanned protocol type by passing an int argument: discover_devices.py -t 1

Expand Down
11 changes: 8 additions & 3 deletions scripts/discover_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from aioswitcher.bridge import (
SWITCHER_UDP_PORT_TYPE1,
SWITCHER_UDP_PORT_TYPE1_NEW_VERSION,
SWITCHER_UDP_PORT_TYPE2,
SwitcherBridge,
)
Expand All @@ -37,7 +38,7 @@
You can change the delay by passing an int argument: discover_devices.py 30
Switcher devices uses two protocol types:
Protocol type 1 (UDP port 20002), used by: """
Protocol type 1 (UDP port 20002 or 10002), used by: """
+ ", ".join(d.value for d in DeviceType if d.protocol_type == 1)
+ """
Protocol type 2 (UDP port 20003), used by: """
Expand Down Expand Up @@ -115,11 +116,15 @@ def on_device_found_callback(device: SwitcherBase) -> None:
args = parser.parse_args()

if args.type == "1":
ports = [SWITCHER_UDP_PORT_TYPE1]
ports = [SWITCHER_UDP_PORT_TYPE1, SWITCHER_UDP_PORT_TYPE1_NEW_VERSION]
elif args.type == "2":
ports = [SWITCHER_UDP_PORT_TYPE2]
else:
ports = [SWITCHER_UDP_PORT_TYPE1, SWITCHER_UDP_PORT_TYPE2]
ports = [
SWITCHER_UDP_PORT_TYPE1,
SWITCHER_UDP_PORT_TYPE1_NEW_VERSION,
SWITCHER_UDP_PORT_TYPE2,
]

try:
asyncio.run(print_devices(args.delay, ports))
Expand Down
10 changes: 8 additions & 2 deletions src/aioswitcher/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

# Protocol type 1 devices: V2, Touch, V4, Mini, Power Plug
SWITCHER_UDP_PORT_TYPE1 = 20002
SWITCHER_UDP_PORT_TYPE1_NEW_VERSION = 10002
# Protocol type 2 devices: Breeze, Runner, Runner Mini
SWITCHER_UDP_PORT_TYPE2 = 20003

Expand Down Expand Up @@ -166,14 +167,19 @@ class SwitcherBridge:
Args:
on_device: a callable to which every new SwitcherBase device found will be send.
broadcast_ports: broadcast ports list, default for type 1 devices is 20002,
default for type 2 devices is 20003
default for type 2 devices is 20003.
On newer type1 devices, the port is 10002.
"""

def __init__(
self,
on_device: Callable[[SwitcherBase], Any],
broadcast_ports: List[int] = [SWITCHER_UDP_PORT_TYPE1, SWITCHER_UDP_PORT_TYPE2],
broadcast_ports: List[int] = [
SWITCHER_UDP_PORT_TYPE1,
SWITCHER_UDP_PORT_TYPE1_NEW_VERSION,
SWITCHER_UDP_PORT_TYPE2,
],
) -> None:
"""Initialize the switcher bridge."""
self._on_device = on_device
Expand Down

0 comments on commit aa07716

Please sign in to comment.