diff --git a/pyisy/events/tcpsocket.py b/pyisy/events/tcpsocket.py index 54a6734..81d6d44 100644 --- a/pyisy/events/tcpsocket.py +++ b/pyisy/events/tcpsocket.py @@ -211,10 +211,10 @@ def subscribe(self): def unsubscribe(self): """Unsubscribe from the Event Stream.""" if self._subscribed and self._connected: - msg = self._create_message(strings.UNSUB_MSG) try: + msg = self._create_message(strings.UNSUB_MSG) self.write(msg) - except OSError as ex: + except (OSError, KeyError) as ex: _LOGGER.error( "PyISY encountered a socket error while writing unsubscribe message to the socket: %s.", ex,