TomerFi / aioswitcher

PyPi module integrating with various Switcher devices
https://aioswitcher.tomfi.info
Apache License 2.0
30 stars 18 forks source link

Code inside a docker not discover devices #530

Closed dolby360 closed 2 years ago

dolby360 commented 2 years ago

What happened?

The following setup doesn't show me any results The same code works on windows. Any ideas?

FROM python:3.10.6-slim-buster
WORKDIR /usr/src/app
RUN apt update && apt upgrade -y && apt install  iputils-ping -y
COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY . .

requirements.txt

aioswitcher
asyncio
from argparse import ArgumentParser
from asyncio import get_event_loop, sleep
from dataclasses import asdict
from pprint import PrettyPrinter

from aioswitcher.bridge import SwitcherBridge
from aioswitcher.device import SwitcherBase

printer = PrettyPrinter(indent=4)

parser = ArgumentParser(description="Discover and print info of Switcher devices")
parser.add_argument(
    "delay",
    help="number of seconds to run, defaults to 60",
    type=int,
    nargs="?",
    default=10,
)

async def print_devices(delay: int) -> None:
    """Run the Switcher bridge and register callback for discovered devices."""

    def on_device_found_callback(device: SwitcherBase) -> None:
        """Use as a callback printing found devices."""
        # printer.pprint(asdict(device))
        print("here :)")
        print(asdict(device))

    async with SwitcherBridge(on_device_found_callback):
        await sleep(delay)

if __name__ == "__main__":
    args = parser.parse_args()

    try:
        get_event_loop().run_until_complete(print_devices(args.delay))
    except KeyboardInterrupt:
        exit()

Although I can ping the device IP.

Module Version

2.0.9

Device Type

Switcher Touch (V3)

Firmware Version

I'm not sure

Relevant log output

No response

welcome[bot] commented 2 years ago

Thanks for opening your first issue here!

thecode commented 2 years ago

You need to forward the following ports to the docker for the discovery to work: https://github.com/TomerFi/aioswitcher/blob/14ac4e4d8852b5696af10ca10967bec8349bd291/src/aioswitcher/bridge.py#L48-L51

dolby360 commented 2 years ago

@thecode this way?

docker run -it -p 20002:20002 switch_client /bin/bash

Because it's not working I have to say that this is not working on wsl as well

thecode commented 2 years ago

Try: -p "20002:20002/udp"

I started to write a note above that sometimes it didn't work and deleted it since I was not sure what is the current status. As for WSL I never got it to forward broadcasts, I don't think it is possible.

dolby360 commented 2 years ago

@thecode That works thank you very much