Fix #602 by keeping track of device state internally