original_docstring: Accept the POST request for push registrations from a browser.
docstring: Accept the POST request for push registrations from a browser.
docstring_tokens: Accept the POST request for push registrations from a browser .
code: async def post(self, request):
          """Accept the POST request for push registrations from a browser."""
          try:
              data = await request.json()
          except ValueError:
              return self.json_message('Invalid JSON', HTTP_BAD_REQUEST)
  
          try:
              data = REGISTER_SCHEMA(data)
          except vol.Invalid as ex:
              return self.json_message(
                  humanize_error(data, ex), HTTP_BAD_REQUEST)
  
          name = self.find_registration_name(data)
          previous_registration = self.registrations.get(name)
  
          self.registrations[name] = data
  
          try:
              hass = request.app['hass']
  
              await hass.async_add_job(save_json, self.json_path,
                                       self.registrations)
              return self.json_message(
                  'Push notification subscriber registered.')
          except HomeAssistantError:
              if previous_registration is not None:
                  self.registrations[name] = previous_registration
              else:
                  self.registrations.pop(name)
  
              return self.json_message(
                  'Error saving registration.', HTTP_INTERNAL_SERVER_ERROR)
code_tokens: async def post ( self , request ) : try : data = await request . json ( ) except ValueError : return self . json_message ( 'Invalid JSON' , HTTP_BAD_REQUEST ) try : data = REGISTER_SCHEMA ( data ) except vol . Invalid as ex : return self . json_message ( humanize_error ( data , ex ) , HTTP_BAD_REQUEST ) name = self . find_registration_name ( data ) previous_registration = self . registrations . get ( name ) self . registrations [ name ] = data try : hass = request . app [ 'hass' ] await hass . async_add_job ( save_json , self . json_path , self . registrations ) return self . json_message ( 'Push notification subscriber registered.' ) except HomeAssistantError : if previous_registration is not None : self . registrations [ name ] = previous_registration else : self . registrations . pop ( name ) return self . json_message ( 'Error saving registration.' , HTTP_INTERNAL_SERVER_ERROR )
short_docstring: Accept the POST request for push registrations from a browser.
short_docstring_tokens: Accept the POST request for push registrations from a browser .
comment: """Accept the POST request for push registrations from a browser."""