'Check if interface is valid
:param self: A NetworkManager object
:param interface_name: Name of an interface
:param mode: The mode of the interface to be checked
:type self: NetworkManager
:type interface_name: str
:type mode: str
:return: True if interface is valid
:rtype: bool
:raises InvalidInterfaceError: If the interface is invalid or the interface
has been chosen in the set _active
:raises InterfaceManagedByNetworkManagerError: If the card is managed and
is being used as deauth/ap mode
.. note: The available modes are monitor, AP and internet
The internet adapter should be put in the _exclude_shutdown set
so that it will not be shutdown after the program exits.'

def is_interface_valid(self, interface_name, mode=None):

    try:
        interface_adapter = self._name_to_object[interface_name]
    except KeyError:
        if (mode == 'internet'):
            return True
        else:
            raise InvalidInterfaceError(interface_name)
    if (mode == 'internet'):
        self._exclude_shutdown.add(interface_name)
    if ((mode != 'internet') and interface_adapter.is_managed_by_nm):
        raise InterfaceManagedByNetworkManagerError(interface_name)
    if ((mode == 'monitor') and (not interface_adapter.has_monitor_mode)):
        raise InvalidInterfaceError(interface_name, mode)
    elif ((mode == 'AP') and (not interface_adapter.has_ap_mode)):
        raise InvalidInterfaceError(interface_name, mode)
    if (interface_name in self._active):
        raise InvalidInterfaceError(interface_name)
    self._active.add(interface_name)
    return True
