Python script to change brightness

Tags: #<Tag:0x00007f739f359908>

I created the script below however it doesn’t seem to be working.
What am I doing wrong?

import time.sleep

entity_id = data.get("entity_id")
rgb_color = data.get("rgb_color", [255, 219, 0])

if entity_id is not None:
  service_data = {"entity_id": entity_id, "rgb_color": rgb_color, "brightness": 1}"light", "turn_on", service_data, False)
  for x in range(2, 255):
    hass.states.set("light.my_light.attributes.brightness", x)