'Check if the websocket is setup and connected.'

def get_ws(self):

    if (self._ws is None):
        try:
            self._ws = self._connection(self._url, timeout=1)
            msg = json.dumps({'namespace': 'connect', 'method': 'connect', 'arguments': ['Home    Assistant', self._authorization_code]})
            self._ws.send(msg)
        except (socket.timeout, ConnectionRefusedError, ConnectionResetError):
            self._ws = None
    return self._ws
