Rework pin_state() to be usable from an alarm context