original_docstring:  Handles updating the state of an entity.
  
      This handles the following paths:
      /api/states/<entity_id>
      
docstring: Handles updating the state of an entity.
  This handles the following paths:
  api/states/
docstring_tokens: Handles updating the state of an entity . This handles the following paths : api / states /
code: def _handle_post_state_entity(handler, path_match, data):
      """ Handles updating the state of an entity.
  
      This handles the following paths:
      /api/states/<entity_id>
      """
      entity_id = path_match.group('entity_id')
  
      try:
          new_state = data['state']
      except KeyError:
          handler.write_json_message("state not specified", HTTP_BAD_REQUEST)
          return
  
      attributes = data['attributes'] if 'attributes' in data else None
  
      is_new_state = handler.server.hass.states.get(entity_id) is None
  
      # Write state
      handler.server.hass.states.set(entity_id, new_state, attributes)
  
      state = handler.server.hass.states.get(entity_id)
  
      status_code = HTTP_CREATED if is_new_state else HTTP_OK
  
      handler.write_json(
          state.as_dict(),
          status_code=status_code,
          location=URL_API_STATES_ENTITY.format(entity_id))
code_tokens: def _handle_post_state_entity ( handler , path_match , data ) : entity_id = path_match . group ( 'entity_id' ) try : new_state = data [ 'state' ] except KeyError : handler . write_json_message ( "state not specified" , HTTP_BAD_REQUEST ) return attributes = data [ 'attributes' ] if 'attributes' in data else None is_new_state = handler . server . hass . states . get ( entity_id ) is None handler . server . hass . states . set ( entity_id , new_state , attributes ) state = handler . server . hass . states . get ( entity_id ) status_code = HTTP_CREATED if is_new_state else HTTP_OK handler . write_json ( state . as_dict ( ) , status_code = status_code , location = URL_API_STATES_ENTITY . format ( entity_id ) )
short_docstring: Handles updating the state of an entity.
short_docstring_tokens: Handles updating the state of an entity .
comment: """ Handles updating the state of an entity.
  
      This handles the following paths:
      /api/states/<entity_id>
      """$SEP$# Write state