original_docstring:  Handles adding an event forwarding target. 
docstring: Handles adding an event forwarding target.
docstring_tokens: Handles adding an event forwarding target .
code: def _handle_post_api_event_forward(handler, path_match, data):
      """ Handles adding an event forwarding target. """
  
      try:
          host = data['host']
          api_password = data['api_password']
      except KeyError:
          handler.write_json_message(
              "No host or api_password received.", HTTP_BAD_REQUEST)
          return
  
      try:
          port = int(data['port']) if 'port' in data else None
      except ValueError:
          handler.write_json_message(
              "Invalid value received for port", HTTP_UNPROCESSABLE_ENTITY)
          return
  
      api = rem.API(host, api_password, port)
  
      if not api.validate_api():
          handler.write_json_message(
              "Unable to validate API", HTTP_UNPROCESSABLE_ENTITY)
          return
  
      if handler.server.event_forwarder is None:
          handler.server.event_forwarder = \
              rem.EventForwarder(handler.server.hass)
  
      handler.server.event_forwarder.connect(api)
  
      handler.write_json_message("Event forwarding setup.")
code_tokens: def _handle_post_api_event_forward ( handler , path_match , data ) : try : host = data [ 'host' ] api_password = data [ 'api_password' ] except KeyError : handler . write_json_message ( "No host or api_password received." , HTTP_BAD_REQUEST ) return try : port = int ( data [ 'port' ] ) if 'port' in data else None except ValueError : handler . write_json_message ( "Invalid value received for port" , HTTP_UNPROCESSABLE_ENTITY ) return api = rem . API ( host , api_password , port ) if not api . validate_api ( ) : handler . write_json_message ( "Unable to validate API" , HTTP_UNPROCESSABLE_ENTITY ) return if handler . server . event_forwarder is None : handler . server . event_forwarder = rem . EventForwarder ( handler . server . hass ) handler . server . event_forwarder . connect ( api ) handler . write_json_message ( "Event forwarding setup." )
short_docstring: Handles adding an event forwarding target.
short_docstring_tokens: Handles adding an event forwarding target .
comment: """ Handles adding an event forwarding target. """