Device Disconnect - Tag Quality Bad

I’m developing a module based on the current OPC-UA Device example. I want to have the tag quality of my tags set to bad after the device disconnects. How can this be achieved?