Im on the phone so its hard to read the handler here , for that function xiaomi has a ‘power outage memory’ setting on the device itself, and the handler has to be able to send the command to enable it. Problem I found (with the 02 CN plug model) is that it seems it requires a firmware update to get the zigbee attribute added if the firmware version is old (which requires a xiaomi/aqara gateway for the update).
The other way i see is to use the DeviceWatch so that when a device is considered offline time of offline is recorded and ‘last state’ saved, and when the plug connects back on, reads the value and forcebly re-enables it.