(
        self,
        model: ModuleModel,
        location: DeckSlotLocation,
        attached_modules: Sequence[HardwareModule],
    )
Get the next matching hardware module for the given model and location.

        If a "matching" model is found already loaded in state at the requested
        location, that hardware module will be "reused" and selected. This behavior
        allows multiple load module commands to be issued while always preserving
        module hardware instance to deck slot mapping, which is required for
        multiples-of-a-module functionality.

        Args:
            model: The requested module model. The selected module may have a
                different model if the definition lists the model as compatible.
            location: The location the module will be assigned to.
            attached_modules: All attached modules as reported by the HardwareAPI,
                in the order in which they should be used.

        Raises:
            ModuleNotAttachedError: A not-yet-assigned module matching the requested
                parameters could not be found in the attached modules list.
            ModuleAlreadyPresentError: A module of a different type is already
                assigned to the requested location.
Get the next matching hardware module for the given model and location.
Get the next matching hardware module for the given model and location .
def find_attached_module(
        self,
        model: ModuleModel,
        location: DeckSlotLocation,
        attached_modules: Sequence[HardwareModule],
    ) -> HardwareModule:
        """Get the next matching hardware module for the given model and location.

        If a "matching" model is found already loaded in state at the requested
        location, that hardware module will be "reused" and selected. This behavior
        allows multiple load module commands to be issued while always preserving
        module hardware instance to deck slot mapping, which is required for
        multiples-of-a-module functionality.

        Args:
            model: The requested module model. The selected module may have a
                different model if the definition lists the model as compatible.
            location: The location the module will be assigned to.
            attached_modules: All attached modules as reported by the HardwareAPI,
                in the order in which they should be used.

        Raises:
            ModuleNotAttachedError: A not-yet-assigned module matching the requested
                parameters could not be found in the attached modules list.
            ModuleAlreadyPresentError: A module of a different type is already
                assigned to the requested location.
        """
        existing_mod = self._state.hardware_module_by_slot.get(location.slotName)

        if existing_mod:
            existing_def = existing_mod.definition

            if existing_def.model == model or model in existing_def.compatibleWith:
                return existing_mod

            else:
                raise errors.ModuleAlreadyPresentError(
                    f"A {existing_def.model.value} is already"
                    f" present in {location.slotName.value}"
                )

        for m in attached_modules:
            if m not in self._state.hardware_module_by_slot.values():
                if model == m.definition.model or model in m.definition.compatibleWith:
                    return m

        raise errors.ModuleNotAttachedError(f"No available {model.value} found.")
def find_attached_module ( self , model : ModuleModel , location : DeckSlotLocation , attached_modules : Sequence [ HardwareModule ] , ) -> HardwareModule : existing_mod = self . _state . hardware_module_by_slot . get ( location . slotName ) if existing_mod : existing_def = existing_mod . definition if existing_def . model == model or model in existing_def . compatibleWith : return existing_mod else : raise errors . ModuleAlreadyPresentError ( f"A {existing_def.model.value} is already" f" present in {location.slotName.value}" ) for m in attached_modules : if m not in self . _state . hardware_module_by_slot . values ( ) : if model == m . definition . model or model in m . definition . compatibleWith : return m raise errors . ModuleNotAttachedError ( f"No available {model.value} found." )