code: def wait_for_plug_update(self, plug_name, remote_state, timeout_s):
      
      plug = self._plugs_by_name.get(plug_name)
  
      if plug is None:
        raise InvalidPlugError('Cannot wait on unknown plug "%s".' % plug_name)
  
      if not isinstance(plug, FrontendAwareBasePlug):
        raise InvalidPlugError('Cannot wait on a plug %s that is not an subclass '
                               'of FrontendAwareBasePlug.' % plug_name)
  
      state, update_event = plug.asdict_with_event()
      if state != remote_state:
        return state
  
      if update_event.wait(timeout_s):
        return plug._asdict()
docs: Wait for a change in the state of a frontend-aware plug.
  
      Args:
        plug_name: Plug name, e.g. 'openhtf.plugs.user_input.UserInput'.
        remote_state: The last observed state.
        timeout_s: Number of seconds to wait for an update.
  
      Returns:
        An updated state, or None if the timeout runs out.
  
      Raises:
        InvalidPlugError: The plug can't be waited on either because it's not in
            use or it's not a frontend-aware plug.