From 9d3fbfa975418386f7350aba8fe367c9c2be4be9 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Sun, 19 Mar 2017 15:53:40 +0100 Subject: [PATCH] Ignore OSError on socket.shutdown() This fixes #22 and obsoletes PR #23. --- pyHS100/protocol.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyHS100/protocol.py b/pyHS100/protocol.py index 50ecd8df..aa08d266 100644 --- a/pyHS100/protocol.py +++ b/pyHS100/protocol.py @@ -63,8 +63,14 @@ class TPLinkSmartHomeProtocol: break finally: - sock.shutdown(socket.SHUT_RDWR) - sock.close() + try: + sock.shutdown(socket.SHUT_RDWR) + sock.close() + except OSError: + # OSX raises OSError when shutdown() gets called on a closed + # socket. We ignore it here as the data has already been read + # into the buffer at this point. + pass response = TPLinkSmartHomeProtocol.decrypt(buffer[4:]) _LOGGER.debug("< (%i) %s", len(response), response)