You can use
RegisterAttributeDriver() to securely swap the unit of a
SecureUnitFrame. Just use this to replace the entire
self.frame.state block.
Code:
RegisterAttributeDriver(self.frame,"unit","[vehicleui] player; pet")
Updating the frame when this happens can be done with an
OnAttributeChanged script hook. Since I highly doubt you're doing anything protected in
PlayerPet:UpdateDisplay(), you can just call that.
Code:
self.frame:HookScript("OnAttributeChanged",function() PlayerPet:UpdateDisplay(); end)