Write-access to /sys

What do I need to write to /sys from my flatpak?

Specifically I want to toggle some system leds via /sys/class/leds.

I found one method, which is to use flatpak-spawn and pkexec to open the file in a child process:

        let mut child = Command::new("flatpak-spawn")
            .args(["--host", "pkexec", "sh", "-c", &format!("echo ready && cat > /sys/class/leds/{led}/brightness")])
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()?;

        let mut stdout = child.stdout.take().ok_or_else(|| anyhow!("no stdout"))?;
        let stdin = child.stdin.take().ok_or_else(|| anyhow!("no stdin"))?;

        // block until pkexec authenticates and sh prints "ready"
        let mut buf = [0u8; 6];
        stdout.read(&mut buf)?;