(self)
Queries the Chromecast for the current status.
        Starts a websocket client if possible.
Queries the Chromecast for the current status.
        Starts a websocket client if possible.
Queries the Chromecast for the current status . Starts a websocket client if possible .
def refresh(self):
        """
        Queries the Chromecast for the current status.
        Starts a websocket client if possible.
        """
        self.logger.info("Refreshing app status")

        # If we are refreshing but a refresh was planned, cancel that one
        with self._refresh_lock:
            if self._refresh_timer:
                self._refresh_timer.cancel()
                self._refresh_timer = None

        cur_app = self.app
        cur_ws = self.websocket_client

        self.app = app = get_app_status(self.host)

        # If no previous app and no new app there is nothing to do
        if not cur_app and not app:
            is_diff_app = False
        else:
            is_diff_app = (not cur_app and app or cur_app and not app or
                           cur_app.app_id != app.app_id)

        # Clean up websocket if:
        #  - there is a different app and a connection exists
        #  - if it is the same app but the connection is terminated
        if cur_ws and (is_diff_app or cur_ws.terminated):

            if not cur_ws.terminated:
                cur_ws.close_connection()

            self.websocket_client = cur_ws = None

        # Create a new websocket client if there is no connection
        if not cur_ws and app:

            try:
                # If the current app is not capable of a websocket client
                # This method will return None so nothing is lost
                self.websocket_client = cur_ws = create_websocket_client(app)

            except ConnectionError:
                pass

            # Ramp service does not always immediately show up in the app
            # status. If we do not have a websocket client but the app is
            # known to be RAMP controllable, then plan refresh.
            if not cur_ws and app.app_id in RAMP_ENABLED:
                self._delayed_refresh()
def refresh ( self ) : self . logger . info ( "Refreshing app status" ) # If we are refreshing but a refresh was planned, cancel that one with self . _refresh_lock : if self . _refresh_timer : self . _refresh_timer . cancel ( ) self . _refresh_timer = None cur_app = self . app cur_ws = self . websocket_client self . app = app = get_app_status ( self . host ) # If no previous app and no new app there is nothing to do if not cur_app and not app : is_diff_app = False else : is_diff_app = ( not cur_app and app or cur_app and not app or cur_app . app_id != app . app_id ) # Clean up websocket if: #  - there is a different app and a connection exists #  - if it is the same app but the connection is terminated if cur_ws and ( is_diff_app or cur_ws . terminated ) : if not cur_ws . terminated : cur_ws . close_connection ( ) self . websocket_client = cur_ws = None # Create a new websocket client if there is no connection if not cur_ws and app : try : # If the current app is not capable of a websocket client # This method will return None so nothing is lost self . websocket_client = cur_ws = create_websocket_client ( app ) except ConnectionError : pass # Ramp service does not always immediately show up in the app # status. If we do not have a websocket client but the app is # known to be RAMP controllable, then plan refresh. if not cur_ws and app . app_id in RAMP_ENABLED : self . _delayed_refresh ( )