@@ -1163,15 +1163,14 @@ def listener(self, name, m):
11631163 def listener (self , name , m ):
11641164 self ._armed = (m .base_mode & mavutil .mavlink .MAV_MODE_FLAG_SAFETY_ARMED ) != 0
11651165 self .notify_attribute_listeners ('armed' , self .armed , cache = True )
1166- if self ._master .mode_mapping () != None :
1167- flightmodesById = {v : k for k , v in self ._master .mode_mapping ().items ()}
1168- if m .custom_mode in flightmodesById :
1169- self ._flightmode = flightmodesById [m .custom_mode ]
1166+ self ._autopilot_type = m .autopilot
1167+ self ._vehicle_type = m .type
1168+ if self ._is_mode_available (m .custom_mode ) == False :
1169+ raise APIException ("mode %s not available on mavlink definition" % m .custom_mode )
1170+ self ._flightmode = self ._mode_mapping_bynumber [m .custom_mode ]
11701171 self .notify_attribute_listeners ('mode' , self .mode , cache = True )
11711172 self ._system_status = m .system_status
11721173 self .notify_attribute_listeners ('system_status' , self .system_status , cache = True )
1173- self ._autopilot_type = m .autopilot
1174- self ._vehicle_type = m .type
11751174
11761175 # Waypoints.
11771176
@@ -1493,6 +1492,13 @@ def flush(self):
14931492 def _mode_mapping (self ):
14941493 return self ._master .mode_mapping ()
14951494
1495+ @property
1496+ def _mode_mapping_bynumber (self ):
1497+ return mavutil .mode_mapping_bynumber (self ._vehicle_type )
1498+
1499+ def _is_mode_available (self , mode_code ):
1500+ return mode_code in self ._mode_mapping_bynumber
1501+
14961502 #
14971503 # Operations to support the standard API.
14981504 #
0 commit comments