How to change the pin mode?

How to change the pin mode, for example, I have defined an output pin, but want to change from output mode to input mode in the following code, how do I operate?

There are a few platforms for inputs but you can start here and tell us if something specific

You didn’t post any code.

    on_turn_on:
      - lambda: id(output_led_1).mode = "output";    # wishful code
    on_turn_off:
      - lambda: id(output_led_1).mode = "input";    # wishful code

Is there a way to change the pin mode from input to output in reaction to an event?