device:online() isn’t a command that is sent to the device. It is a state that the device instance “emits”.
There is not a callback for online/offline and we suggest that wherever you set that value you can run other necessary commands/functions.
For example:
You could check the device’s online status and generate an internal event or save it in persistent storage as the “last_health_status” (device:set_field(), device:get_field()). That is similar to the variable state we used in Groovy.