sermayoral / ha-samsungtv-encrypted

Samsung TV Encrypted Models (H & J Series) custom component for Home Assistant
Apache License 2.0
38 stars 24 forks source link

I use hostnames on my network, this makes ssdp work #45

Closed nashant closed 4 years ago

sermayoral commented 4 years ago

@nashant

Please, help me to understand this part of code:

    try:
        ipaddress.ip_address(host)
    except:
        host = socket.gethostbyname(host)
    if host not in known_devices:

What happen if the 'try' part succeed? Shouldn't be the following?

    try:
        host = ipaddress.ip_address(host)
    except:
        host = socket.gethostbyname(host)
    if host not in known_devices:

Thanks

nashant commented 4 years ago

The try is just to check if host is already an ip address. If it is not and it is a dns name instead then it will resolve the dns to an ip

On Wed, 29 Jul 2020, 10:55 Sergio Mayoral Martínez, < notifications@github.com> wrote:

@nashant https://github.com/nashant

Please, help me to understand this part of code:

try:
    ipaddress.ip_address(host)
except:
    host = socket.gethostbyname(host)
if host not in known_devices:

What happen if the 'try' part succeed? Shouldn't be the following?

try:
    **host =** ipaddress.ip_address(host)
except:
    host = socket.gethostbyname(host)
if host not in known_devices:

Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sermayoral/ha-samsungtv-encrypted/pull/45#issuecomment-665565207, or unsubscribe https://github.com/notifications/unsubscribe-auth/AATNTOBCPJVWBEVHT6VWIJTR57WYNANCNFSM4OXGU3RQ .

sermayoral commented 4 years ago

@nashant Ok, I have understood. Thanks!