Upgrade KWin script to detect screen about to turn off and wake

Some years ago I developed a KWin script to use CEC device to turn the screen on and off automatically using a KWin script.
My old post is here: Determine when monitor is turned on or off via python dbus - #14 by supagu

I have some some code that used to work (I think it was using Qt5), now it appears not to work (My computer is using Qt6):

The problem is with this line of code:
firstScreen.aboutToTurnOff.connect(aboutToTurnOff)

Gives me the error:
/home/server/.local/share/kwin/scripts/cec_kwin/contents/code/main.js:22: error: Cannot call method ‘connect’ of undefined

It seems that “aboutToTurnOff” is no longer available.
Was this renamed or is there some other method to detect this now?

I can’t seem to find any good KWin script documentation.

Not an answer, but the question has also been asked here: