A man who exposed himself in Sunderland believed he was taking his clothes off at home while getting ready for bed, a court heard.