"settings" map occasionally misses a couple devices when accessing keySet

I am trying to report the state of all my devices whenever one of the devices change. The following method gets called whenever a device in my preferences section fires an event:

def getAllDevices() {
	def devices = []
    for (String key : settings.keySet()) {
    	settings["$key"].each { device ->
            devices << device

	return devices

However, if two events fire, I sometimes get 2 different results. I have 12 devices connected… The first time an event fires the getAllDevices method returns a list of 12 devices (which is perfect), but the second time getAllDevices is called (when another device fires an event) it will return a list of 10 devices (the relay switch and presence sensor won’t show up).
This started happening after I added PresenceSensor and RelaySwitch into the preferences section of my app.

Does anyone have any idea what might be going on here?