The device is a microswitch.
The metal tab gets pushed in (toward the blue body) which closes the switch between the 2 wires.
I bet it was positioned to detect when the hood is open or closed.
Hyundai Forum is a community for all Hyundai Owners to talk and learn all about their favorite subject: Hyundai cars from the Sonata to the Elantra and even the new Kona!